Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

67
LINES

< > BotCompany Repo | #1012323 // TripleIndex (older version with TripleRefs)

JavaX fragment (include)

1  
sclass TripleIndex extends VirtualNodeIndex {
2  
  SyncListMultiMap<S, TripleRef<S>> index = caseInsensitiveSyncListMultiMap();
3  
  Map<GlobalID, TripleWeb> websByID = synchroHashMap();
4  
  bool activated; // are we the main index (see tripleIndex())
5  
6  
  int numWebs() {
7  
    ret l(websByID);
8  
  }
9  
  
10  
  L<WebNode> get(S query) {
11  
    ret ai_tripleRefsToWebNodes_lazyList(index.get(query));
12  
  }
13  
  
14  
  Web getWeb(GlobalID id) {
15  
    ret webFromTriple(websByID.get(id));
16  
  }
17  
  
18  
  void addWeb(Web web) {
19  
    if (web == null) ret;
20  
    TripleWeb w = ai_webToTripleWeb(web);
21  
    if (w == null)
22  
      //ret with print("Skipping non-tripelizable web");
23  
      fail("Skipping non-tripelizable web: " + webToStringShort(web));
24  
    index.put(w.a, TripleA(w));
25  
    index.put(w.b, TripleB(w));
26  
    index.put(w.c, TripleC(w));
27  
    websByID.put(w.globalID, w);
28  
  }
29  
  
30  
  void removeWeb(Web web) {
31  
    if (web == null) ret;
32  
    TripleWeb w = ai_webToTripleWeb(web);
33  
    if (w == null) ret;
34  
    websByID.remove(w.globalID);
35  
    indexRemove(w.a, w.globalID);
36  
    indexRemove(w.b, w.globalID);
37  
    indexRemove(w.c, w.globalID);
38  
  }
39  
  
40  
  // internal
41  
  void indexRemove(S term, GlobalID globalID) {
42  
    L<TripleRef<S>> l = index.get(term);
43  
    for i over l:
44  
      if (eq(((TripleWeb) l.get(i).triple).globalID, globalID)) {
45  
        index.remove(term, l.get(i));
46  
        ret;
47  
      }
48  
  }
49  
  
50  
  void clear() {
51  
    index.clear();
52  
    websByID.clear();
53  
  }
54  
  
55  
  void activate {
56  
    if (!activated) {
57  
      activated = true;
58  
      ai_onNewOrRemovedWeb(func(Web web) {
59  
        addWeb(web);
60  
        false;
61  
      }, func(Web web) {
62  
        removeWeb(web);
63  
        false;
64  
      });
65  
    }
66  
  }
67  
}

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: 475 / 480
Version history: 20 change(s)
Referenced in: [show references]