Binary sort
Signed-off-by: James Ketrenos <james_git@ketrenos.com>
This commit is contained in:
parent
4d9c3145fc
commit
a8a79712ef
@ -341,14 +341,12 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var index, length = this.thumbnails.length - 1;
|
var index, start, stop, length = this.thumbnails.length - 1;
|
||||||
|
|
||||||
This needs to become a binary sort between min/max set by either visibleThumbs, or the full
|
|
||||||
array. 'index' adjustments then need to be done based on these values instead of on the full
|
|
||||||
array or the search can end up bouncing over the 'visible' items
|
|
||||||
|
|
||||||
|
start = 0;
|
||||||
|
stop = this.thumbnails.length - 1;
|
||||||
if (this.visibleThumbs.length) {
|
if (this.visibleThumbs.length) {
|
||||||
index = this.visibleThumbs[this.visibleThumbs.length >> 1];
|
index = this.visibleThumbs[stop >> 1];
|
||||||
} else {
|
} else {
|
||||||
index = length >> 1;
|
index = length >> 1;
|
||||||
}
|
}
|
||||||
@ -357,10 +355,20 @@ array or the search can end up bouncing over the 'visible' items
|
|||||||
while (pos != 0 && last != index) {
|
while (pos != 0 && last != index) {
|
||||||
last = index; /* safety escape in case the DOM changed and nothing matches */
|
last = index; /* safety escape in case the DOM changed and nothing matches */
|
||||||
|
|
||||||
if (pos == +1) { /* Checked item was too low on the page, so look closer to start */
|
if (pos == +1) { /* Checked item was too far down page, so look closer to start */
|
||||||
index = index >> 1;
|
stop = index - 1;
|
||||||
} else { /* Checked item was too high on the page, so look farther */
|
if (stop < 0) {
|
||||||
index += (length - index) >> 1;
|
console.log("No items in viewport -- all are below");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
index = start + ((stop - start) >> 1);
|
||||||
|
} else { /* Checked item was too high up on the page, so look farther */
|
||||||
|
start = index + 1;
|
||||||
|
if (start == length) {
|
||||||
|
console.log("No items in viewport -- all are above");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
index += (stop - start) >> 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
pos = this.checkPosition(index);
|
pos = this.checkPosition(index);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user