Factor handbook » The language » Collections

Next:Association lists

A hashtable provides efficient (expected constant time) lookup and storage of key/value pairs. Keys are compared for equality, and a hashing function is used to reduce the number of comparisons made. The literal syntax is covered in Hashtable syntax.

Words for constructing hashtables are in the hashtables vocabulary. Hashtables implement the Associative mapping protocol, and all Associative mapping operations can be used on them; there are no hashtable-specific words to access and modify keys, because associative mapping operations are generic and work with all associative mappings.

Hashtables are a class of objects.

hashtable? ( object -- ? )

You can create a new hashtable with an initial capacity.
<hashtable> ( n -- hash )

If you don't care about initial capacity, a more elegant way to create a new hashtable is to write:
H{ } clone

To convert an assoc to a hashtable:
>hashtable ( assoc -- hashtable )

Further topics:
Hashtable keys
Hashtable utilities
Hashtable implementation details