|
vitrio 0.1.4
High-throughput image I/O for Cryo-Electron Microscopy (CryoEM)
|
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. | |
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.
| std::size_t vitrio::interned_key_list::append | ( | std::size_t | key_index | ) |
Append one entry referring to an interned key.
| key_index | Index of the key, as intern returned it. Must be below get_key_count. |
| std::out_of_range | If key_index names no interned key. |
| std::size_t vitrio::interned_key_list::append | ( | std::string | key | ) |
Intern a key and append one entry referring to it.
| key | The key to intern and refer to. |
|
noexcept |
Get the index a key was interned under.
| key | The key to look up. |
|
noexcept |
Get the key one entry refers to.
| entry_index | Position of the entry. Must be below get_entry_count. |
|
noexcept |
Get how many entries are held.
|
noexcept |
Get one of the interned keys.
| key_index | Index of the key. Must be below get_key_count. |
|
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.
|
noexcept |
Get which interned key one entry refers to.
| entry_index | Position of the entry. Must be below get_entry_count. |
| 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.
| key | The key to intern. |
| void vitrio::interned_key_list::reserve | ( | std::size_t | keys, |
| std::size_t | entries | ||
| ) |
Make room without allocating later.
| keys | Number of distinct keys to make room for. |
| entries | Number of entries to make room for. |
|
staticconstexpr |
Index reported for a key that was never interned.