mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 15:48:51 +00:00
Just use a method instead
This commit is contained in:
+15
-9
@@ -13,16 +13,22 @@ enum : MapIndex { MAP_SENTINEL = ~(MapIndex)0 };
|
|||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct PtrMapConstant {
|
struct PtrMapConstant {
|
||||||
static constexpr void const *TOMBSTONE = reinterpret_cast<void *>(~(uintptr)0);
|
static gb_inline T const TOMBSTONE() {
|
||||||
|
return (T)reinterpret_cast<void *>(~(uintptr)0);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
struct PtrMapConstant<u64> {
|
struct PtrMapConstant<u64> {
|
||||||
static constexpr u64 TOMBSTONE = ~(u64)0;
|
static gb_inline u64 const TOMBSTONE() {
|
||||||
|
return ~(u64)0;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
template <>
|
template <>
|
||||||
struct PtrMapConstant<i64> {
|
struct PtrMapConstant<i64> {
|
||||||
static constexpr i64 TOMBSTONE = ~(i64)0;
|
static gb_inline i64 const TOMBSTONE() {
|
||||||
|
return ~(i64)0;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename K, typename V>
|
template <typename K, typename V>
|
||||||
@@ -113,7 +119,7 @@ gb_internal void map__insert(PtrMap<K, V> *h, K key, V const &value) {
|
|||||||
MapIndex original_index = index;
|
MapIndex original_index = index;
|
||||||
do {
|
do {
|
||||||
auto *entry = h->entries+index;
|
auto *entry = h->entries+index;
|
||||||
if (!entry->key || entry->key == PtrMapConstant<K>::TOMBSTONE) {
|
if (!entry->key || entry->key == PtrMapConstant<K>::TOMBSTONE()) {
|
||||||
entry->key = key;
|
entry->key = key;
|
||||||
entry->value = value;
|
entry->value = value;
|
||||||
h->count += 1;
|
h->count += 1;
|
||||||
@@ -161,7 +167,7 @@ gb_internal void map_reserve(PtrMap<K, V> *h, isize cap) {
|
|||||||
for (u32 i = 0; i < h->capacity; i++) {
|
for (u32 i = 0; i < h->capacity; i++) {
|
||||||
auto *entry = h->entries+i;
|
auto *entry = h->entries+i;
|
||||||
if (entry->key &&
|
if (entry->key &&
|
||||||
entry->key != PtrMapConstant<K>::TOMBSTONE) {
|
entry->key != PtrMapConstant<K>::TOMBSTONE()) {
|
||||||
map__insert(&new_h, entry->key, entry->value);
|
map__insert(&new_h, entry->key, entry->value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -271,7 +277,7 @@ template <typename K, typename V>
|
|||||||
gb_internal void map_remove(PtrMap<K, V> *h, K key) {
|
gb_internal void map_remove(PtrMap<K, V> *h, K key) {
|
||||||
MapIndex found_index = 0;
|
MapIndex found_index = 0;
|
||||||
if (map_try_get(h, key, &found_index)) {
|
if (map_try_get(h, key, &found_index)) {
|
||||||
h->entries[found_index].key = cast(K)PtrMapConstant<K>::TOMBSTONE;
|
h->entries[found_index].key = cast(K)PtrMapConstant<K>::TOMBSTONE();
|
||||||
h->count -= 1;
|
h->count -= 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -381,7 +387,7 @@ struct PtrMapIterator {
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
PtrMapEntry<K, V> *entry = map->entries+index;
|
PtrMapEntry<K, V> *entry = map->entries+index;
|
||||||
if (entry->key && entry->key != PtrMapConstant<K>::TOMBSTONE) {
|
if (entry->key && entry->key != PtrMapConstant<K>::TOMBSTONE()) {
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -418,7 +424,7 @@ gb_internal PtrMapIterator<K, V> begin(PtrMap<K, V> &m) noexcept {
|
|||||||
MapIndex index = 0;
|
MapIndex index = 0;
|
||||||
while (index < m.capacity) {
|
while (index < m.capacity) {
|
||||||
auto key = m.entries[index].key;
|
auto key = m.entries[index].key;
|
||||||
if (key && key != PtrMapConstant<K>::TOMBSTONE) {
|
if (key && key != PtrMapConstant<K>::TOMBSTONE()) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
index++;
|
index++;
|
||||||
@@ -434,7 +440,7 @@ gb_internal PtrMapIterator<K, V> const begin(PtrMap<K, V> const &m) noexcept {
|
|||||||
MapIndex index = 0;
|
MapIndex index = 0;
|
||||||
while (index < m.capacity) {
|
while (index < m.capacity) {
|
||||||
auto key = m.entries[index].key;
|
auto key = m.entries[index].key;
|
||||||
if (key && key != PtrMapConstant<K>::TOMBSTONE) {
|
if (key && key != PtrMapConstant<K>::TOMBSTONE()) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
index++;
|
index++;
|
||||||
|
|||||||
Reference in New Issue
Block a user