mdds
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 <unordered_map>
13
14
namespace
mdds {
15
16
namespace
ssmap {
17
namespace
detail {
18
19
template
<
typename
ValueT>
20
struct
map_entry
21
{
22
std::string_view key;
23
ValueT value;
24
};
25
26
}
// namespace detail
27
32
template
<
typename
ValueT>
33
class
linear_key_finder
34
{
35
using
value_type = ValueT;
36
using
size_type =
typename
std::string_view::size_type;
37
using
entry_type =
detail::map_entry<ValueT>
;
38
39
const
entry_type* m_entries;
40
const
entry_type* m_entries_end;
41
42
public
:
43
linear_key_finder(
const
entry_type* entries,
const
entry_type* entries_end)
noexcept
;
44
45
std::string_view operator()(
const
value_type& v)
const
;
46
};
47
52
template
<
typename
ValueT>
53
class
hash_key_finder
54
{
55
using
value_type = ValueT;
56
using
size_type =
typename
std::string_view::size_type;
57
using
entry_type =
detail::map_entry<ValueT>
;
58
using
keystore_type = std::unordered_map<
59
mdds::detail::cref_wrapper<value_type>
, size_type,
typename
mdds::detail::cref_wrapper<value_type>::hash
>;
60
61
const
entry_type* m_entries;
62
keystore_type m_keys;
63
64
public
:
65
hash_key_finder(
const
entry_type* entries,
const
entry_type* entries_end);
66
67
std::string_view operator()(
const
value_type& v)
const
;
68
};
69
70
}
// namespace ssmap
71
88
template
<
typename
ValueT,
template
<
typename
>
class
KeyFinderT =
ssmap::linear_key_finder
>
89
class
sorted_string_map
90
{
91
using
func_find_key_type = KeyFinderT<ValueT>;
92
93
public
:
94
using
value_type = ValueT;
95
using
size_type =
typename
std::string_view::size_type;
96
101
using
entry_type
=
ssmap::detail::map_entry<ValueT>
;
102
111
sorted_string_map
(
const
entry_type
* entries, size_type entry_size, value_type null_value);
112
123
const
value_type&
find
(
const
char
* input, size_type len)
const
;
124
133
const
value_type&
find
(std::string_view input)
const
;
134
147
std::string_view
find_key
(
const
value_type& v)
const
;
148
156
size_type
size
()
const
;
157
158
private
:
159
const
entry_type
* m_entries;
160
const
value_type m_null_value;
161
const
size_type m_entry_size;
162
const
entry_type
* m_entries_end;
163
164
func_find_key_type m_func_find_key;
165
};
166
167
}
// namespace mdds
168
169
#include "sorted_string_map_def.inl"
170
171
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
mdds::detail::cref_wrapper
Definition
cref_wrapper.hpp:20
mdds::sorted_string_map::find
const value_type & find(std::string_view input) const
mdds::sorted_string_map::find_key
std::string_view find_key(const value_type &v) const
mdds::sorted_string_map::sorted_string_map
sorted_string_map(const entry_type *entries, size_type entry_size, value_type null_value)
mdds::sorted_string_map::size
size_type size() const
mdds::sorted_string_map::entry_type
ssmap::detail::map_entry< ValueT > entry_type
Definition
sorted_string_map.hpp:101
mdds::sorted_string_map::find
const value_type & find(const char *input, size_type len) const
mdds::ssmap::linear_key_finder
Definition
sorted_string_map.hpp:34
mdds::detail::cref_wrapper::hash
Definition
cref_wrapper.hpp:43
mdds::ssmap::detail::map_entry
Definition
sorted_string_map.hpp:21
Generated on
for mdds by
1.15.0