If two records or record IDs have the same rank, sort them by ID.
 This prevents a different order being returned by different Rubies.
356902
def sort(ranked_records)
      ranked_records.sort { |a, b|
        a_score = a.last
        a_id = a.first.is_a?(Fixnum) ? a.first : a.first.id

        b_score = b.last
        b_id = b.first.is_a?(Fixnum) ? b.first : b.first.id

        if a_score == b_score
          a_id <=> b_id
        else
          b_score <=> a_score # We want the records with better relevance first.
        end

      }
    end
1093678
def order_by(self, field_name=None):
        
        assert self.query.can_filter(), "Cannot reorder a query once a slice has been taken."

        clone = self._clone()
        clone.query.clear_ordering()

        if field_name is not None:
            clone.query.add_ordering(field_name)

        return clone
136015
def sort_run(run):
        """"""
        # Sort errors first, then by name. Also show errors that were manually
        # approved, so the paging sort order stays the same even after users
        # approve a diff on the run page.
        if run.status in models.Run.DIFF_NEEDED_STATES:
            return (0, run.name)
        return (1, run.name)
1320705
public static function sortRecords(array $records, $parentId = 0, $includeParent = false, $depth = null, $height = 0)
    {
        $list = [ ];
        $map  = [ ];

        $records = self::orderRecords($records, 'position');

        foreach ($records as $record)
        {
            if ($record->getParent() === 0 || $record->getParent() > 0) // include 0 and numbers, exclude null and ''
            {
                $map[$record->getId()] = $record;
                $list[]                = [ 'id' => $record->getId(), 'parentId' => $record->getParent() ];
            }
        }

        $util      = new AdjacentList2NestedSet($list);
        $nestedSet = $util->getNestedSet();

        $root = false;

        if ($parentId != 0)
        {
            if (array_key_exists($parentId,$nestedSet)) {
                $root = $nestedSet[$parentId];
            }
            else
            {
                return [];
            }
        }

        $result = [ ];

        if ($height != 0 && $root)
        {
            foreach ($nestedSet as $id => $positioning)
            {
                if ($root['left'] > $positioning['left'] && $root['right'] < $positioning['right'])
                {
                    $result[$id] = $map[$id];
                    $result[$id]->setLevel($positioning['level']);
                }
            }
        }

        if ($includeParent && $root)
        {
            $result[$parentId] = $map[$parentId];
            $result[$parentId]->setLevel($root['level']);

        }

        if ($depth != null)
        {
            $depth = $depth + $root['level'];
        }

        foreach ($nestedSet as $id => $positioning)
        {

            if ($depth === null || $positioning['level'] <= $depth)
            {
                if ($parentId == 0 || ($positioning['left'] > $root['left'] && $positioning['right'] < $root['right']))
                {
                    $result[$id] = $map[$id];
                    $result[$id]->setLevel($positioning['level']);
                }
            }
        }

        return $result;

    }
1073180
def uniq_by_id(self, records):
        """"""
        uniq = []
        keys = set()
        for rec in records:
            rec_id = rec[self._id_field]
            if rec_id not in keys:
                uniq.append(rec)
                keys.add(rec_id)
        return uniq
916918
function compareByIdThenRev(a, b) {
  var idCompare = compare(a._id, b._id);
  if (idCompare !== 0) {
    return idCompare;
  }
  var aStart = a._revisions ? a._revisions.start : 0;
  var bStart = b._revisions ? b._revisions.start : 0;
  return compare(aStart, bStart);
}
301406
public boolean dnEquals(DirRecord that) throws NamingException {
    if (that == null) {
      throw new NamingException("Null record for dnEquals");
    }

    String thisDn = getDn();
    if (thisDn == null) {
      throw new NamingException("No dn for this record");
    }

    String thatDn = that.getDn();
    if (thatDn == null) {
      throw new NamingException("That record has no dn");
    }

    return (thisDn.equals(thatDn));
  }
