Implementation of btree inspired by the book and an interface for reading/writing data to it.
go test -v ./... # run all tests in the project
go run main.go # build and run server
telnet localhost 8080 # open a tcp connection to the server
> 1paaa,bbb$ # [telnet prompt] put value 'bbb' with key 'aaa'
> gaaa$ # [telnet prompt] get value of the key 'aaa'
< sbbb$ # [telnet prompt] see data you've just entered (first symbol marks success/failure of the operation)
Repo consists of several packages:
- server (tcp server and a wire protocol implementations)
- btree (btree's interface and traversal implementation)
- storage (implementation of slotted pages used to store btree nodes and links between them)
- util
Dependency chain:
server -> btree -> storage
-> util
In a nutshell, this is a datastructure used to store data on disk. Seems that, postgres implements it to store and retrieve data associated with a primary key.
The same as for binary search tree, lookup is performed by triversing the tree. Although, there is an important distinction: nodes of a btree generally have a greater number of ancestors and this number is variable for each node.
This design is better suited for disk as data access require less separate disk io-operations. That means that more data can be read within one disk access, and this data will be immediately useful for tree triversal.
TBD: rebalancing algorithm and comparison to classical binary tree rotation technique.