dadhi / ImTools

Fast and memory-efficient immutable collections and helper data structures
MIT License
232 stars 10 forks source link

Provide number of slots to ImMapArray via struct type argument #24

Closed dadhi closed 5 years ago

dadhi commented 5 years ago
struct ImMapArray<V, Config> where Config : struct, IImArrayMapSlotConfig 
{
    public bool TryFind(int key, out V value) =>
        Slots[key & default(Config).SlotMask].TryFind(key & default(Config).KeyMask, out value); 
}

struct DefaultConfig : IImArrayMapSlotConfig
{
    public int SlotCount => 32;
    public int SlotMask  => 31;
    public int KeyMask  => ~31;  
}
dadhi commented 5 years ago

I've ended up passing it as parameter.