Category talk:Wren-sort: Difference between revisions
→Source code: Added Find.nearest and SortedList.nearestIndexOf methods.
(→Source code: Made several methods 'chaining' friendly.) |
(→Source code: Added Find.nearest and SortedList.nearestIndexOf methods.) |
||
Line 370:
return (t[1] > 0) ? t[2].to : -1
}
// Works similarly to 'all' but only returns the index of the first match
// or the index at which it would need to be inserted if there were no matches at all.
static nearest(a, value, cmp) { all(a, value, cmp)[2].from }
// Finds the lowest value in an unsorted list according to 'cmp' but without sorting.
Line 470 ⟶ 474:
// Convenience versions of the above which use default values for the 'cmp' parameter.
static all(a, value) { all(a, value, false) }
static first(a, value) { first(a, value, false) }
static last(a, value) { last(a, value, false) }
static
static
static
static quick(a, k) { quick(a, k, false) }
// Finds the median element(s) of a sorted list.
Line 695 ⟶ 700:
// in the sorted list. Returns -1 if not found.
lastIndexOf(value) { Find.last(_lst, value, _cmp) }
// Uses binary search to find the index of the first occurence of 'value'
// in the sorted list. Returns the index at which it would need to be inserted
// if not found.
nearestIndexOf(value) { Find.nearest(_lst, value, _cmp) }
// Iterator protocol methods.
|