vitrio 0.1.4
High-throughput image I/O for Cryo-Electron Microscopy (CryoEM)
Loading...
Searching...
No Matches
Public Member Functions | Static Public Attributes | List of all members
vitrio::interned_key_list Class Reference

A list of keys in which equal keys are held once. More...

#include <vitrio/interned_key_list.hpp>

Public Member Functions

 interned_key_list () noexcept
 Construct a list holding no key and no entry.
 
 interned_key_list (const interned_key_list &other)
 
 interned_key_list (interned_key_list &&other) noexcept
 
interned_key_list & operator= (const interned_key_list &other)
 
interned_key_list & operator= (interned_key_list &&other) noexcept
 
std::size_t intern (std::string key)
 Intern a key without appending an entry.
 
std::size_t append (std::size_t key_index)
 Append one entry referring to an interned key.
 
std::size_t append (std::string key)
 Intern a key and append one entry referring to it.
 
void clear () noexcept
 Drop every key and every entry, keeping both capacities.
 
void reserve (std::size_t keys, std::size_t entries)
 Make room without allocating later.
 
std::size_t find (const std::string &key) const noexcept
 Get the index a key was interned under.
 
std::size_t get_entry_count () const noexcept
 Get how many entries are held.
 
const std::string & get (std::size_t entry_index) const noexcept
 Get the key one entry refers to.
 
std::size_t get_key_index (std::size_t entry_index) const noexcept
 Get which interned key one entry refers to.
 
std::size_t get_key_count () const noexcept
 Get how many distinct keys are held.
 
const std::string & get_key (std::size_t key_index) const noexcept
 Get one of the interned keys.
 

Static Public Attributes

static constexpr std::size_t no_key
 Index reported for a key that was never interned.
 

Detailed Description

A list of keys in which equal keys are held once.

Each entry of the list refers to a key, and entries naming the same key share one copy of it: the distinct keys are held once and the entries are indices into them. A list naming a few keys many times over therefore costs a string per distinct key rather than per entry.

The list has two sizes. get_key_count is how many distinct keys were interned and get_entry_count how many entries there are. Each is addressed on its own: get_key takes a key index, get an entry index.

clear keeps both capacities, so a list refilled after clearing allocates only the strings of the keys it interns.

Member Function Documentation

◆ append() [1/2]

std::size_t vitrio::interned_key_list::append ( std::size_t  key_index)

Append one entry referring to an interned key.

Parameters
key_indexIndex of the key, as intern returned it. Must be below get_key_count.
Returns
std::size_t Position of the appended entry.
Exceptions
std::out_of_rangeIf key_index names no interned key.

◆ append() [2/2]

std::size_t vitrio::interned_key_list::append ( std::string  key)

Intern a key and append one entry referring to it.

Parameters
keyThe key to intern and refer to.
Returns
std::size_t Position of the appended entry.

◆ find()

std::size_t vitrio::interned_key_list::find ( const std::string &  key) const
noexcept

Get the index a key was interned under.

Parameters
keyThe key to look up.
Returns
std::size_t Its index, or no_key when it was never interned.

◆ get()

const std::string & vitrio::interned_key_list::get ( std::size_t  entry_index) const
noexcept

Get the key one entry refers to.

Parameters
entry_indexPosition of the entry. Must be below get_entry_count.
Returns
const std::string& The key. It refers to storage owned by this list, which interning into, assigning to or destroying it invalidates.

◆ get_entry_count()

std::size_t vitrio::interned_key_list::get_entry_count ( ) const
noexcept

Get how many entries are held.

Returns
std::size_t The number of entries.

◆ get_key()

const std::string & vitrio::interned_key_list::get_key ( std::size_t  key_index) const
noexcept

Get one of the interned keys.

Parameters
key_indexIndex of the key. Must be below get_key_count.
Returns
const std::string& The key. It refers to storage owned by this list, which interning into, assigning to or destroying it invalidates.

◆ get_key_count()

std::size_t vitrio::interned_key_list::get_key_count ( ) const
noexcept

Get how many distinct keys are held.

A key counts once however many entries refer to it, and also when none does, having been interned without an entry.

Returns
std::size_t The number of distinct keys.

◆ get_key_index()

std::size_t vitrio::interned_key_list::get_key_index ( std::size_t  entry_index) const
noexcept

Get which interned key one entry refers to.

Parameters
entry_indexPosition of the entry. Must be below get_entry_count.
Returns
std::size_t The key index, below get_key_count.

◆ intern()

std::size_t vitrio::interned_key_list::intern ( std::string  key)

Intern a key without appending an entry.

A key equal to one already interned yields the index it was given the first time rather than a second one, so a key can be interned once and referred to by index afterwards.

The interned keys are searched one by one, so this takes time in proportion to the number of distinct keys, not of entries.

Parameters
keyThe key to intern.
Returns
std::size_t Index of the key, below get_key_count.

◆ reserve()

void vitrio::interned_key_list::reserve ( std::size_t  keys,
std::size_t  entries 
)

Make room without allocating later.

Parameters
keysNumber of distinct keys to make room for.
entriesNumber of entries to make room for.

Member Data Documentation

◆ no_key

constexpr std::size_t vitrio::interned_key_list::no_key
staticconstexpr
Initial value:
=
std::numeric_limits<std::size_t>::max()

Index reported for a key that was never interned.


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