# OpenEuphoria Manual

## Euphoria v4.1

routine or constant name search

| Up |  |  | TOC | Index
<< 5 Formal Syntax | < 6.1.11 guru.ex | Up: 6 Mini-Guides | 6.1.13 key.ex > | 7 Included Tools >>

### 6.1.12 hash.ex

Hash Table Demo written by Junko C. Miura, RDS

This reads a text file and builds a hash table containing all of the unique words plus a count of how many times each word occurred. It outputs the words to and a bunch of hash table statistics to "hash.out".

#### 6.1.12.1 Example

    eui hash \euphoria\doc\library.doc

hash.ex (hash table) is faster than tree.ex (binary tree), but does not produce a sorted list of words.

#### 6.1.12.2 How it Works

hashing is generally much faster than searching a long linear list for a word. Instead of searching one big list, we create hundreds of small lists, and then use a "hash function" to tell us which small list (or "bucket") to search. For each word, the hash function will return an integer. For a given word, the hash function must always return the same integer. That integer is used as the index into a sequence of small word-lists. We can quickly search the selected small list for the word.

| Up |  |  | TOC | Index
<< 5 Formal Syntax | < 6.1.11 guru.ex | Up: 6 Mini-Guides | 6.1.13 key.ex > | 7 Included Tools >>