sclass AI_SubSpace implements AI_PostHandler, AI_CacheChecker { int limit; new MultiMap index; new HashMap websByID; new L webs; bool changed; *() {} *(int *limit) {} // existence of triple has already been checked public GlobalID postTriple(T3 t) { if (limitReached()) fail("Subspace limit reached"); Web web = webFromTriple(t); web.source = ai_currentMaker(); addWeb(web); ret web.globalIDObj(); } public GlobalID postTriple(T3 t, bool verified) { ret postTriple(t); // XXX } void addWeb(Web web) { websByID.put(web.globalIDObj(), web); webs.add(web); changed = true; for (WebNode node : web_nodesAndRelations(web)) for (S text : asSet(node.texts())) index.put(symbol(ai_shortenForIndex(text)), node); } public bool hasTriple(Symbol a, Symbol b, Symbol c) { L webs = ai_withoutInvalidWebs(nodesToWebs(shortestList3( index.get(a), index.get(b), index.get(c)))); ret webs_search_noVar_bool(webFromTriple(a, b, c), webs); } bool limitReached() { ret limit > 0 && l(websByID) >= limit; } L indexedNodes_rawLookup(Symbol s) { ret index.get(ai_shortenForIndex(s)); } int numWebs() { ret l(websByID); } }