Orcus
Loading...
Searching...
No Matches
orcus::string_pool Class Reference

#include <string_pool.hpp>

Public Member Functions

 string_pool (const string_pool &)=delete
 
string_pooloperator= (const string_pool &)=delete
 
 string_pool (string_pool &&other)
 
std::pair< std::string_view, bool > intern (std::string_view str)
 
std::vector< std::string_view > get_interned_strings () const
 
void dump () const
 
void clear ()
 
size_t size () const
 
void swap (string_pool &other)
 
void merge (string_pool &other)
 

Detailed Description

This class implements a shared string pool with the ability to merge with other pools.

Note
This class is not copy-constructible, but is move-constructible.

Member Function Documentation

◆ clear()

void orcus::string_pool::clear ( )

Clear pool's content.

◆ dump()

void orcus::string_pool::dump ( ) const

Dump pool's content to stdout.

Todo
This needs to be reworked to make it more generally usable.

◆ get_interned_strings()

std::vector< std::string_view > orcus::string_pool::get_interned_strings ( ) const

Return all interned strings.

Returns
sequence of all interned strings. The sequence will be sorted.

◆ intern()

std::pair< std::string_view, bool > orcus::string_pool::intern ( std::string_view str)

Intern a string.

Parameters
strstring to intern.
Returns
pair whose first value is the interned string, and the second value specifies whether it is a newly created instance (true) or a reuse of an existing instance (false).

◆ merge()

void orcus::string_pool::merge ( string_pool & other)

Merge another string pool instance in. This will not invalidate any string references to the other pool.

The other string pool instance will become empty when this call returns.

Parameters
otherstring pool instance to merge in.

◆ size()

size_t orcus::string_pool::size ( ) const

Query the total number of strings stored in the pool.

Returns
size_t total number of strings in the pool.

◆ swap()

void orcus::string_pool::swap ( string_pool & other)

Swap the content with another string-pool instance.

Parameters
otherstring-pool instance to swap contents with.