xo-interpreter2 stack: refactor: string clases -> xo-stringtable2/
This commit is contained in:
parent
dc530ea9d8
commit
ab61cddb6b
41 changed files with 550 additions and 111 deletions
65
xo-stringtable2/include/xo/stringtable2/StringTable.hpp
Normal file
65
xo-stringtable2/include/xo/stringtable2/StringTable.hpp
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
/** @file StringTable.hpp
|
||||
*
|
||||
* @author Roland Conybeare, Jan 2026
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "DUniqueString.hpp"
|
||||
#include <xo/arena/DArenaHashMap.hpp>
|
||||
#include <xo/arena/DArena.hpp>
|
||||
#include <xo/arena/hashmap/verify_policy.hpp>
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
|
||||
/** @class StringTable
|
||||
* @brief table containing a set of interned strings
|
||||
*
|
||||
* A table of strings referenced in schematika expressions
|
||||
**/
|
||||
class StringTable {
|
||||
public:
|
||||
using DArena = xo::mm::DArena;
|
||||
using MemorySizeVisitor = xo::mm::MemorySizeVisitor;
|
||||
using StringMap = xo::map::DArenaHashMap<std::string_view,
|
||||
DUniqueString*>;
|
||||
using size_type = StringMap::size_type;
|
||||
|
||||
public:
|
||||
StringTable(size_type hint_max_capacity,
|
||||
bool debug_flag = false);
|
||||
|
||||
/** lookup interned string; nullptr if not present **/
|
||||
const DUniqueString * lookup(std::string_view key) const;
|
||||
|
||||
/** return unique string with contents @p key. Idempotent! **/
|
||||
const DUniqueString * intern(std::string_view key);
|
||||
|
||||
/** generate unique symbol -- guaranteed not to collide
|
||||
* with existing symbol in this table.
|
||||
**/
|
||||
const DUniqueString * gensym(std::string_view prefix);
|
||||
|
||||
/** verify StringTable invariants.
|
||||
* Act on failure according to policy @p p
|
||||
**/
|
||||
bool verify_ok(verify_policy p = verify_policy::throw_only()) const;
|
||||
|
||||
/** visit string-table memory pools, call visitor(info) for each **/
|
||||
void visit_pools(const MemorySizeVisitor & visitor) const;
|
||||
|
||||
private:
|
||||
/** allocate string storage in this arena; use DString to represent each string.
|
||||
* Can't use DArenaVector b/c DString has variable size
|
||||
**/
|
||||
DArena strings_;
|
||||
/** map_[s] points to arena strings, i.e. members of @ref strings_ **/
|
||||
StringMap map_;
|
||||
};
|
||||
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end StringTable.hpp */
|
||||
Loading…
Add table
Add a link
Reference in a new issue