factor/doc/handbook/collections.facts

74 lines
2.6 KiB
Plaintext

USING: graphs hashtables hashtables-internals help io-internals
kernel kernel-internals namespaces queues ;
ARTICLE: "collections" "Collections"
"Classical data structures:"
{ $subsection "sequences" }
{ $subsection "hashtables" }
"An abstraction on hashtables:"
{ $subsection "namespaces" }
"Special-purpose data structures:"
{ $subsection "queues" }
{ $subsection "graphs" }
"A low-level facility:"
{ $subsection "buffers" } ;
ARTICLE: "queues" "Queues"
"Last-in-first-out queues can be found in the " { $vocab-link "queues" } " vocabulary."
{ $subsection queue? }
{ $subsection <queue> }
{ $subsection queue-empty? }
{ $subsection deque }
{ $subsection enque }
"An example:"
{ $code
"<queue> \"q\" set"
"5 \"q\" get enque"
"3 \"q\" get enque"
"7 \"q\" get enque"
"\"q\" get deque ."
" 5"
"\"q\" get deque ."
" 3"
"\"q\" get deque ."
" 7"
} ;
ARTICLE: "graphs" "Directed graphs"
"A minimalist directed graph data type can be found in the " { $vocab-link "graphs" } " vocabulary. A directed graph is represented as a hashtable mapping each vertex to a set of edges entering that vertex, where the set is represented as a hashtable with equal keys and values."
$terpri
"To create a new graph, just call " { $link <hashtable> } " or construct a hashtable by some other means. To add vertices and edges to a graph:"
{ $subsection add-vertex }
{ $subsection build-graph }
"To remove vertices from the graph:"
{ $subsection remove-vertex }
{ $subsection clear-hash }
"You can perform queries on the graph:"
{ $subsection in-edges }
{ $subsection closure }
"Directed graphs are used to maintain cross-referencing information for words (" { $link "word-crossref" } ")." ;
ARTICLE: "buffers" "Locked I/O buffers"
"I/O buffers are a circular ring structure, a fixed-size queue of characters. Their key feature is that they are backed by manually allocated storage that does not get moved by the garbage collector. They are typically used for asynchronous I/O in conjunction with the C library interface in Factor's implementation."
$terpri
"Buffer words are in the " { $vocab-link "io-internals" } " vocabulary."
{ $subsection buffer }
{ $subsection <buffer> }
"Buffers must be manually deallocated:"
{ $subsection buffer-free }
"Buffer operations:"
{ $subsection buffer-reset }
{ $subsection buffer-length }
{ $subsection buffer-empty? }
{ $subsection buffer-capacity }
"Reading from the buffer:"
{ $subsection buffer-peek }
{ $subsection buffer-pop }
{ $subsection buffer> }
{ $subsection buffer>> }
{ $subsection buffer-contents }
"Writing to the buffer:"
{ $subsection extend-buffer }
{ $subsection ch>buffer }
{ $subsection >buffer } ;