treedb is a simple in-memory database for hierarchical keys. This means, your keys are structured like a path in a file system or a system regstry.
treedb comes with an ASDF system, so it can be loaded via ASDF or as a local project via quicklisp.
treedb lives in the package treedb
.
Here are some examples:
;;create a new instance
(defparameter *db* (treedb:make-alist-treedb))
;;set values:
(setf (treedb:node *db* :a :1) "Hello" ; /:a/:1 <- "Hello"
(treedb:node *db* :a :2) :world ; /:a/:2 <- :world
(treedb:node *db* :b) 1 ; /:b <- 1
(treedb:node *db* :c) '((1 . 2) (3 . 4))) ; /:c <- '((1 . 2) (3 . 4))
;;get values
(treedb:node *db* :a :1) ; => "Hello"
;;delete nodes
(treedb:del-node *db* :b)
;;list keys
(treedb:children *db*) ; => (:A :C)
(treedb:children *db* :a) ; => (:|1| :|2|)
;;take a subtree
(treedb:subtree *db* :a) ; => subtree from :a
;;convert to alists or json (via cl-json)
(treedb:to-alist (treedb:subtree *db* :a))
; => ((:1 . "Hello") (:2 . :world))
(treedb:to-json (treedb:subtree *db* :a))
; => "{\"2\":\"Hello\",\"2\":\"world\"}"
/k/e/y/s
Returns a list of keys, which are the children of the given node.
Deletes the value at /k/e/y/s
.
t
or nil
Tests, if /k/e/y/s
is a leaf in db
.
Returns an empty tree of type <alist-treedb>
.
/k/e/y/s
, t
/ nil
)
Returns the value of a leaf node as the first
and t
or nil
as the second value,
depending on if the node was found or not.
Can be used with setf
.
t
or nil
Tests, if /k/e/y/s
is a node in db
.
/k/e/y/s
Returns a new tree object with the contents of the subtree.
The new object has the same type as db
.
Returns the tree in alist form
nil
Serializes the tree into json objects.
If stream
is supplied, the json object is written to the corresponding stream.
Otherwise it is returned as a string.
/k/e/y/s or
default`
Returns the value at keys or, if it is not found,
default`.
Run the test specified by TEST-SPEC.
TEST-SPEC can be either a symbol naming a test or test suite, or a testable-object object. This function changes the operations performed by the !, !! and !!! functions.
Equivalent to (explain (run TEST-SPEC)).
Creates the documentation (doc/treedb.html) using cl-gendoc.