make hash table use an arena
This commit is contained in:
parent
94b9561545
commit
6a757dd36b
52
util.d
52
util.d
@ -13,40 +13,6 @@ import std.string;
|
||||
import core.stdc.string : memset;
|
||||
import core.simd;
|
||||
|
||||
struct DynSlice(T)
|
||||
{
|
||||
T[][] slices;
|
||||
u32 length;
|
||||
u32 capacity;
|
||||
u32 grow_size;
|
||||
}
|
||||
|
||||
DynSlice!(T)
|
||||
CreateDynSlice(T)(u32 size)
|
||||
{
|
||||
DynSlice!(T) dslice = {
|
||||
slices: MAllocArray!(T[])(size),
|
||||
length: 0,
|
||||
capacity: size,
|
||||
grow_size: size,
|
||||
};
|
||||
|
||||
dslice.slices[0] = MAllocArray!(T)(size);
|
||||
|
||||
return dslice;
|
||||
}
|
||||
|
||||
u32
|
||||
Next(T)(DynSlice!(T)* slice)
|
||||
{
|
||||
if (slice.length < slice.capacity)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
Logf(Args...)(string fmt, Args args)
|
||||
{
|
||||
@ -248,8 +214,9 @@ struct HashTable(K, V)
|
||||
SLList!(P) free_lists;
|
||||
SLList!(P)[] lists;
|
||||
Node!(P)* nil;
|
||||
u64 node_count;
|
||||
u64 list_count;
|
||||
Arena arena;
|
||||
u64 node_count;
|
||||
u64 list_count;
|
||||
|
||||
void opIndexAssign(V value, K key)
|
||||
{
|
||||
@ -270,20 +237,17 @@ struct HashTable(K, V)
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Result!(V) opIndexUnary(string s: "~")(K key)
|
||||
{
|
||||
return Delete(&this, key);
|
||||
}
|
||||
}
|
||||
|
||||
HashTable!(K, V)
|
||||
CreateHashTable(K, V)(u64 size)
|
||||
{
|
||||
auto nil = Alloc!(Node!(KVPair!(K, V)));
|
||||
auto lists = AllocArray!(SLList!(KVPair!(K, V)))(size);
|
||||
Arena arena = CreateArena(MB(4));
|
||||
auto nil = Alloc!(Node!(KVPair!(K, V)))(&arena);
|
||||
auto lists = AllocArray!(SLList!(KVPair!(K, V)))(&arena, size);
|
||||
|
||||
HashTable!(K, V) table = {
|
||||
arena: arena,
|
||||
lists: lists,
|
||||
list_count: size,
|
||||
nil: nil,
|
||||
@ -326,7 +290,7 @@ Push(K, V)(HashTable!(K, V)* ht, K key, V value)
|
||||
}
|
||||
else
|
||||
{
|
||||
node = Alloc!(N);
|
||||
node = Alloc!(N)(&ht.arena);
|
||||
}
|
||||
|
||||
node.next = ht.nil;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user