Add LfIdMap and generational LfSlots #12

Merged
fputs merged 1 commit from fputs/slotmap into master 2026-11-05 09:44:22 -08:00 AGit
Owner

Adds LfIdMap and generational LfSlots in lfslotmap.h.

LfIdMap is an open-addressed table from uint64_t keys to inline uint32_t values. Capacity is a power of two, at least 8, and a new key grows before the load would pass 3/4. The key mix is the SplitMix64 finalizer, with no seed. Duplicate insert keeps the original value. Replace does not insert a missing key. Bucket order is unspecified.

LfSlots stores caller-owned void * payloads and does not free them. A stored NULL is a successful lookup. Fresh indexes start at generation 1. Generation 0 is never issued. Reuse bumps the generation. A stale id does not free the current occupant. A generation that cannot be bumped past UINT32_MAX stays on the free list and is not recycled, and a failed alloc does not change that list.

Both handles are complete structs so the caller can own them on the stack. The fields are private.

Allocation failure is covered for id-map init, a growing id-map insert, slots init, and a growing slots alloc. Previously inserted pairs and previously issued ids stay resolvable.

Tested with -DCMAKE_BUILD_TYPE=Debug -DFLINT_SANITIZE=ON -DCMAKE_C_EXTENSIONS=OFF. ctest --label-exclude slow: 26/26 passed.

Adds `LfIdMap` and generational `LfSlots` in `lfslotmap.h`. `LfIdMap` is an open-addressed table from `uint64_t` keys to inline `uint32_t` values. Capacity is a power of two, at least 8, and a new key grows before the load would pass 3/4. The key mix is the SplitMix64 finalizer, with no seed. Duplicate insert keeps the original value. Replace does not insert a missing key. Bucket order is unspecified. `LfSlots` stores caller-owned `void *` payloads and does not free them. A stored NULL is a successful lookup. Fresh indexes start at generation 1. Generation 0 is never issued. Reuse bumps the generation. A stale id does not free the current occupant. A generation that cannot be bumped past `UINT32_MAX` stays on the free list and is not recycled, and a failed alloc does not change that list. Both handles are complete structs so the caller can own them on the stack. The fields are private. Allocation failure is covered for id-map init, a growing id-map insert, slots init, and a growing slots alloc. Previously inserted pairs and previously issued ids stay resolvable. Tested with `-DCMAKE_BUILD_TYPE=Debug -DFLINT_SANITIZE=ON -DCMAKE_C_EXTENSIONS=OFF`. `ctest --label-exclude slow`: 26/26 passed.
Add LfIdMap and generational LfSlots
All checks were successful
test / test (pull_request) Successful in 13s
test / sanitize (pull_request) Successful in 16s
ba6c3b134a
fputs force-pushed fputs/slotmap from ba6c3b134a
All checks were successful
test / test (pull_request) Successful in 13s
test / sanitize (pull_request) Successful in 16s
to b226aa2618
All checks were successful
test / test (pull_request) Successful in 15s
test / sanitize (pull_request) Successful in 19s
2026-11-05 09:39:16 -08:00
Compare
fputs merged commit 9d5a8a04a1 into master 2026-11-05 09:44:22 -08:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
fputs/libflint!12
No description provided.