FE 0.15.0
A C++23 toolkit for writing compiler/interpreter frontends.
Loading...
Searching...
No Matches
fe::SymTab< V, Size > Class Template Reference

A fixed-capacity Symbol -> V map for a closed set of Size entries: filled once, then only looked up - a Lexer's reserved words, say. More...

#include <fe/sym.h>

Public Member Functions

Access
void emplace (Sym sym, V v)
std::optional< V > find (Sym sym) const
 Yields nothing if sym is not present - the empty Symbol never is.
bool contains (Sym sym) const

Static Public Attributes

static constexpr size_t Capacity = std::bit_ceil(2 * Size)
 Twice Size, rounded up to a power of two, so the load factor stays below 1/2.

Detailed Description

template<class V, size_t Size>
class fe::SymTab< V, Size >

A fixed-capacity Symbol -> V map for a closed set of Size entries: filled once, then only looked up - a Lexer's reserved words, say.

Prefer this over SymMap for that use: both hash and compare the same interned pointer, but SymMap pays a full finalizer and a SwissTable group probe where this pays one multiply and one probe of a table whose capacity is a compile-time constant.

Note
V has to be default-constructible; an absent key yields no V at all - see SymTab::find.
Warning
Insert-only: there is no erase, and SymTab::emplace asserts on a key already present.

Definition at line 253 of file sym.h.

Member Function Documentation

◆ contains()

template<class V, size_t Size>
bool fe::SymTab< V, Size >::contains ( Sym sym) const
inline

Definition at line 280 of file sym.h.

References find().

◆ emplace()

template<class V, size_t Size>
void fe::SymTab< V, Size >::emplace ( Sym sym,
V v )
inline

Definition at line 260 of file sym.h.

References fe::Sym::empty().

◆ find()

template<class V, size_t Size>
std::optional< V > fe::SymTab< V, Size >::find ( Sym sym) const
inline

Yields nothing if sym is not present - the empty Symbol never is.

Note
The free-slot test comes first: the empty Symbol is a free slot's key.

Definition at line 273 of file sym.h.

References fe::Sym::empty().

Referenced by contains().

Member Data Documentation

◆ Capacity

template<class V, size_t Size>
size_t fe::SymTab< V, Size >::Capacity = std::bit_ceil(2 * Size)
staticconstexpr

Twice Size, rounded up to a power of two, so the load factor stays below 1/2.

Definition at line 256 of file sym.h.


The documentation for this class was generated from the following file: