Skip to main content

Practice ยท 1 of 1

Linear Probe + Tombstone

Implement an open-addressing table, long keys, int values. The boilerplate declares: ``c #define OTAB_CAP 16 /* status: 0 empty, 1 occupied, 2 tombstone */ typedef struct { long key; int value; int status; } OSlot; typedef struct { OSlot slots[OTAB_CAP]; size_t count; } OTab; void otab_init(OTab *t); /* all empty */ /* returns bucket index probed... no: 0 ok, 1 already-present (value updated), -1 table full (no empty AND no tombstone slot) */ int otab_put(OTab *t, long key, int value); int otab_get(const OTab *t, long key, int *out); /* 0 found, -1 absent */ /* marks a tombstone; 1 removed, 0 absent */ int otab_del(OTab *t, long key); size_t otab_size(const OTab *t); /* live entries only */ ` Hash: (size_t)key % OTAB_CAP`, linear probing. Deleted slots become tombstones โ€” they are skipped by get, reused by put.

Difficulty: intermediate

Back to lesson: Practice: Open Addressing Gym