Design decisions

108. Rooted.virtual returns a virtual tree over a fresh domain (2026-11-21)

  • Decision. t.virtual(keys) replaces t.virtual_tree(keys). It returns VirtualTree<V, K> whose own domain vt.K lists the kept vertices (keys and pairwise LCAs) in preorder, with at: [K]V, up: [K]?K, len: [K]Int (weighted distance to up) and key: [K]Bool. A per-query DP is then var dp: [vt.K]Int = 0 and for x in vt.K.rev, children first, with no [V] scratch to reset and no edge list to turn back into parents. Matched C++ (bench/trees/virtual_bench): 1.12x and 1.18x at n = 2·10^5, q = 10^5, k = 10; 0.9x at n = 10^6, k = 1000.
  • Reverse. Restore virtual_tree returning (nodes, edges) from history; callers rebuild parents from the edges.