Category talk:Wren-sort: Difference between revisions
m
→Source code: Now uses Wren S/H lexer.
(→Source code: Made several methods 'chaining' friendly.) |
m (→Source code: Now uses Wren S/H lexer.) |
||
(4 intermediate revisions by the same user not shown) | |||
Line 1:
===Source code===
<
import "./trait" for Comparable
Line 298:
static isSorted(a) { isSorted(a, false) }
static isSortedDesc(a) { isSorted(a, true) }
}
Line 370 ⟶ 354:
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 ⟶ 458:
// 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 ⟶ 684:
// 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.
Line 718 ⟶ 712:
// Returns the string representation of 'this'.
toString { _lst.toString }
}</
|