Use TypeSet for DeclInfo deps

This commit is contained in:
gingerBill
2025-02-18 13:31:34 +00:00
parent 721bcf2249
commit 19b59461b0
4 changed files with 71 additions and 60 deletions
+7 -30
View File
@@ -57,11 +57,10 @@ gb_internal GB_COMPARE_PROC(type_info_pair_cmp) {
return x->hash < y->hash ? -1 : +1;
}
static constexpr u64 TYPE_SET_TOMBSTONE = ~(u64)(0ull);
gb_internal void type_set_init (TypeSet *s, isize capacity);
gb_internal void type_set_destroy(TypeSet *s);
gb_internal Type *type_set_add (TypeSet *s, Type *ptr);
gb_internal Type *type_set_add (TypeSet *s, TypeInfoPair pair);
gb_internal bool type_set_update (TypeSet *s, Type *ptr); // returns true if it previously existed
gb_internal bool type_set_update (TypeSet *s, TypeInfoPair pair); // returns true if it previously existed
gb_internal bool type_set_exists (TypeSet *s, Type *ptr);
@@ -73,34 +72,6 @@ gb_internal gbAllocator type_set_allocator(void) {
return heap_allocator();
}
struct TypeSetIterator {
TypeSet *set;
usize index;
TypeSetIterator &operator++() noexcept {
for (;;) {
++index;
if (set->capacity == index) {
return *this;
}
TypeInfoPair key = set->keys[index];
if (key.hash != 0 && key.hash != TYPE_SET_TOMBSTONE) {
return *this;
}
}
}
bool operator==(TypeSetIterator const &other) const noexcept {
return this->set == other.set && this->index == other.index;
}
operator TypeInfoPair *() const {
return &set->keys[index];
}
};
gb_internal TypeSetIterator begin(TypeSet &set) noexcept {
usize index = 0;
while (index < set.capacity) {
@@ -257,6 +228,12 @@ gb_internal Type *type_set_add(TypeSet *s, Type *ptr) {
return ptr;
}
gb_internal Type *type_set_add(TypeSet *s, TypeInfoPair pair) {
type_set_update(s, pair);
return pair.type;
}
gb_internal void type_set_remove(TypeSet *s, Type *ptr) {
isize index = type_set__find(s, ptr);