static double ai_gc_scan_maxDistance_reached; static S ai_gc_scan(S root) { ai_gc_clear(); ai_startBuffering(); Map distances; try { time "GC Scan" { ai_postTriple(root, "has GC distance", "0"); distances = litcimap(root, 0.0); LinkedList queue = litLinkedList(root); S word; while ping ((word = queue.poll()) != null) { double d = distances.get(word); for (WebNode node : indexedNodes(word)) { for (WebRelation r : web_forwardRelations(node)) { double dist = ai_gc_distanceFunction(web_text(r), true); if (!isNaN(dist)) ai_gc_scan_update(distances, queue, r.b, d+dist); } for (WebRelation r : web_backwardRelations(node)) { double dist = ai_gc_distanceFunction(web_text(r), false); if (!isNaN(dist)) ai_gc_scan_update(distances, queue, r.a, d+dist); } } } Collection keys = keys(distances); if (ai_inTestMode()) keys = keysSortedByValueDesc(distances); ai_gc_scan_maxDistance_reached = 0; for (S key : keys) { double d = distances.get(key); if (d > ai_gc_scan_maxDistance_reached) ai_gc_scan_maxDistance_reached = d; ai_postTriple(key, "has GC distance", formatDouble(d, 1)); } } } finally { ai_stopBuffering(); } ret print(l(distances) + "/" + l(indexedTerms()) + " terms were reached in " + toS(lastTiming(), 1) + " s GC scan from " + quote(root) + ". Max distance: " + formatDouble(ai_gc_scan_maxDistance_reached, 1)); } static void ai_gc_scan_update(Map distances, L queue, WebNode n, double d) { //S text = ai_shortenForIndex(web_text(n)); S text = web_text(n); Double od = distances.get(text); if (od == null || d < od) { distances.put(text, d); queue.add(text); } }