Skip to main content

Practice · 1 of 4

Linear-Probing Hash Table

CHALLENGE
Difficulty: advanced+25 XP

Fixed-capacity int→int table with linear probing and tombstones: ``c #define HT_CAP 16 typedef struct { int key; int val; unsigned char state; } ht_ent_t; /* state: 0 empty, 1 used, 2 tombstone */ void ht_init(ht_ent_t *t); int ht_put(ht_ent_t *t, int key, int val); /* 1 stored, 0 full */ int *ht_get(ht_ent_t *t, int key); /* pointer to val, or NULL */ int ht_del(ht_ent_t *t, int key); /* 1 deleted, 0 absent */ ` Hash: ((unsigned)key * 2654435761u) % HT_CAP`. Probe forward with wraparound; insert may reuse tombstones; the table is never resized.

Back to lesson: Practice: Data Structure Build Drills