vitrio 0.1.4
High-throughput image I/O for Cryo-Electron Microscopy (CryoEM)
Loading...
Searching...
No Matches
interned_key_list.hpp
1// SPDX-License-Identifier: LGPL-2.1-or-later
2
3#pragma once
4
5#include <vitrio/export.hpp>
6
7#include <cstddef>
8#include <limits>
9#include <string>
10#include <vector>
11
12namespace vitrio
13{
14
32{
33public:
38 static constexpr std::size_t no_key =
39 std::numeric_limits<std::size_t>::max();
40
46
53
58
73 std::size_t intern(std::string key);
74
84 std::size_t append(std::size_t key_index);
85
93 std::size_t append(std::string key);
94
100
108 void reserve(std::size_t keys, std::size_t entries);
109
118 std::size_t find(const std::string &key) const noexcept;
119
127
138 const std::string& get(std::size_t entry_index) const noexcept;
139
148 std::size_t get_key_index(std::size_t entry_index) const noexcept;
149
160
171 const std::string& get_key(std::size_t key_index) const noexcept;
172
173private:
174 std::vector<std::string> m_keys;
175 std::vector<std::size_t> m_entries;
176};
177
178} // namespace vitrio
A list of keys in which equal keys are held once.
Definition interned_key_list.hpp:32
std::size_t get_entry_count() const noexcept
Get how many entries are held.
void reserve(std::size_t keys, std::size_t entries)
Make room without allocating later.
static constexpr std::size_t no_key
Index reported for a key that was never interned.
Definition interned_key_list.hpp:38
interned_key_list() noexcept
Construct a list holding no key and no entry.
std::size_t find(const std::string &key) const noexcept
Get the index a key was interned under.
void clear() noexcept
Drop every key and every entry, keeping both capacities.
std::size_t append(std::size_t key_index)
Append one entry referring to an interned key.
std::size_t get_key_count() const noexcept
Get how many distinct keys are held.
std::size_t intern(std::string key)
Intern a key without appending an entry.
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.
const std::string & get_key(std::size_t key_index) const noexcept
Get one of the interned keys.
A view of a contiguous sequence of elements.
Definition span.hpp:29