cl-bplustree – A Common Lisp implementation of an in-memory B+ tree.
cl-bplustree is an implementation of a in-memory B+ tree data structure in Common Lisp.
https://github.com/ebobby/cl-bplustree
Dependencies
None.
Usage :
------------------------------------------------------------------------
(bplustree-new (order &key key comparer))
Creates a new empty B+ tre of the given order and returns it.
The key parameter expects a function used to grab the key values (used for sorting) on whatever you are stuffing into the tree, the function will be called with one parameter (a record to be inserted into the tree for example) and it should return the value that will be used as a key. It defaults to #'identity.
The comparer parameter expects a function used when comparing keys against each other in the tree operations. This function has to take two parameters (keys of records) and return a value depending on the following conditions:
(< a b) → -1
(= a b) → 0
(> a b) → 1
The meaning of this of course is given by your particular keys and your particular applications, for string keys for example string<, string>, etc., could be used.
This parameter defaults to a function that implements the explained logic but for numerical keys. If your keys are numeric, you don’t need to supply a comparison function.
Example:
(defparameter *my-tree* (bplustree-new 4 :key (lambda (r) (parse-integer r))))
------------------------------------------------------------------------
(bplustree-insert (record tree))
Inserts the given record into the given tree, if the given key already exists in the tree, the value is updated. Returns the tree but is not needed to capture it and assign it,this call is not destructive on the tree itself, althought its internal elements are changed by it.
Example:
(bplustree-insert "100" *my-tree*)
(bplustree-insert-many (tree &rest items))
Inserts all the records given into the tree. Returns the tree.
Example:
(bplustree-insert-many *my-tree* "5" "10" "-1" "1337" "212" "32" "311" "52")
------------------------------------------------------------------------
(bplustree-search (key tree))
Searches the value stored in the given key in the given tree.
Example:
(bplustree-search 311 *my-tree*) -> "311"
------------------------------------------------------------------------
(bplustree-search-range (from to tree))
Searches the tree for all the records that exists between the given from and to keys and returns them in a list.
Example:
(bplustree-search-range 0 1000 *my-tree*) -> ("5" "10" "32" "52" "100" "212" "311")
------------------------------------------------------------------------
(bplustree-delete (key tree))
Deletes the record stored in the given key in the tree. Returns the tree but is not needed to capture it and assign it, this call is not destructive on the tree itself, althought its internal elements are changed by it.
Example:
(bplustree-search-range 0 1000 *my-tree*) -> ("5" "10" "32" "52" "100" "212" "311")
(bplustree-delete 32 *my-tree*)
(bplustree-search-range 0 1000 *my-tree*) -> ("5" "10" "52" "100" "212" "311")
------------------------------------------------------------------------
PS. Sorry about the repost, the text needed more editing.