diff options
| author | gingerBill <bill@gingerbill.org> | 2020-11-15 21:22:26 +0000 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2020-11-15 21:22:26 +0000 |
| commit | 3a229397e48a3e8b408a51b52f366c63fc52f043 (patch) | |
| tree | 15c8eded03ba852bc85045c0a63f57b18b794123 /src/ptr_set.cpp | |
| parent | db0bcbc4f47afbb69bb172401ead7f484eed6b6c (diff) | |
Add next_pow2_isize for PtrSet
Diffstat (limited to 'src/ptr_set.cpp')
| -rw-r--r-- | src/ptr_set.cpp | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/ptr_set.cpp b/src/ptr_set.cpp index 890a0df1d..44bc1eca7 100644 --- a/src/ptr_set.cpp +++ b/src/ptr_set.cpp @@ -31,9 +31,26 @@ template <typename T> void ptr_set_grow (PtrSet<T> *s); template <typename T> void ptr_set_rehash (PtrSet<T> *s, isize new_count); +isize next_pow2_isize(isize n) { + if (n <= 0) { + return 0; + } + n--; + n |= n >> 1; + n |= n >> 2; + n |= n >> 4; + n |= n >> 8; + n |= n >> 16; + if (gb_size_of(isize) == 8) { + n |= n >> 32; + } + n++; + return n; +} + template <typename T> void ptr_set_init(PtrSet<T> *s, gbAllocator a, isize capacity) { - capacity = next_pow2(gb_max(16, capacity)); + capacity = next_pow2_isize(gb_max(16, capacity)); array_init(&s->hashes, a, capacity); array_init(&s->entries, a, 0, capacity); |