Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
ArenaDict works like a normal
Dictionary<TKey, TValue>
but allocated to an unmanaged memory arena. It uses a single contiguous array of memory storage for both its backing array and any additional entries that are part of a linked list for a bucket with multiple items. The linked list's head is always found in the backing array. Linked list nodes are allocated via a bump allocator which starts after the backing array, and removed entries are stored in a freelist to be reused.The amount of items stored after the backing array always equals or exceeds the capacity of the backing array, which means that even in the worst case scenario of all entries mapping to a single bucket there is always enough space for all items before rebalancing occurs.
Though I have not tested it my assumption is that because the backing array and linked list node entries exist in the same contiguous memory area cache misses are reduced, at least for small dictionaries.
This dictionary uses fibonacci hashing, which means the capacity of the backing array must always be a power of 2.