Insert, Lookup, Delete
Core operations.
The Three Core Operations
Every hash table supports three operations: insert, lookup, and delete. With a good hash and reasonable load factor, all three run in average O(1) time.
We will build a chaining-based table step by step.
The Table and Node Types
We define a node holding a copied key string and an integer value, plus a table struct holding the bucket array and its capacity.
#include <stdio.h>
typedef struct Node {
char *key;
int value;
struct Node *next;
} Node;
typedef struct {
Node **buckets;
unsigned capacity;
unsigned size;
} HashTable;
int main(void) {
printf("types defined\n");
return 0;
}All lessons in this course
- Hash Functions
- Collision Handling
- Insert, Lookup, Delete
- Resizing and Load Factor