I found out, that in CL hash table has a type HASH-TABLE (surprisingly). However, a vector can be just VECTOR, but it also can be specified further as (vector number 12), for example.
It seems only natural for hash-table to have a list type, like, (hash-table number cons) or something, but it doesn't seem to work, and I cannot find any reference to it. Any advice?
The Hash data typeThe data type of hashes is Hash . By default, Hash matches hashes of any size, as long as their keys match the abstract type Scalar and their values match the abstract type Data . You can use parameters to restrict which values Hash will match.
A dictionary is a data structure that maps keys to values. A hash table is a data structure that maps keys to values by taking the hash value of the key (by applying some hash function to it) and mapping that to a bucket where one or more values are stored.
A hash table is simply an array that is addressed via a hash function. For example, in Figure 3-1, HashTable is an array with 8 elements. Each element is a pointer to a linked list of numeric data. The hash function for this example simply divides the data key by 8, and uses the remainder as an index into the table.
TL;DR typed vectors may be optimized for memory usage, but typed hash-tables are mostly pointless.
Disclaimer: this is mostly based on intuition and it's not even close to an authoritative answer.
Typed vectors are useful because they're the most practical way to store data contiguously in memory -- if you know the type (and thanks to that, also the size) of all elements, it's trivial to allocate just enough memory to store all of them together. As you may already know, CL's bit vectors are just that: an abstraction for optimally stored, individually accessible bits. Without type information, you must store a vector of pointers to scattered pieces of actual data.
If you're familiar with how a simple hash-table is implemented, then you know that type information is less useful here. It is kinda awkward to store the actual data in the table (which is usually a vector of pointers instead), either because dealing with hash-key collisions becomes harder (or else you would end up with a linked list anyway), or because resizing the table would involve copying all the data to a new table, instead of just changing a few pointers. Of course resizing a vector also requires copying everything, but it's done in a single step, while for the hash-table it must be done once for every element, because their positions in the table will have changed. There's mostly no benefit.
Also, a typed hash-table doesn't sound very Lispy.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With