981873
function sortFeatures({ stage: a, id: aa }, { stage: b, id: bb }) {
	return b - a || (aa < bb ? -1 : aa > bb ? 1 : 0);
}
524567
function orderByComparator(a, b) {
    if (a === null || typeof a === 'undefined')
        a = 0;
    if (b === null || typeof b === 'undefined')
        b = 0;
    if (a instanceof Date && b instanceof Date) {
        if (a < b)
            return -1;
        if (a > b)
            return 1;
    }
    else if ((isNaN(parseFloat(a)) || !isFinite(a)) || (isNaN(parseFloat(b)) || !isFinite(b))) {
        // Convert to string in case of a=0 or b=0
        a = String(a);
        b = String(b);
        // Isn't a number so lowercase the string to properly compare
        if (a.toLowerCase() < b.toLowerCase())
            return -1;
        if (a.toLowerCase() > b.toLowerCase())
            return 1;
    }
    else {
        // Parse strings as numbers to compare properly
        if (parseFloat(a) < parseFloat(b))
            return -1;
        if (parseFloat(a) > parseFloat(b))
            return 1;
    }
    // equal each other
    return 0;
}
1218093
def sort_collection_by_column(collection, column, order)
      sorter = column.sort[:method]
      collection = collection.sort_by do |record|
        value = sorter.is_a?(Proc) ? record.instance_eval(&sorter) : record.instance_eval(sorter.to_s)
        value = '' if value.nil?
        value
      end
      collection.reverse! if order.casecmp('DESC').zero?
      collection
    end
739931
def sort_by(self, *ids):
        
        # Support sorting by file_ids or keys.
        files = {str(f_.file_id): f_.key for f_ in self}
        # self.record['_files'] = [{'key': files.get(id_, id_)} for id_ in ids]
        self.filesmap = OrderedDict([
            (files.get(id_, id_), self[files.get(id_, id_)].dumps())
            for id_ in ids
        ])
        self.flush()
818467
function _compareById(a, b) {
        assert.strictEqual(typeof a.id, typeof b.id);
        assert.ok(!_.isUndefined(a.id));
        return _compareIds(a.id, b.id);
    }
1010635
protected function sortByRank(Identification $a, Identification $b)
    {
        if ($a->getRank() == $b->getRank()) {
            return 0;
        }
        
        return $a->getRank() > $b->getRank() ? $this->returnTrue : $this->returnFalse;
    }
1099735
def get_next_record(in_uid, kind='1'):
        '''
        
        '''
        current_rec = MPost.get_by_uid(in_uid)
        recs = TabPost.select().where(
            (TabPost.kind == kind) &
            (TabPost.time_create < current_rec.time_create)
        ).order_by(TabPost.time_create.desc())
        if recs.count():
            return recs.get()
        return None
1182984
@Override
    public int compare(final Row row0, final Row row1) {
        int result = 0;

        for (int i = 0; i < orderbys.size(); i++) {
            final OrderColumn oc = orderbys.get(i);
            // null indicates "detail" record which is what the parser assigns
            // to <column> 's setup outside of <record> elements
            final String mdkey0 = row0.getMdkey() == null ? FPConstants.DETAIL_ID : row0.getMdkey();
            final String mdkey1 = row1.getMdkey() == null ? FPConstants.DETAIL_ID : row1.getMdkey();

            // shift all non detail records to the bottom of the DataSet
            if (!mdkey0.equals(FPConstants.DETAIL_ID) && !mdkey1.equals(FPConstants.DETAIL_ID)) {
                // keep headers / trailers in the same order at the bottom of
                // the DataSet
                return 0;
            } else if (!mdkey0.equals(FPConstants.DETAIL_ID) || !mdkey1.equals(FPConstants.DETAIL_ID)) {
                return !mdkey0.equals(FPConstants.DETAIL_ID) ? 1 : 0;
            }

            result = compareCol(row0, row1, oc);

            // if it is = 0 then the primary sort is done, and it can start the
            // secondary sorts
            if (result != 0) {
                break;
            }
        }

        return result;
    }
168128
def sort(self, callback=None):
        
        items = self.items

        if callback:
            return self.__class__(sorted(items, key=callback))
        else:
            return self.__class__(sorted(items))
1260471
private void ensureSorted() {
    if (sorted) {
      return;
    }

    ensureCapacity();

    DataUtils.sort(byBlockHash);
    for (int i = 0; i < size; i++) {
      resourceIdsIndex[i] = i;
    }
    DataUtils.sort(byResourceId);

    sorted = true;
  }