Dict
Source: lib/Dict.cs
This page is generated from the source by scripts/gen-reference.py.
Dict<TKey, TValue>: open-addressing hash map backed by an Arena.
Like List
Keys are hashed (FNV-1a) and compared by their raw bytes. That is exact for integers and for structs without padding. It is NOT value equality for floats (0.0 vs -0.0, NaN payloads) or for structs whose padding bytes may differ, so avoid such keys or normalize them first.
Members
Create
public static Dict<TKey, TValue> Create(Arena arena, int capacity = 32)
Returns a new map in arena, or a not-created map if it is out of memory.
IsCreated
public bool IsCreated
Count
public int Count
Set
public bool Set(TKey key, TValue value)
Inserts or overwrites. Returns false if the map isn't created or the arena is full.
TryGet
public bool TryGet(TKey key, out TValue value)
ContainsKey
public bool ContainsKey(TKey key)
Remove
public bool Remove(TKey key)
Removes a key. Returns false if it wasn't there.
GetEnumerator
public Enumerator GetEnumerator()
For foreach: every key and value, in no particular order.
foreach (var pair in scores) total += pair.Value;
Don't Set or Remove during the loop: entries move, so some may be skipped or seen twice.
Clone
public Dict<TKey, TValue> Clone(Arena target)
Returns an independent copy in target (this map's own arena or another one). Returns a not-created map if this one isn't created or the target is out of memory.
Keys and values are copied as they are. One that is, or contains, a pointer still points wherever it did: into the original's arena, if that's where it led.
Dict.Pair
A key with its value, as foreach yields them.
Key
public TKey Key
Value
public TValue Value