git subrepo clone git@github.com:Rconybea/xo-stringtable2.git xo-stringtable2
subrepo: subdir: "xo-stringtable2" merged: "356a03a0" upstream: origin: "git@github.com:Rconybea/xo-stringtable2.git" branch: "main" commit: "356a03a0" git-subrepo: version: "0.4.9" origin: "???" commit: "???"
This commit is contained in:
parent
05acb038a7
commit
323d5a62dc
37 changed files with 2640 additions and 0 deletions
69
xo-stringtable2/include/xo/stringtable2/StringTable.hpp
Normal file
69
xo-stringtable2/include/xo/stringtable2/StringTable.hpp
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
/** @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:
|
||||
/** hint_max_capacity in bytes = capacity for strings **/
|
||||
StringTable(size_type hint_max_capacity,
|
||||
bool debug_flag = false);
|
||||
|
||||
/** false -> not eligible for GC (maps own memory + not moveable) **/
|
||||
static constexpr bool is_gc_eligible() { return 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