|
smollerGraph 0.20.2
A small graph database, from scratch
|
Accepted
From episode 1, a graph found a node by its name in a hash map in memory, and from episode 2, with the graph on disk, opening it rebuilt the map by reading every node record. On the generated graph of 100,000 people, opening it took 10.4 ms in episode 6: "ten times the nodes, ten times the wait", and the map took memory for each name, whether it was asked for or not.
NameIndex (name_index.h, episode 6) is a B+ tree in a file of its own, names, through a buffer pool of its own of up to 4,096 pages. Page 0 says which page is the root and how many pages there are. A page is a 16-byte header, whether it's a leaf, how many entries it has and, in a leaf, the next leaf, then its entries in name order. A leaf's entry is a name padded with zeros and the id kept for it; above the leaves, an entry is a name and the page with the names from it on.Find goes down from the root, with a binary search on each level. Insert goes down the same way, and splits a full page, keeping its first half and moving the rest to a new page on its right; above the leaves, the middle entry moves up, and a root that splits gets a new root above its two halves.NamesStartingWith reads names in order from where a prefix would go, leaf to leaf. GET /api/names answers with up to eight of them, which the page suggests as a name is typed.sg load timed itself. "That's a trade most databases make, and Neo4j's
indexes are B+ trees too."