Docsity

Understand the Hashing, Slides of Computer Programming

Partial preview of the text

Download Understand the Hashing and more Slides Computer Programming in PDF only on Docsity!

Hashing

Hash function H(x) maps the value x at the index x%10 in an Array.

Hashing

Search Operation

struct DataItem *search(int key) { //get the hash int hashIndex = hashCode(key); if(hashArray[hashIndex]->key == key) return hashArray[hashIndex]; return NULL; }

Insert Operation

void insert(int key,int data) { struct DataItem item = (struct DataItem) malloc(sizeof(struct DataItem)); item->data = data; item->key = key; //get the hash int hashIndex = hashCode(key); hashArray[hashIndex] = item; }