Your browser doesn't support the features required by impress.js, so you are presented with a simplified version of this presentation.

For the best experience please use the latest Chrome, Safari or Firefox browser.

Hardware Meetup - Sputnik, 24. october 2019

Hash tables

... the background of their implementations.


Samo Penič

About me...

Let's fill in the data...

    Name:
    Name:
    Name:
    Name:
    Name:
    Name:
    Name:
    Name:


What is a hash table

Sometimes also called associative array or dictionary. It is a data structure used to map key into values



data["Yoda"] gives us all the information stored for Yoda.



It is widely used to build things such us dictionaries, telephone books, book indexes, ...


Hash table provide Insertion, Deletion and Retreival in constant time!

However...

The memory is accessible by addressing the data numerically.

data[0]
Yoda
(01)123-1234
data[1]
Obi
(01)222-2222
data[2]
Luke
(01)123-1234
data[3]
Darth
(01)111-1111

e.g.: Accessing the item at memory location data[0] yields name of the person Yoda and person's phone number: (01)123-1234


Finding phone number of Darth requires linear search through the array, which is not efficient.

Mapping key to index

... is performed by so called hash functions. It can be as simple as sum(ascii_code[i]) % array_size


Let's try it out for our phone directory (array_size=13):





data[0]
 
 
data[1]
 
 
data[2]
 
 
data[3]
 
 
data[4]
 
 
data[5]
 
 
data[6]
 
 
data[7]
 
 
data[8]
 
 
data[9]
 
 
data[10]
 
 
data[11]
 
 
data[12]
 
 

Collisions!

They will occur. The probability depends on Load factor (LF=number_of_items/array_size)

We can cope with collisions in multitude of ways:

Closed addressing

data[0]
data[1]
data[2]
data[3]
data[4]
data[5]
data[6]
data[7]
data[8]
data[9]
data[10]
data[11]
data[12]
data[13]

Open addressing




data[0]
 
 
data[1]
 
 
data[2]
 
 
data[3]
 
 
data[4]
 
 
data[5]
 
 
data[6]
 
 
data[7]
 
 
data[8]
 
 
data[9]
 
 
data[10]
 
 
data[11]
 
 
data[12]
 
 

Hash function properties

Python dictionaries

Hash tables in firmware

Use a spacebar or arrow keys to navigate.
Press 'P' to launch speaker console.