Next: , Previous: Using Transactions, Up: Tutorial


2.9 Using BTrees

The btree class are to hash-tables as persistent-objects are to ordinary objects. BTrees have a hash-table-like interface, but store their keys and values directly as rows in a Sleepycat BTree. Btrees may be persisted simply by their OID. Hence they have all the nice properties of persistent objects: identity, fast serialization / deserialization, no merge conflicts.....

     * (defvar *friends-birthdays* (make-btree))
     => *FRIENDS-BIRTHDAYS*
     
     * (add-to-root "friends-birthdays" *friends-birthdays*)
     => #<BTREE {4951CF6D}>
     
     * (setf (get-value "Andrew" *friends-birthdays*)
     	(encode-universal-time 0 0 0 22 12 1976))
     => 2429071200
     
     * (setf (get-value "Ben" *friends-birthdays*)
     	(encode-universal-time 0 0 0 14 4 1976))
     => 2407298400
     
     *  (get-value "Andrew" *friends-birthdays*)
     => 2429071200
     => T
     
     * (decode-universal-time *)
     => 0
        0
        0
        22
        12
        1976
        2
        NIL
        6

Because of serialization semantics, BTrees hash on a value, not identity. This is probably ok for strings, numbers, and persistent things, but may be strange for other values.