sclass ActualThoughtSpace extends AbstractThoughtSpace { new TripleIndex index; int limit; // 0 = no limit L> blockedPatterns = listWithNotify(r { blocked.clear(); }); Map blocked = newWeakHashMap(); *() {} *(int *limit) {} *(AbstractThoughtSpace parent) { super(parent); } // existence of triple has already been checked public GlobalID postTriple(T3 t) { if (limitReached()) fail("Thought space limit reached"); TripleWeb w = tripleWeb(t); index.addTriple(w); ret w.globalID(); } bool limitReached() { ret limit > 0 && size() >= limit; } L> get(S s) { ret ai_triplesToTripleRefs_lazyList(s, getTriples(s)); } L getTriples(S s) { L l = filterNonBlockedTriples(parent.getTriples(s)); ret combineLists(l, index.getTriples(ai_shortenForIndex(s))); } L> filterNonBlocked(L> l) { if (empty(blockedPatterns)) ret l; L> out = emptyListWithCapacity(l); for (TripleRef ref : l) if (!isBlocked((TripleWeb) ref.triple)) out.add(ref); ret out; } L filterNonBlockedTriples(L l) { if (empty(blockedPatterns)) ret l; L out = emptyListWithCapacity(l); for (TripleWeb w : l) if (!isBlocked(w)) out.add(w); ret out; } bool isBlocked(TripleWeb t) { Bool b = blocked.get(t); if (b != null) ret b; b = false; for (T3 pat : blockedPatterns) if (simpleMatchTriple_dollarVars(pat, t) != null) { b = true; break; } blocked.put(t, b); ret b; } int size() { ret index.size(); } }