mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-29 10:20:08 +00:00
preparation to rewrite binSearch(...) ...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
20d6b0b019
commit
e7196b76e9
28
ui/data.js
28
ui/data.js
@ -82,14 +82,38 @@ function imageNameCmp(a, b, data){
|
||||
}
|
||||
|
||||
|
||||
// A predicate returning:
|
||||
// Check if a is at position i in lst
|
||||
//
|
||||
// This will return:
|
||||
// - 0 if a is equal to position i
|
||||
// - -1 if a is less position i
|
||||
// - +1 if a is greater position i
|
||||
//
|
||||
// NOTE: the signature is different from the traditional cmp(a, b) so as
|
||||
// to enable more complex comparisons involving adjacent elements
|
||||
// (see isBetween(...) for an example)
|
||||
function cmp(a, i, lst){
|
||||
var b = lst[i]
|
||||
if(a == b){
|
||||
return 0
|
||||
} else if(a < b){
|
||||
return -1
|
||||
} else {
|
||||
return 1
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Check if a is at position i in lst or between positions i and i+1
|
||||
//
|
||||
// This will return:
|
||||
// - 0 if a is equal at position i in lst or is between i and i+1
|
||||
// - -1 if a is "below" position i
|
||||
// - +1 if a is "above" position i
|
||||
//
|
||||
// NOTE: this is here mostly to make debuging easy...
|
||||
function isBetween(a, i, lst){
|
||||
console.log('>>>', a, i, lst)
|
||||
//console.log('>>>', a, i, lst)
|
||||
var b = lst[i]
|
||||
var c = lst[i+1]
|
||||
// hit...
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user