Next: Introduction, Previous: (dir), Up: (dir) [Contents][Index]
This is the cl-bplustree Reference Manual, generated automatically by Declt version 2.4 "Will Decker" on Wed Jun 20 10:59:41 2018 GMT+0.
• Introduction: | What cl-bplustree is all about | |
• Systems: | The systems documentation | |
• Files: | The files documentation | |
• Packages: | The packages documentation | |
• Definitions: | The symbols documentation | |
• Indexes: | Concepts, functions, variables and data types |
h1. 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. B+ trees main characteristics: * All the data is in the leaves, internal nodes hold only keys used for traversal, pointers between the leaves are kept, so range-retrieval is easy and efficient. * It is a generalization of a binary tree but instead of having only two pointers per node to other nodes it can have many more (this is called the order of the tree) because of this characteristic the tree has typically a large fanout and a small depth. For more information about B+ trees, check "Wikipedia":http://en.wikipedia.org/wiki/B%2B_tree. h2. Dependencies None. h2. Usage h3. @(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: bc. (defparameter *my-tree* (bplustree-new 4 :key (lambda (r) (parse-integer r)))) h3. @(bplustree-empty-p (tree))@ Returns true if the tree is empty. Example: bc. (bplustree-empty-p *my-tree*) -> T h3. @(bplustree-insert (record tree &optional key))@ 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. If _key_ is omitted, calls the _key_ function passed to bplustree-new on _record_. If _key_ is included, uses that directly as the key. This enables using a B+ tree as a key/value store instead of a sorted set. Examples: bc. (bplustree-insert "100" *my-tree*) (bplustree-insert "100" *my-tree* 100) h3. @(bplustree-insert-many (tree &rest items))@ Inserts all the records given into the _tree_. Returns the tree. Example: bc. (bplustree-insert-many *my-tree* "5" "10" "-1" "1337" "212" "32" "311" "52") h3. @(bplustree-search (key tree))@ Searches the value stored in the given _key_ in the given _tree_. Example: bc. (bplustree-search 311 *my-tree*) -> "311" h3. @(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: bc. (bplustree-search-range 0 1000 *my-tree*) -> ("5" "10" "32" "52" "100" "212" "311") h3. @(bplustree-search-next (key tree))@ Returns the first key after the passed _key_. Passing NIL for the _key_ returns the first key in the tree. The passed _key_ need not be in the tree. Still returns the first key greater than that, which IS in the tree. Returns NIL when passed the last key. The record corresponding to the key is returned as a second value. If the key was cached, T is returned as a third value. Examples: bc. (bplustree-search-next nil *my-tree*) -> (values -1 "-1") (bplustree-search-next -1 *my-tree*) -> (values 5 "-5" t) (bplustree-search-next 1337 *my-tree*) -> nil h3. @(bplustree-search-prev (key tree))@ Returns the key before the passed _key_. Passing NIL for the _key_ returns the last key in the tree. The passed _key_ need not be in the tree. Still returns the first key less than that, which IS in the tree. Returns NIL when passed the first key. The record corresponding to the key is returned as a second value. If the key was cached, T is returned as a third value. Examples: bc. (bplustree-search-prev nil *my-tree*) -> (values 1337 "1337") (bplustree-search-prev 1337 *my-tree*) -> (values 311 "311" t) (bplustree-search-prev -1 *my-tree*) -> nil h3. @(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: bc. (bplustree-delete 32 *my-tree*) (bplustree-search-range 0 1000 *my-tree*) ("5" "10" "52" "100" "212" "311") h3. @(bplustree-traverse (tree fn))@ Traverses all records in the tree in order from smallest to largest. As the B+ trees store data sorted already this operation is not expensive. Example: bc. (bplustree-traverse *my-tree* 'print) "-1" "5" "10" "32" "52" "212" "311" "1337" h3. @(bplustree-traverse-with-keys (tree fn))@ Traverses all records in the tree in order from smallest to largest, calling fn on each with two args: the key and the value. As the B+ trees store data sorted already this operation is not expensive. Example: bc. (bplustree-traverse-with-keys *my-tree* (lambda (k v) (print (list k v)))) (-1 "-1") (5 "5") (10 "10") (32 "32") (52 "52") (212 "212") (311 "311") (1337 "1337") h2. Final remarks I hope this code is useful to you in any sense, either for learning, reading or maybe actual practical use, I will be very glad if you can even modify it to suit your needs. If you have suggestions please send them my way. Be sure to read *COPYING* file as well.
Next: Files, Previous: Introduction, Up: Top [Contents][Index]
The main system appears first, followed by any subsystem dependency.
• The cl-bplustree system: |
Francisco Soto <ebobby@ebobby.org>
BSD
In-memory B+ tree
cl-bplustree.asd (file)
Files are sorted by type and then listed depth-first from the systems components trees.
• Lisp files: |
• The cl-bplustree.asd file: | ||
• The cl-bplustree/packages.lisp file: | ||
• The cl-bplustree/bplustree.lisp file: |
Next: The cl-bplustree/packages<dot>lisp file, Previous: Lisp files, Up: Lisp files [Contents][Index]
cl-bplustree.asd
cl-bplustree (system)
Next: The cl-bplustree/bplustree<dot>lisp file, Previous: The cl-bplustree<dot>asd file, Up: Lisp files [Contents][Index]
cl-bplustree (system)
packages.lisp
Previous: The cl-bplustree/packages<dot>lisp file, Up: Lisp files [Contents][Index]
packages.lisp (file)
cl-bplustree (system)
bplustree.lisp
Next: Definitions, Previous: Files, Up: Top [Contents][Index]
Packages are listed by definition order.
• The org.ebobby.bplustree package: |
packages.lisp (file)
common-lisp
Definitions are sorted by export status, category, package, and then by lexicographic order.
• Exported definitions: | ||
• Internal definitions: |
Next: Internal definitions, Previous: Definitions, Up: Definitions [Contents][Index]
• Exported functions: |
Previous: Exported definitions, Up: Exported definitions [Contents][Index]
Deletes a record from the given tree using the given key. Returns the tree with the record deleted.
bplustree.lisp (file)
bplustree.lisp (file)
Insert a record into the given tree using the given key. Returns the tree with the new record inserted.
If ‘key‘ is included, uses that instead of calling the key function on ‘record‘.
This enabled using the tree as a key/value store instead of a sorted set.
bplustree.lisp (file)
Insert as many records given into the tree. Returns the tree with the new records inserted.
bplustree.lisp (file)
Makes a new B+ tree with the given order.
bplustree.lisp (file)
Search for a record in the given tree using the given key.
bplustree.lisp (file)
Return the first key in ‘tree‘ after the passed ‘key‘.
Return the record as a second value.
If the third values is true, then the key and value were cached.
bplustree.lisp (file)
Return the key in ‘tree‘ before the passed ‘key‘.
Return the record as a second value.
If the third values is true, then the key and value were cached.
bplustree.lisp (file)
Search and return a range of records in the given tree between the given keys.
bplustree.lisp (file)
bplustree.lisp (file)
bplustree.lisp (file)
Previous: Exported definitions, Up: Definitions [Contents][Index]
• Internal macros: | ||
• Internal functions: | ||
• Internal structures: |
Next: Internal functions, Previous: Internal definitions, Up: Internal definitions [Contents][Index]
Generates the getter/setter functions for the btreeplus-node internal collections, keys and records.
bplustree.lisp (file)
Generates functions to transfer elements from a node into another node.
bplustree.lisp (file)
Wrap code inside a block that will create a dynamic variable that holds the comparer function.
bplustree.lisp (file)
Next: Internal structures, Previous: Internal macros, Up: Internal definitions [Contents][Index]
bplustree.lisp (file)
bplustree.lisp (file)
bplustree.lisp (file)
bplustree.lisp (file)
bplustree.lisp (file)
bplustree.lisp (file)
bplustree.lisp (file)
Call ‘fn‘ on each leaf record in ‘node‘.
bplustree.lisp (file)
Call ‘fn‘ with key and record for each leaf of ‘node‘.
bplustree.lisp (file)
Makes an empty B+ tree node with the given order and the optional type (:leaf or :internal).
bplustree.lisp (file)
bplustree.lisp (file)
bplustree.lisp (file)
Find the proper leaf node for the given key.
bplustree.lisp (file)
Get the next node using the given key in the given node.
bplustree.lisp (file)
Get the record with the given key in the given node, nil if none.
bplustree.lisp (file)
bplustree.lisp (file)
bplustree.lisp (file)
Move the keys and records going left to right from given starting point.
bplustree.lisp (file)
Move the keys and records from the given starting point to the right.
bplustree.lisp (file)
Is the node an internal node?
bplustree.lisp (file)
bplustree.lisp (file)
Sets both the key and record at the given index to the given B+ node.
bplustree.lisp (file)
bplustree.lisp (file)
bplustree.lisp (file)
bplustree.lisp (file)
bplustree.lisp (file)
Returns the minimum size a node can have (except root).
bplustree.lisp (file)
bplustree.lisp (file)
Get the number of keys based on the node size and node type.
bplustree.lisp (file)
bplustree.lisp (file)
Does the node have more records than it should?
bplustree.lisp (file)
bplustree.lisp (file)
bplustree.lisp (file)
bplustree.lisp (file)
bplustree.lisp (file)
bplustree.lisp (file)
bplustree.lisp (file)
bplustree.lisp (file)
Does the node have less records than it should?
bplustree.lisp (file)
Promotes the first key in the node, if its a leaf it simply returns it, if its an internal node it returns it but shifts the other keys to the left.
bplustree.lisp (file)
Search the given node keys vector using binary search.
Keys assumed to be sorted. Optional mix and max define the search space.
The keyword record-search indicates if you are looking for a record or a node.
bplustree.lisp (file)
Previous: Internal functions, Up: Internal definitions [Contents][Index]
bplustree.lisp (file)
structure-object (structure)
print-object (method)
bplustree-root (function)
(setf bplustree-root) (function)
bplustree-depth (function)
(setf bplustree-depth) (function)
bplustree-order (function)
(setf bplustree-order) (function)
bplustree-key (function)
(setf bplustree-key) (function)
bplustree-comparer (function)
(setf bplustree-comparer) (function)
bplustree-cache (function)
(setf bplustree-cache) (function)
bplustree.lisp (file)
structure-object (structure)
node-kind (function)
(setf node-kind) (function)
node-order (function)
(setf node-order) (function)
node-size (function)
(setf node-size) (function)
node-keys (function)
(setf node-keys) (function)
node-records (function)
(setf node-records) (function)
node-prev-node (function)
(setf node-prev-node) (function)
node-next-node (function)
(setf node-next-node) (function)
Previous: Definitions, Up: Top [Contents][Index]
• Concept index: | ||
• Function index: | ||
• Variable index: | ||
• Data type index: |
Next: Function index, Previous: Indexes, Up: Indexes [Contents][Index]
Jump to: | C F L |
---|
Jump to: | C F L |
---|
Next: Variable index, Previous: Concept index, Up: Indexes [Contents][Index]
Jump to: | (
B C F M N P S W |
---|
Jump to: | (
B C F M N P S W |
---|
Next: Data type index, Previous: Function index, Up: Indexes [Contents][Index]
Jump to: | C D K N O P R S |
---|
Jump to: | C D K N O P R S |
---|
Previous: Variable index, Up: Indexes [Contents][Index]
Jump to: | B C N O P S |
---|
Jump to: | B C N O P S |
---|