# Lookup Tables

Can anyone explain what lookup tables are? I was wondering if they are the same as hash tables.

• : Can anyone explain what lookup tables are? I was wondering if they are the same as hash tables.
:

a "lookup table" can be quite a few different things. The simplest is just a one or two dimensional array, where the first dimension is a key and the second dimension is the lookup value. In some cases you may only need a one dimensional array -- such as keyboard scan codes can be one dimensional.

[code]
unsigned char keyboard[255] = {0,1,2,3,4,5,6...};

now to get the scan code based on the key value:

int key = 'A';
unsigned char ScanCode = keyboard[key];
[/code]

• : : Can anyone explain what lookup tables are? I was wondering if they are the same as hash tables.
: :
:
: a "lookup table" can be quite a few different things. The simplest is just a one or two dimensional array, where the first dimension is a key and the second dimension is the lookup value. In some cases you may only need a one dimensional array -- such as keyboard scan codes can be one dimensional.
:
: [code]
: unsigned char keyboard[255] = {0,1,2,3,4,5,6...};
:
: now to get the scan code based on the key value:
:
: int key = 'A';
: unsigned char ScanCode = keyboard[key];
: [/code]
:

A hash table is an efficient way to look things up in a table based on a key. So a hash function is merely an algorithm to look something up *efficiently*.

A great way to implement a look-up table is through the STL container std::map. It does all the work for you. For a 1-D look up, use std::set.

If you want to use a hash function, then the boost containers (www.boost.org) hast_set and hash_map are good candidates. Any good book on CS algorithms will explain how hash functions work.

Matt.