experimenting with sparse lists...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2014-01-16 07:53:17 +04:00
parent 6fe9276cee
commit c945b3413f
2 changed files with 35 additions and 8 deletions

View File

@ -577,12 +577,14 @@ function binSearch(target, lst, check, return_position, get){
// Make a sparse gid list...
//
// if target is given this will merge gids into target...
//
// NOTE: the resulting list will always be sorted...
// NOTE: this will skip all elements not in order
function makeSparceGIDList(gids, data){
function populateSparceGIDList(gids, target, data){
data = data == null ? DATA : data
var order = data.order
var res = []
var res = target == null ? [] : target
gids.forEach(function(e){
var i = order.indexOf(e)
@ -599,9 +601,11 @@ function makeSparceGIDList(gids, data){
// Remove all the undefined's form a sparse list...
//
function compactSparceList(lst){
return lst.filter(function(e){
return e !== undefined
})
// XXX is it normal that .filter(..) skips undefined values?
return lst.filter(function(){ return true })
//return lst.filter(function(e){
// return e !== undefined
//})
}
@ -636,7 +640,7 @@ function compactSparceList(lst){
// On the down side, this has some memory overhead -- ~ N - n * ref
//
function fastSortGIDsByOrder(gids, data){
return compactSparceList(makeSparceGIDList(gids, data))
return compactSparceList(populateSparceGIDList(gids, data))
}

View File

@ -139,6 +139,29 @@ var getUnmarked = makeUnmarkedLister(
function(){ return MARKED },
function(){ return _UNMARKED_CACHE })
// these two are about 3 orders of magnitude faster than the above...
// ...which is better I do not yet know...
function getUnmarked_s0(){
var order = DATA.order
var res = []
for(var i=0; i < order.length; i++){
if(MARKED[i] == null){
res.push(order[i])
}
}
//return res
return getLoadedGIDs(res)
}
function getUnmarked_s1(){
var res = DATA.order.slice()
// XXX is it normal that .map() and .forEach() skip undefined values?
MARKED.map(function(e, i){
delete res[i]
})
//return compactSparceList(res)
return getLoadedGIDs(compactSparceList(res))
}
// XXX make this undefined tolerant -- sparse list compatibility...
var getMarkedGIDBefore = makeGIDBeforeGetterFromList(
@ -692,7 +715,7 @@ var loadFileMarks = makeFileLoader(
MARKED_FILE_PATTERN,
[],
function(data){
MARKED = makeSparceGIDList(data)
MARKED = populateSparceGIDList(data)
},
'marksLoaded')
@ -747,7 +770,7 @@ function setupMarks(viewer){
})
})
.on('sortedImages', function(){
MARKED = makeSparceGIDList(MARKED)
MARKED = populateSparceGIDList(MARKED)
marksUpdated()
})
.on('horizontalShiftedImage', function(evt, gid, direction){