Recursively sort a tree of comments using the comp comparator.
494045
function sortComments(comments) {
    comments.sort(comp);
    $.each(comments, function() {
      this.children = sortComments(this.children);
    });
    return comments;
  }
204460
def split_comments(comments):
    """"""
    flags = []
    other = []
    for c in comments:
        if len(c) > 1 and c[1] == ',':
            flags.append(c)
        else:
            other.append(c)
    return flags, other
723690
function orderNodes(ast) {
  var comments  = Array.isArray(ast.comments) ? ast.comments.slice() : [];
  var comparitor = ('sortIndex' in ast) ? compareIndex : compareLocation;
  return comments
    .concat(depthFirst(ast, ast.parent))
    .sort(comparitor)
    .map(setSortIndex);
}
1142539
function getCommentLineNumbers(comments) {
            const lines = new Set();

            comments.forEach(comment => {
                for (let i = comment.loc.start.line; i <= comment.loc.end.line; i++) {
                    lines.add(i);
                }
            });

            return lines;
        }
1314626
private static <T> ArrayList<T> sorted(Collection<T> cls, Comparator<? super T> c) {
    ArrayList<T> sorted = new ArrayList<>(cls);
    sorted.sort(c);
    return sorted;
  }
426986
public static void sort(BaseComponent parent, boolean recurse) {
        if (parent == null || parent.getChildren().size() < 2) {
            return;
        }

        int i = 1;
        int size = parent.getChildren().size();

        while (i < size) {
            Treenode item1 = (Treenode) parent.getChildren().get(i - 1);
            Treenode item2 = (Treenode) parent.getChildren().get(i);

            if (compare(item1, item2) > 0) {
                parent.swapChildren(i - 1, i);
                i = i == 1 ? 2 : i - 1;
            } else {
                i++;
            }
        }

        if (recurse) {
            for (BaseComponent child : parent.getChildren()) {
                sort(child, recurse);
            }
        }
    }
289066
public void sortChildrenByNode(Comparator<TreeNode<T>> comparator) {
		Collections.sort(children, comparator);
		for (TreeNode<T> child : children) {
			child.sortChildrenByNode(comparator);
		}
	}
423959
def assign_comments(self, tree, comments):
        
        comments = list(comments)
        comments.sort(key=lambda c: c.line)

        idx_by_line = {0: 0}  # {line_no: comment_idx}

        for i, c in enumerate(comments):
            if c.line not in idx_by_line:
                idx_by_line[c.line] = i

        idx = []

        # convert comment tokens to strings, and remove any line breaks
        self.comments = [c.value.strip() for c in comments]
        last_comment_line = max(idx_by_line.keys())

        # make a list with an entry for each line
        # number associated with a comment list index

        for i in range(last_comment_line, 0, -1):
            if i in idx_by_line:
                # associate line with new comment
                idx.append(idx_by_line[i])
            else:
                # associate line with following comment
                idx.append(idx[-1])

        idx.append(0)  # line numbers start from 1
        idx.reverse()
        self.idx = idx
        self._assign_comments(tree, 0)
964998
def comment_lines(lines):
    """"""
    ret = []
    for line in lines:
        ws_prefix, rest, ignore = RE_LINE_SPLITTER_COMMENT.match(line).groups()
        ret.append(ws_prefix + '#' + rest)
    return ''.join(ret)
91792
def handle(self, *args, **options):
        
        comments = Comment.objects.filter(
            Q(classifiedcomment__isnull=True) |
            Q(classifiedcomment__cls='unsure')).order_by('?')
        if options['count']:
            comments = comments[:options['count']]
        comment_count = comments.count()

        self.stdout.write('Classifying %s comments, please wait...' %
                          comment_count)
        self.stdout.flush()

        for comment in comments:
            classified_comment = utils.classify_comment(comment)
            self.stdout.write('%s,' % classified_comment.cls[0])
            self.stdout.flush()

        self.stdout.write('\nDone!\n')
847932
def sort_canonical(keyword, stmts):
    

    try:
        (_arg_type, subspec) = stmt_map[keyword]
    except KeyError:
        return stmts
    res = []
    # keep the order of data definition statements and case
    keep = [s[0] for s in data_def_stmts] + ['case']
    for (kw, _spec) in flatten_spec(subspec):
        # keep comments before a statement together with that statement
        comments = []
        for s in stmts:
            if s.keyword == '_comment':
                comments.append(s)
            elif s.keyword == kw and kw not in keep:
                res.extend(comments)
                comments = []
                res.append(s)
            else:
                comments = []

    # then copy all other statements (extensions)
    res.extend([stmt for stmt in stmts if stmt not in res])
    return res
1306983
public static void sortNode(TreeNode node, Comparator comparator) {
        TreeNodeList children = (TreeNodeList) node.getChildren();

        if (children != null && !children.isEmpty()) {
            Object[] childrenArray = children.toArray();
            Arrays.sort(childrenArray, comparator);
            for (int i = 0; i < childrenArray.length; i++) {
                children.setSibling(i, (TreeNode) childrenArray[i]);
            }

            for (int i = 0; i < children.size(); i++) {
                sortNode(children.get(i), comparator);
            }
        }
    }
439704
public void sort (Comparator<? super T> comp)
    {
        if (_size > 1) {
            QuickSort.sort(_elements, 0, _size-1, comp);
        }
    }
831178
function getCommentLineNums(comments) {
    const lines = [];

    comments.forEach(token => {
        const start = token.loc.start.line;
        const end = token.loc.end.line;

        lines.push(start, end);
    });
    return lines;
}
147109
function findLeadingComments(comments, index, beginIndex, first) {
    const leadComments = [];
    if (first && ignoreComment.test(comments[index].raw)) {
        return leadComments;
    }
    let backIndex = index - 1;
    while (backIndex >= beginIndex &&
        (comments[backIndex].loc.end.line + 1 === comments[backIndex + 1].loc.start.line
            || comments[backIndex].loc.end.line === comments[backIndex + 1].loc.start.line)) {
        if (first && ignoreComment.test(comments[backIndex].raw)) {
            break;
        }
        backIndex -= 1;
    }
    for (let ind = backIndex + 1; ind <= index; ind += 1) {
        leadComments.push(comments[ind]);
    }
    return leadComments;
}
811902
def _strip_comments(line, comments=None):
        """"""
        if comments is None:
            comments = []

        new_comments = False
        comment_start = line.find("#")
        if comment_start != -1:
            comments.append(line[comment_start + 1:].strip())
            new_comments = True
            line = line[:comment_start]

        return line, comments, new_comments
699548
public static <T> void sort (T[] a, Comparator<? super T> comp)
    {
        sort(a, 0, a.length - 1, comp);
    }