From 20a9f68c90a6cb5f1a6b1c374147148ef11da504 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Tue, 4 Jun 2013 02:08:20 +0400 Subject: [PATCH] added get attr to most generic search/cmp functions... Signed-off-by: Alex A. Naanou --- ui/TODO.otl | 5 +++++ ui/data.js | 31 +++++++++++++++++-------------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/ui/TODO.otl b/ui/TODO.otl index 8a26909e..26cd4db1 100755 --- a/ui/TODO.otl +++ b/ui/TODO.otl @@ -99,6 +99,10 @@ Roadmap | | $('[order='+$('.current.image').attr('order')+']').length | + | happens when: + | ribbon length: ~42 + | screen width: 4 + | jumping to end from start of ribbon [_] usable empty view -- w.o. data... [_] single image mode transition (alpha-blend/fade/none) [_] 0% Tablet UI @@ -176,6 +180,7 @@ Roadmap | positioning is OK but ribbons are not fully visible... [_] BUG: BASE_URL seems to gain a new trailing '/' on each save... | low priority as this does not affect anything... + [_] start/stop gif animations... [X] BUG: shifting ribbon left sometimes results in wrong order... | i.e. an image with order 12 before image with order 11 | diff --git a/ui/data.js b/ui/data.js index d4134bd2..0153e8bf 100755 --- a/ui/data.js +++ b/ui/data.js @@ -260,11 +260,12 @@ function imageOrderCmp(a, b, get, data){ // - -1 if a is less than position i // - +1 if a is greater than position i // -// NOTE: the signature is different from the traditional lcmp(a, b) so as +// 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 lcmp(a, i, lst){ - var b = lst[i] +function lcmp(a, i, lst, get){ + var b = get == null ? lst[i] : get(lst[i]) + if(a == b){ return 0 } else if(a < b){ @@ -282,9 +283,9 @@ function lcmp(a, i, lst){ // - -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){ - var b = lst[i] +// NOTE: this is here mostly to make debugging easy... +function isBetween(a, i, lst, get){ + var b = get == null ? lst[i] : get(lst[i]) // special case: tail... if(i == lst.length-1 && a >= b){ @@ -306,14 +307,15 @@ function isBetween(a, i, lst){ } +/* // Basic liner search... // // NOTE: this is here for testing reasons only... -function linSearch(target, lst, check, return_position){ +function linSearch(target, lst, check, return_position, get){ check = check == null ? lcmp : check for(var i=0; i < lst.length; i++){ - if(check(target, i, lst) == 0){ + if(check(target, i, lst, get) == 0){ return return_position ? i : lst[i] } } @@ -321,9 +323,10 @@ function linSearch(target, lst, check, return_position){ // no hit... return return_position ? -1 : null } -Array.prototype.linSearch = function(target, cmp){ - return linSearch(target, this, cmp, true) +Array.prototype.linSearch = function(target, cmp, get){ + return linSearch(target, this, cmp, true, get) } +*/ // Basic binary search implementation... @@ -331,7 +334,7 @@ Array.prototype.linSearch = function(target, cmp){ // NOTE: this will return the object by default, to return position set // return_position to true. // NOTE: by default this will use cmp as a predicate. -function binSearch(target, lst, check, return_position){ +function binSearch(target, lst, check, return_position, get){ check = check == null ? lcmp : check var h = 0 var t = lst.length - 1 @@ -339,7 +342,7 @@ function binSearch(target, lst, check, return_position){ while(h <= t){ m = Math.floor((h + t)/2) - res = check(target, m, lst) + res = check(target, m, lst, get) // match... if(res == 0){ @@ -358,8 +361,8 @@ function binSearch(target, lst, check, return_position){ // no result... return return_position ? -1 : null } -Array.prototype.binSearch = function(target, cmp){ - return binSearch(target, this, cmp, true) +Array.prototype.binSearch = function(target, cmp, get){ + return binSearch(target, this, cmp, true, get) }