A '''hash''' is a data structure. In Tcl, it is used for [array]s, [dict]s, and many other things. For [C] programmers, the convenient and generic hash functions are one of the advantages of using the [Tcl Portable Runtime Library]. A hash associates a ''value'' to each of zero or more ''keys'', which are typically not sequential. The basic idea is to store the pairs of key and value in a vector (like a Tcl list), at a position computed by applying the ''hash function'' to the key. A good hash function thoroughly mixes the bits in the key and thereby produces a seemingly random number from each possible key. Chances are fairly good that no two keys in a particular hash get the same hash number, and then one can find the value corresponding to a key by computing its hash number and looking up the corresponding entry in the hash table vector. Of course, sometimes two keys ''do'' get the same number, and then one need some strategy for handling such situations. Older literature often consider schemes for walking around the hash table vector until an empty entry is found an putting key+value pairs there when inserting; similarly one would when looking up a key have to walk ahead until finding an empty entry before concluding that the key wasn't in the hash. Newer implementations rather tend to have each vector entry (a "bucket") be a pointer to a linked list of the key+value pairs that should fall in this entry. Efficiency in hashes depend on having sufficiently many buckets that collisions don't happen too often, but having too many buckets is a waste of memory. Tcl hashes automatically adjust to the number of keys by occationally resizing themselves. See also: * [array statistics] * [Judy array] * [skiplist] ---- !!!!!! %| [Category Concept] | [Category Data Structure] |% !!!!!!