mdds
Toggle main menu visibility
Loading...
Searching...
No Matches
include
mdds
sorted_string_map.hpp
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3
// SPDX-FileCopyrightText: 2022 - 2025 Kohei Yoshida
4
//
5
// SPDX-License-Identifier: MIT
6
7
#pragma once
8
9
#include "./cref_wrapper.hpp"
10
11
#include <string_view>
12
#include <span>
13
#include <unordered_map>
14
15
namespace
mdds {
16
17
namespace
ssmap {
18
namespace
detail {
19
20
template
<
typename
ValueT>
21
struct
map_entry
22
{
23
std::string_view key;
24
ValueT value;
25
};
26
27
}
// namespace detail
28
33
template
<
typename
ValueT>
34
class
linear_key_finder
35
{
36
using
value_type = ValueT;
37
using
size_type =
typename
std::string_view::size_type;
38
using
entry_type =
detail::map_entry<ValueT>
;
39
40
const
entry_type* m_entries;
41
const
entry_type* m_entries_end;
42
43
public
:
44
constexpr
linear_key_finder(
const
entry_type* entries,
const
entry_type* entries_end)
noexcept
;
45
46
constexpr
std::string_view operator()(
const
value_type& v)
const
;
47
};
48
53
template
<
typename
ValueT>
54
class
hash_key_finder
55
{
56
using
value_type = ValueT;
57
using
size_type =
typename
std::string_view::size_type;
58
using
entry_type =
detail::map_entry<ValueT>
;
59
using
keystore_type = std::unordered_map<
60
mdds::detail::cref_wrapper<value_type>
, size_type,
typename
mdds::detail::cref_wrapper<value_type>::hash
>;
61
62
const
entry_type* m_entries;
63
keystore_type m_keys;
64
65
public
:
66
hash_key_finder(
const
entry_type* entries,
const
entry_type* entries_end);
67
68
std::string_view operator()(
const
value_type& v)
const
;
69
};
70
71
}
// namespace ssmap
72
89
template
<
typename
ValueT,
template
<
typename
>
class
KeyFinderT =
ssmap::linear_key_finder
>
90
class
sorted_string_map
91
{
92
using
func_find_key_type = KeyFinderT<ValueT>;
93
94
public
:
95
using
value_type = ValueT;
96
using
size_type =
typename
std::string_view::size_type;
97
102
using
entry_type
=
ssmap::detail::map_entry<ValueT>
;
103
111
constexpr
sorted_string_map
(std::span<const entry_type> entries, value_type null_value);
112
121
[[deprecated(
"use the constructor taking std::span<const entry_type> instead"
)]]
constexpr
sorted_string_map
(
122
const
entry_type
* entries, size_type entry_size, value_type null_value);
123
134
[[deprecated(
"use the overload taking std::string_view instead"
)]]
constexpr
const
value_type&
find
(
135
const
char
* input, size_type len)
const
;
136
145
constexpr
const
value_type&
find
(std::string_view input)
const
;
146
159
constexpr
std::string_view
find_key
(
const
value_type& v)
const
;
160
168
constexpr
size_type
size
()
const
;
169
170
private
:
171
const
entry_type
* m_entries;
172
const
value_type m_null_value;
173
const
size_type m_entry_size;
174
const
entry_type
* m_entries_end;
175
176
func_find_key_type m_func_find_key;
177
};
178
179
}
// namespace mdds
180
181
#include "sorted_string_map_def.inl"
182
183
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
mdds::detail::cref_wrapper
Definition
cref_wrapper.hpp:20
mdds::sorted_string_map::find_key
constexpr std::string_view find_key(const value_type &v) const
mdds::sorted_string_map::find
constexpr const value_type & find(std::string_view input) const
mdds::sorted_string_map::find
constexpr const value_type & find(const char *input, size_type len) const
mdds::sorted_string_map::entry_type
ssmap::detail::map_entry< ValueT > entry_type
Definition
sorted_string_map.hpp:102
mdds::sorted_string_map::size
constexpr size_type size() const
mdds::sorted_string_map::sorted_string_map
constexpr sorted_string_map(const entry_type *entries, size_type entry_size, value_type null_value)
mdds::sorted_string_map::sorted_string_map
constexpr sorted_string_map(std::span< const entry_type > entries, value_type null_value)
mdds::ssmap::linear_key_finder
Definition
sorted_string_map.hpp:35
mdds::detail::cref_wrapper::hash
Definition
cref_wrapper.hpp:43
mdds::ssmap::detail::map_entry
Definition
sorted_string_map.hpp:22
Generated on
for mdds by
1.17.0