Common Lisp Package: ZCDB

README:

FUNCTION

Public

ADD-RECORD (KEY VALUE CDB-WRITER)

Add KEY and VALUE to a cdb file. KEY and VALUE should both be (unsigned-byte 8) vectors.

Undocumented

LOOKUP (KEY CDB)

MAP-CDB (FUNCTION CDB)

Private

BUCKET-HASH-VECTOR (BUCKET)

Create a hash vector for a bucket. A hash vector has 2x the entries of the bucket, and is initialized to an empty record pointer. The high 24 bits of the hash value of a record pointer, mod the size of the vector, is used as a starting slot, and the vector is walked (wrapping at the end) to find the first free slot for positioning each record pointer entry.

CALL-WITH-OUTPUT-TO-CDB (CDB-PATHNAME TEMP-PATHNAME FUN)

Call FUN with one argument, a CDB-WRITER instance to which records can be added with ADD-RECORD.

CDB-HASH (OCTETS)

http://cr.yp.to/cdb/cdb.txt

FINISH-CDB-WRITER (CDB-WRITER)

Write the trailing hash tables and leading table pointers to the cdb file.

WRITE-BUCKET-HASH-TABLE (BUCKET STREAM)

Write BUCKET's hash table vector to STREAM.

WRITE-CDB-U32 (U32 STREAM)

Write an (unsigned-byte 32) value to STREAM in little-endian order.

WRITE-HASH-TABLES (CDB-WRITER)

Write the traililng hash tables to the end of the cdb file. Initializes the position of the buckets in the process.

WRITE-POINTERS (CDB-WRITER)

Write the leading hash table pointers to the beginning of the cdb file. Must be called after WRITE-HASH-TABLES, or the positions won't be available.

Undocumented

LOOKUP-RECORD-AT (POSITION KEY STREAM)

MAKE-GROWABLE-VECTOR (&KEY (SIZE 10) (ELEMENT-TYPE T))

MAKE-OCTET-VECTOR (SIZE)

READ-CDB-U32 (STREAM)

STREAM-LOOKUP (KEY STREAM)

STREAM-MAP-CDB (FUNCTION STREAM)

TABLE-SLOT-LOOKUP (KEY HASH TABLE-POSITION INITIAL-SLOT SLOT-COUNT STREAM)

MACRO

Public

WITH-OUTPUT-TO-CDB ((CDB FILE TEMP-FILE) &BODY BODY)

Evaluate BODY with CDB bound to a CDB-WRITER object. The CDB in progress is written to TEMP-FILE, and then when the CDB is successfully written, TEMP-FILE is renamed to FILE. For atomic operation, FILE and TEMP-FILE must be on the same filesystem.

GENERIC-FUNCTION

Private

Undocumented

ENTRY-COUNT (OBJECT)

SLOT-COUNT (OBJECT)

SLOT-ACCESSOR

Private

ENTRIES (OBJECT)

A vector of record-pointers.

SETFENTRIES (NEW-VALUE OBJECT)

A vector of record-pointers.

HASH-VALUE (OBJECT)

The hash value of the record key.

SETFHASH-VALUE (NEW-VALUE OBJECT)

The hash value of the record key.

RECORD-POSITION (OBJECT)

The file position at which the record is stored.

SETFRECORD-POSITION (NEW-VALUE OBJECT)

The file position at which the record is stored.

TABLE-POSITION (OBJECT)

The file position at which this table is (eventually) slotted.

SETFTABLE-POSITION (NEW-VALUE OBJECT)

The file position at which this table is (eventually) slotted.

Undocumented

BUCKETS (OBJECT)

SETFBUCKETS (NEW-VALUE OBJECT)

END-OF-RECORDS-POSITION (OBJECT)

SETFEND-OF-RECORDS-POSITION (NEW-VALUE OBJECT)

OUTPUT (OBJECT)

SETFOUTPUT (NEW-VALUE OBJECT)

VARIABLE

Private

Undocumented

*EMPTY-RECORD-POINTER*

*POINTER-PADDING*

CLASS

Private

HASH-TABLE-BUCKET

During construction of the CDB, record pointers are accumulated into one of 256 hash table buckets, depending on the low 8 bits of the hash value of the key. At the end of record writing, these buckets are used to write out hash table vectors at the end of the file, and write pointers to the hash table vectors at the start of the file.

RECORD-POINTER

Every key/value record written to a CDB has a corresponding record pointer, which tracks the key's hash value and the record's position in the data file. When all records have been written to the file, these record pointers are organized into hash tables at the end of the cdb file.

Undocumented

CDB-WRITER

CONSTANT

Private

Undocumented

+INITIAL-HASH-VALUE+