jonnify·bcs /bcs/elixir-core/relations/dual-indexes

B2.5.3 · dive 3 of 3 · module B2.5

Dual private indexes.

Two :private ordered sets — fwd keyed {subject, object} for from, rev keyed {object, subject} for to — written together by one owner, so they cannot disagree. degree counts fwd without a scan.

A forward and a reverse ordered_set, written together by the single owner, traversed both ways. Select a part.
fwd · key {s, o}from(s): objects ascending rev · key {o, s}to(o): subjects ascending one owner writes bothlink, unlink: together:private, to nobody degree(s): count fwd, no scan
readout · Select a part. fwd keyed {subject, object} answers from; rev keyed {object, subject} answers to; both are :private and written together by one owner so they cannot disagree.
§1

The idea

echo_data · bcs/edge_store.ex

Traversal in both directions wants two orderings, so the store keeps two tables. A forward :ets ordered_set is keyed {subject, object} and answers from — the objects of a subject, ascending; a reverse table is keyed {object, subject} and answers to — the subjects of an object. degree counts a subject’s forward rows without listing them.

Both tables are :private and maintained together. A single owner writes the forward and reverse rows in the same link, deletes both in the same unlink, and exports neither, so the two indexes cannot disagree — there is no path by which one is updated and the other is not. The store hands out answers to from and to, never a table to read.

Codemojex reads its membership both ways without a scan. From a player, the rooms they are in; from a room, the players in it; the count of a player’s rooms without walking them — each a bounded key walk on one of the two tables. The same composite-key-is-the-index idea runs the parent-to-children hierarchy in EchoData.Edges, where a {parent, child} snowflake pair keeps a parent’s children contiguous and in creation order.

§4

The doors

the sibling courses
§2

References

sources · related

Sources

Related