gun/lib/radix.js
Mark Nadal b1b408971d
Master into Deploys (#1391)
* Thank you Murage Martin @murageyun for donating!!!

* Fix opt.s3.fakes3 parsing issue (#1318)

* Fix opt.s3.fakes3 parsing issue

* Fix second typo within if block

* Support variable number of auth retry attempts through opt.retries (#1325)

Maintain default to 9 to ensure backwards compatibility

* Thanks Jason Stallings @octalmage !!!

* Remove unused imports (#1337)

* Update README.md

* yay format change

* encode objects

* WS ws.path fix  (#1343)

* Update wire.js

* Update wire.js

* Update wire.js

* add one click deploy to readme (#1342)

* update src/index (#1254)

* update src/index

* update

* src/index fix

* added src/core

* is ??? this a MVP of book & rad ???? thanks to @rogowski

* book & rad APIs stabilizing

* RAD & Book promoted! + buggy example: test/rad/book.html

* bump path

* cleaned up Book results & sorting & caching

* sea blobs! (#1353)

* sea blobs!

* and null origins

* null fix

* null check is last

* add a way to select stats file from url (#1351)

* react-native detection, and load needed shims (#1349)

* react-native detection

* added lib mobile

* changed back to gun. for another solution

* have unbuild function wrap to prevent scope leaks & allow RETURN hehehe so I can reject @bmatusiak 's lS change O:) O:) I love you you're a hero!

later with @bmatusiak check sea.then for '../gun.js' vs '../' vs ...
note: src/index -> core.js
TODO: something about WebRTC candidates hitting ack decrement limits?

* quick-fix (#1355)

* Fix SEA certificate verification, allow multiple pubs (#1358)

* Create SECURITY.md (#1364)

* ... works (#1357)

* Loading fix (#1356)

* does this load better

* check window.Gun too in rfs

* update SECURITY.md file and change the versions to 0.2020.x (#1365)

* webrtc accept getUserMedia streams as peer

* Check atom exists in graph when deciding to read from disk (#1371)

* fix: ERROR: Radisk needs `store.put` interface (#1374)

* Update STUN servers (#1381)

Commented out sipgate.net STUN server.
Added Cloudflare STUN server.

* universal notification system

---------

Co-authored-by: ritchia1 <andrew.ritchie@estimateone.com>
Co-authored-by: Anton <dev@atjn.dk>
Co-authored-by: Bradley Matusiak <bmatusiak@gmail.com>
Co-authored-by: Jay Byoun <jay8061@pm.me>
Co-authored-by: mimiza <dev@mimiza.com>
Co-authored-by: Simardeep Singh <1003simar@gmail.com>
Co-authored-by: Malcolm Blaney <mblaney@gmail.com>
Co-authored-by: Andreas Heissenberger <andreas@heissenberger.at>
Co-authored-by: carlin978 <120719190+carlin978@users.noreply.github.com>
2024-11-23 17:52:28 -08:00

126 lines
4.1 KiB
JavaScript

;(function(){
function Radix(){
var radix = function(key, val, t){
radix.unit = 0;
if(!t && u !== val){
radix.last = (''+key < radix.last)? radix.last : ''+key;
delete (radix.$||{})[_];
}
t = t || radix.$ || (radix.$ = {});
if(!key && Object.keys(t).length){ return t }
key = ''+key;
var i = 0, l = key.length-1, k = key[i], at, tmp;
while(!(at = t[k]) && i < l){
k += key[++i];
}
if(!at){
if(!each(t, function(r, s){
var ii = 0, kk = '';
if((s||'').length){ while(s[ii] == key[ii]){
kk += s[ii++];
} }
if(kk){
if(u === val){
if(ii <= l){ return }
(tmp || (tmp = {}))[s.slice(ii)] = r;
//(tmp[_] = function $(){ $.sort = Object.keys(tmp).sort(); return $ }()); // get rid of this one, cause it is on read?
return r;
}
var __ = {};
__[s.slice(ii)] = r;
ii = key.slice(ii);
('' === ii)? (__[''] = val) : ((__[ii] = {})[''] = val);
//(__[_] = function $(){ $.sort = Object.keys(__).sort(); return $ }());
t[kk] = __;
if(Radix.debug && 'undefined' === ''+kk){ console.log(0, kk); debugger }
delete t[s];
//(t[_] = function $(){ $.sort = Object.keys(t).sort(); return $ }());
return true;
}
})){
if(u === val){ return; }
(t[k] || (t[k] = {}))[''] = val;
if(Radix.debug && 'undefined' === ''+k){ console.log(1, k); debugger }
//(t[_] = function $(){ $.sort = Object.keys(t).sort(); return $ }());
}
if(u === val){
return tmp;
}
} else
if(i == l){
//if(u === val){ return (u === (tmp = at['']))? at : tmp } // THIS CODE IS CORRECT, below is
if(u === val){ return (u === (tmp = at['']))? at : ((radix.unit = 1) && tmp) } // temporary help??
at[''] = val;
//(at[_] = function $(){ $.sort = Object.keys(at).sort(); return $ }());
} else {
if(u !== val){ delete at[_] }
//at && (at[_] = function $(){ $.sort = Object.keys(at).sort(); return $ }());
return radix(key.slice(++i), val, at || (at = {}));
}
}
return radix;
};
Radix.map = function rap(radix, cb, opt, pre){
try {
pre = pre || []; // TODO: BUG: most out-of-memory crashes come from here.
var t = ('function' == typeof radix)? radix.$ || {} : radix;
//!opt && console.log("WHAT IS T?", JSON.stringify(t).length);
if(!t){ return }
if('string' == typeof t){ if(Radix.debug){ throw ['BUG:', radix, cb, opt, pre] } return; }
var keys = (t[_]||no).sort || (t[_] = function $(){ $.sort = Object.keys(t).sort(); return $ }()).sort, rev; // ONLY 17% of ops are pre-sorted!
//var keys = Object.keys(t).sort();
opt = (true === opt)? {branch: true} : (opt || {});
if(rev = opt.reverse){ keys = keys.slice(0).reverse() }
var start = opt.start, end = opt.end, END = '\uffff';
var i = 0, l = keys.length;
for(;i < l; i++){ var key = keys[i], tree = t[key], tmp, p, pt;
if(!tree || '' === key || _ === key || 'undefined' === key){ continue }
p = pre.slice(0); p.push(key);
pt = p.join('');
if(u !== start && pt < (start||'').slice(0,pt.length)){ continue }
if(u !== end && (end || END) < pt){ continue }
if(rev){ // children must be checked first when going in reverse.
tmp = rap(tree, cb, opt, p);
if(u !== tmp){ return tmp }
}
if(u !== (tmp = tree[''])){
var yes = 1;
if(u !== start && pt < (start||'')){ yes = 0 }
if(u !== end && pt > (end || END)){ yes = 0 }
if(yes){
tmp = cb(tmp, pt, key, pre);
if(u !== tmp){ return tmp }
}
} else
if(opt.branch){
tmp = cb(u, pt, key, pre);
if(u !== tmp){ return tmp }
}
pre = p;
if(!rev){
tmp = rap(tree, cb, opt, pre);
if(u !== tmp){ return tmp }
}
pre.pop();
}
} catch (e) { console.error(e); }
};
(function(name, exports){
if(typeof window !== "undefined"){
window[name] = window[name]||exports;
}
try{ module.exports = exports }catch(e){}
})("Radix",Radix);
var each = Radix.object = function(o, f, r){
for(var k in o){
if(!o.hasOwnProperty(k)){ continue }
if((r = f(o[k], k)) !== u){ return r }
}
}, no = {}, u;
var _ = String.fromCharCode(24);
}());