/* * Copyright (c) 2025, Andreas Kling * Copyright (c) 2026, Luke Wilde * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include #include namespace GC { class GC_API RootHashTableBase { public: virtual void gather_roots(HashMap&) const = 0; protected: RootHashTableBase(); explicit RootHashTableBase(Heap&); ~RootHashTableBase(); Heap* m_heap { nullptr }; IntrusiveListNode m_list_node; public: using List = IntrusiveList<&RootHashTableBase::m_list_node>; }; template, bool IsOrdered = false> class RootHashTable final : public RootHashTableBase , public HashTable { using HashTableBase = HashTable; public: RootHashTable() : RootHashTableBase() { } ~RootHashTable() = default; virtual void gather_roots(HashMap& roots) const override { static_assert(Detail::RootableValueTraits::is_rootable, "RootHashTable element type must be convertible to Cell const* or derive from NanBoxedValue"); for (auto& value : *this) Detail::gather_root(roots, value, HeapRoot::Type::RootHashTable); } }; template> using OrderedRootHashTable = RootHashTable; }