1
0
Fork 0

Change literal syntax to CB{

master
Michael Raitza 2020-02-24 16:26:17 +01:00
parent 921f1ca979
commit 7c61cdf984
2 changed files with 11 additions and 11 deletions

View File

@ -2,8 +2,8 @@ USING: arrays assocs byte-arrays help.markup help.syntax io.encodings.utf8
kernel math serialize trees.cb.private ; kernel math serialize trees.cb.private ;
IN: trees.cb IN: trees.cb
HELP: CBTREE{ HELP: CB{
{ $syntax "CBTREE{ { key value }... }" } { $syntax "CB{ { key value }... }" }
{ $values { "key" "a key" } { "value" "a value" } } { $values { "key" "a key" } { "value" "a value" } }
{ $description "Literal syntax for a crit-bit tree." } ; { $description "Literal syntax for a crit-bit tree." } ;
@ -22,20 +22,20 @@ HELP: key>bytes*
{ $values { "key" object } { "bytes" byte-array } } { $values { "key" object } { "bytes" byte-array } }
{ $description "Converts a key, which can be any " { $link object } ", into a " { $link byte-array } ". Standard methods convert strings into its " { $link utf8 } " byte sequences and " { $link float } " values into byte arrays representing machine-specific doubles. Integrals are converted into a byte sequence of at least machine word size in little endian byte order." { $description "Converts a key, which can be any " { $link object } ", into a " { $link byte-array } ". Standard methods convert strings into its " { $link utf8 } " byte sequences and " { $link float } " values into byte arrays representing machine-specific doubles. Integrals are converted into a byte sequence of at least machine word size in little endian byte order."
$nl $nl
"All other objects are serialized using " { $link object>bytes } ". In the standard implementation, this maps " { $link f } " to the byte array " { $snippet "B{ 110 }" } print-element " and " { $link t } " to " { $snippet "B{ 116 }" } ", which is identical to the respective integers." } ; "All other objects are serialized using " { $link object>bytes } ". In the standard implementation, this maps " { $link f } " to the byte array " { $snippet "B{ 110 }" } " and " { $link t } " to " { $snippet "B{ 116 }" } ", which is identical to the respective integers." } ;
ARTICLE: "trees.cb" "Binary crit-bit trees" ARTICLE: "trees.cb" "Binary crit-bit trees"
"The " { $vocab-link "trees.cb" } " vocabulary is a library for binary critical bit trees, a variant of PATRICIA tries. A crit-bit tree stores each element of a non-empty set of keys K in a leaf node. Each leaf node is attached to the tree of internal split nodes for bit strings x such that x0 and x1 are prefixes of (serialized byte arrays of) elements in K and ancestors of other bit strings higher up in the tree. Split nodes store the prefix compressed as two values, the byte number and bit position, in the subset of K at which the prefixes of all ancestors to the left differ from all ancestors to the right." "The " { $vocab-link "trees.cb" } " vocabulary is a library for binary critical bit trees, a variant of PATRICIA tries. A crit-bit tree stores each element of a non-empty set of keys " { $snippet "K" } " in a leaf node. Each leaf node is attached to the tree of internal split nodes for bit strings " { $snippet "x" } " such that " { $snippet "x0" } " and " { $snippet "x1" } " are prefixes of (serialized byte arrays of) elements in " { $snippet "K" } " and ancestors of other bit strings higher up in the tree. Split nodes store the prefix compressed as two values, the byte number and bit position, in the subset of " { $snippet "K" } " at which the prefixes of all ancestors to the left differ from all ancestors to the right."
$nl $nl
"Serialization on keys is implemented using " { $link key>bytes } ". Crit-bit trees can store arbitrary keys and values, even mixed. Due to the nature of crit-bit trees, for any given input set that shares a common prefix, the tree compresses the common prefix into the split node at the root extending the lookup by one for arbitrary long prefixes." "Serialization of keys is implemented using " { $link key>bytes } ". Crit-bit trees can store arbitrary keys and values, even mixed (but see implementation notes to " { $link key>bytes* } "). Due to the nature of crit-bit trees, for any given input key set that shares a common prefix, the tree compresses the common prefix into the split node at the root extending the lookup by one for arbitrary long prefixes."
$nl $nl
"Keys are serialized once for every lookup and insertion not adding a new leaf node. Two keys are serialized for every insertion adding a new leaf node to the tree." "Keys are serialized once for every lookup and insertion not adding a new leaf node. Two keys are serialized for every insertion adding a new leaf node to the tree."
$nl $nl
"Due to ordering ancestors at split nodes into crit-bit '0' (left) and crit-bit '1' (right) the order of the elements in a crit-bit tree is total allowing efficient suffix searches and minimum searches." "Due to ordering ancestors at split nodes into crit-bit '0' (left) and crit-bit '1' (right), the order of the elements in a crit-bit tree is total allowing efficient suffix searches and minimum searches."
$nl $nl
"Crit-bit trees consume 2 * n - 1 nodes in total for storing n elements; each internal split node consumes two pointers and two fixnums; each leaf node two pointers to the key and value. Their shape is unique for any given set of keys, which also means lookup times are deterministic for a known set of keys regardless of insertion order or the tree having been cloned." "Crit-bit trees consume 2 * " { $emphasis "n" } " - 1 nodes in total for storing " { $emphasis "n" } " elements; each internal split node consumes two pointers and two fixnums; each leaf node two pointers to the key and value. Their shape is unique for any given set of keys, which also means lookup times are deterministic for a known set of keys regardless of insertion order or the tree having been cloned."
$nl $nl
"Compared to hash tables, crit-bit trees provide fast access without being prone to malicious input (or a badly chosen hash function) and also provide ordered operations (e.g. finding minimums). Compared to heaps, they support exact searches and suffix searches in addition. Compared to other ordered trees (AVL, B-), they support the same set of operations while keeping a simpler inner structure." "Compared to hash tables, crit-bit trees provide fast access without being prone to malicious input (but see limitations of the standard implementation of " { $link key>bytes* } ") and also provide ordered operations (e.g. finding minimums). Compared to heaps, they support exact searches and suffix searches in addition. Compared to other ordered trees (AVL, B-), they support the same set of operations while keeping a simpler inner structure."
$nl $nl
"Crit-bit trees conform to the assoc protocol." "Crit-bit trees conform to the assoc protocol."
; ;

View File

@ -278,14 +278,14 @@ PRIVATE>
: >cb ( assoc -- tree ) : >cb ( assoc -- tree )
<cb> assoc-clone-like ; <cb> assoc-clone-like ;
SYNTAX: CBTREE{ SYNTAX: CB{
\ } [ >cb ] parse-literal ; \ } [ >cb ] parse-literal ;
<PRIVATE <PRIVATE
M: cb assoc-like drop dup cb? [ >cb ] unless ; M: cb assoc-like drop dup cb? [ >cb ] unless ;
M: cb pprint-delims drop \ CBTREE{ \ } ; M: cb pprint-delims drop \ CB{ \ } ;
M: cb >pprint-sequence >alist ; M: cb >pprint-sequence >alist ;
M: cb pprint-narrow? drop t ; M: cb pprint-narrow? drop t ;