sclass TripleIndex extends VirtualNodeIndex { SyncListMultiMap<S, TripleRef<S>> index = caseInsensitiveSyncListMultiMap(); Map<GlobalID, TripleWeb> websByID = synchroHashMap(); bool activated; // are we the main index (see tripleIndex()) int numWebs() { ret l(websByID); } L<WebNode> get(S query) { ret ai_tripleRefsToWebNodes_lazyList(index.get(query)); } Web getWeb(GlobalID id) { ret webFromTriple(websByID.get(id)); } void addWeb(Web web) { if (web == null) ret; TripleWeb w = ai_webToTripleWeb(web); if (w == null) //ret with print("Skipping non-tripelizable web"); fail("Skipping non-tripelizable web: " + webToStringShort(web)); index.put(w.a, TripleA(w)); index.put(w.b, TripleB(w)); index.put(w.c, TripleC(w)); websByID.put(w.globalID, w); } void removeWeb(Web web) { if (web == null) ret; TripleWeb w = ai_webToTripleWeb(web); if (w == null) ret; websByID.remove(w.globalID); indexRemove(w.a, w.globalID); indexRemove(w.b, w.globalID); indexRemove(w.c, w.globalID); } // internal void indexRemove(S term, GlobalID globalID) { L<TripleRef<S>> l = index.get(term); for i over l: if (eq(((TripleWeb) l.get(i).triple).globalID, globalID)) { index.remove(term, l.get(i)); ret; } } void clear() { index.clear(); websByID.clear(); } void activate { if (!activated) { activated = true; ai_onNewOrRemovedWeb(func(Web web) { addWeb(web); false; }, func(Web web) { removeWeb(web); false; }); } } }
download show line numbers debug dex old transpilations
Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1012323 |
Snippet name: | TripleIndex (older version with TripleRefs) |
Eternal ID of this version: | #1012323/21 |
Text MD5: | aecee05d80efcc15d6cd93473402f205 |
Author: | stefan |
Category: | javax / a.i. |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2017-11-28 23:37:28 |
Source code size: | 1712 bytes / 67 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 474 / 479 |
Version history: | 20 change(s) |
Referenced in: | #1012330 - TripleIndex with direct link to triples [LIVE] |