Category talk:Wren-sort: Difference between revisions
Content added Content deleted
(→Source code: Made several methods 'chaining' friendly.) |
(→Source code: Added Find.nearest and SortedList.nearestIndexOf methods.) |
||
Line 370: | Line 370: | ||
return (t[1] > 0) ? t[2].to : -1 |
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. |
// Finds the lowest value in an unsorted list according to 'cmp' but without sorting. |
||
Line 470: | Line 474: | ||
// Convenience versions of the above which use default values for the 'cmp' parameter. |
// Convenience versions of the above which use default values for the 'cmp' parameter. |
||
static all(a, value) { all(a, value, false) } |
static all(a, value) { all(a, value, false) } |
||
static first(a, value) { first(a, value, false) } |
static first(a, value) { first(a, value, false) } |
||
static last(a, value) { last(a, value, false) } |
static last(a, value) { last(a, value, false) } |
||
static |
static nearest(a, value) { nearest(a, value, false) } |
||
static |
static lowest(a) { lowest(a, false) } |
||
static |
static highest(a) { highest(a, false) } |
||
static quick(a, k) { quick(a, k, false) } |
|||
// Finds the median element(s) of a sorted list. |
// Finds the median element(s) of a sorted list. |
||
Line 695: | Line 700: | ||
// in the sorted list. Returns -1 if not found. |
// in the sorted list. Returns -1 if not found. |
||
lastIndexOf(value) { Find.last(_lst, value, _cmp) } |
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. |
// Iterator protocol methods. |