kblib 0.2.3
General utilities library for modern C++
intrusive_containers.h
Go to the documentation of this file.
1/* *****************************************************************************
2 * kblib is a general utility library for C++14 and C++17, intended to provide
3 * performant high-level abstractions and more expressive ways to do simple
4 * things.
5 *
6 * Copyright (c) 2021 killerbee
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 * ****************************************************************************/
21
32#ifndef INTRUSIVE_CONTAINERS_H
33#define INTRUSIVE_CONTAINERS_H
34
35#include "hash.h"
36#include "traits.h"
37#include <deque>
38#include <unordered_map>
39
40namespace KBLIB_NS {
41
42#if KBLIB_USE_CXX17
43
44template <typename Value, auto KeyExtract, typename Hash = kblib::FNV_hash<>,
45 typename KeyEqual = std::equal_to<>>
47 public:
48 using value_type = Value;
50 = remove_cvref_t<std::invoke_result_t<decltype(KeyExtract), Value&>>;
51 using mapped_type = Value;
52
53 using size_type = std::size_t;
54 using difference_type = std::ptrdiff_t;
55 using hasher = Hash;
56 using key_equal = KeyEqual;
57 using allocator_type = void;
58
61
63 using const_pointer = const value_type*;
64
65 using iterator = void;
66 using const_iterator = void;
67 using local_iterator = void;
69
70 // etc
71
72 template <int>
73 auto get() -> auto;
74
75 private:
76 std::deque<Value> storage;
77 double load_factor;
78};
79
80template <
81 typename Value, auto KeyExtract1, auto KeyExtract2,
82 typename Hash1 = kblib::FNV_hash<>, typename Hash2 = kblib::FNV_hash<>,
83 typename KeyEqual1 = std::equal_to<>, typename KeyEqual2 = std::equal_to<>>
85 public:
86 using value_type = Value;
88 = remove_cvref_t<std::invoke_result_t<decltype(KeyExtract1), Value&>>;
90 = remove_cvref_t<std::invoke_result_t<decltype(KeyExtract2), Value&>>;
91 using mapped_type = Value;
92 // etc
93
94 template <int>
95 auto get() -> auto;
96
97 private:
98 std::deque<Value> storage;
99 std::unordered_map<key_type_a, Value*, Hash1, KeyEqual1> map_a;
100 std::unordered_map<key_type_b, Value*, Hash2, KeyEqual2> map_b;
101};
102
103#endif
104
105} // namespace KBLIB_NS
106
107#endif // INTRUSIVE_CONTAINERS_H
remove_cvref_t< std::invoke_result_t< decltype(KeyExtract2), Value & > > key_type_b
remove_cvref_t< std::invoke_result_t< decltype(KeyExtract1), Value & > > key_type_a
const value_type & const_reference
remove_cvref_t< std::invoke_result_t< decltype(KeyExtract), Value & > > key_type
const value_type * const_pointer
Provides generic facilities for hashing data, and aliases for standard unordered containers using the...
typename invoke_result< F, ArgTypes... >::type invoke_result_t
Definition: fakestd.h:179
typename std::remove_reference< typename std::remove_cv< T >::type >::type remove_cvref_t
Definition: fakestd.h:68
The primary template has to exist, but not be constructible, in order to be compatible with std::hash...
Definition: hash.h:334
#define KBLIB_NS
Definition: tdecl.h:113
Contains some type traits not in the standard library that are useful in the implementation of kblib.