Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,14 @@
/** Returns null if the value is not found. */
def binarySearch(collection, value) {
var low := 0
var high := collection.size() - 1
while (low <= high) {
def mid := (low + high) // 2
def comparison := value.op__cmp(collection[mid])
if (comparison.belowZero()) { high := mid - 1 } \
else if (comparison.aboveZero()) { low := mid + 1 } \
else if (comparison.isZero()) { return mid } \
else { throw("You expect me to binary search with a partial order?") }
}
return null
}