isotree 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (151) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +8 -1
  3. data/LICENSE.txt +2 -2
  4. data/README.md +32 -14
  5. data/ext/isotree/ext.cpp +144 -31
  6. data/ext/isotree/extconf.rb +7 -7
  7. data/lib/isotree/isolation_forest.rb +110 -30
  8. data/lib/isotree/version.rb +1 -1
  9. data/vendor/isotree/LICENSE +1 -1
  10. data/vendor/isotree/README.md +165 -27
  11. data/vendor/isotree/include/isotree.hpp +2111 -0
  12. data/vendor/isotree/include/isotree_oop.hpp +394 -0
  13. data/vendor/isotree/inst/COPYRIGHTS +62 -0
  14. data/vendor/isotree/src/RcppExports.cpp +525 -52
  15. data/vendor/isotree/src/Rwrapper.cpp +1931 -268
  16. data/vendor/isotree/src/c_interface.cpp +953 -0
  17. data/vendor/isotree/src/crit.hpp +4232 -0
  18. data/vendor/isotree/src/dist.hpp +1886 -0
  19. data/vendor/isotree/src/exp_depth_table.hpp +134 -0
  20. data/vendor/isotree/src/extended.hpp +1444 -0
  21. data/vendor/isotree/src/external_facing_generic.hpp +399 -0
  22. data/vendor/isotree/src/fit_model.hpp +2401 -0
  23. data/vendor/isotree/src/{dealloc.cpp → headers_joined.hpp} +38 -22
  24. data/vendor/isotree/src/helpers_iforest.hpp +813 -0
  25. data/vendor/isotree/src/{impute.cpp → impute.hpp} +353 -122
  26. data/vendor/isotree/src/indexer.cpp +515 -0
  27. data/vendor/isotree/src/instantiate_template_headers.cpp +118 -0
  28. data/vendor/isotree/src/instantiate_template_headers.hpp +240 -0
  29. data/vendor/isotree/src/isoforest.hpp +1659 -0
  30. data/vendor/isotree/src/isotree.hpp +1804 -392
  31. data/vendor/isotree/src/isotree_exportable.hpp +99 -0
  32. data/vendor/isotree/src/merge_models.cpp +159 -16
  33. data/vendor/isotree/src/mult.hpp +1321 -0
  34. data/vendor/isotree/src/oop_interface.cpp +842 -0
  35. data/vendor/isotree/src/oop_interface.hpp +278 -0
  36. data/vendor/isotree/src/other_helpers.hpp +219 -0
  37. data/vendor/isotree/src/predict.hpp +1932 -0
  38. data/vendor/isotree/src/python_helpers.hpp +134 -0
  39. data/vendor/isotree/src/ref_indexer.hpp +154 -0
  40. data/vendor/isotree/src/robinmap/LICENSE +21 -0
  41. data/vendor/isotree/src/robinmap/README.md +483 -0
  42. data/vendor/isotree/src/robinmap/include/tsl/robin_growth_policy.h +406 -0
  43. data/vendor/isotree/src/robinmap/include/tsl/robin_hash.h +1620 -0
  44. data/vendor/isotree/src/robinmap/include/tsl/robin_map.h +807 -0
  45. data/vendor/isotree/src/robinmap/include/tsl/robin_set.h +660 -0
  46. data/vendor/isotree/src/serialize.cpp +4300 -139
  47. data/vendor/isotree/src/sql.cpp +141 -59
  48. data/vendor/isotree/src/subset_models.cpp +174 -0
  49. data/vendor/isotree/src/utils.hpp +3808 -0
  50. data/vendor/isotree/src/xoshiro.hpp +467 -0
  51. data/vendor/isotree/src/ziggurat.hpp +405 -0
  52. metadata +38 -104
  53. data/vendor/cereal/LICENSE +0 -24
  54. data/vendor/cereal/README.md +0 -85
  55. data/vendor/cereal/include/cereal/access.hpp +0 -351
  56. data/vendor/cereal/include/cereal/archives/adapters.hpp +0 -163
  57. data/vendor/cereal/include/cereal/archives/binary.hpp +0 -169
  58. data/vendor/cereal/include/cereal/archives/json.hpp +0 -1019
  59. data/vendor/cereal/include/cereal/archives/portable_binary.hpp +0 -334
  60. data/vendor/cereal/include/cereal/archives/xml.hpp +0 -956
  61. data/vendor/cereal/include/cereal/cereal.hpp +0 -1089
  62. data/vendor/cereal/include/cereal/details/helpers.hpp +0 -422
  63. data/vendor/cereal/include/cereal/details/polymorphic_impl.hpp +0 -796
  64. data/vendor/cereal/include/cereal/details/polymorphic_impl_fwd.hpp +0 -65
  65. data/vendor/cereal/include/cereal/details/static_object.hpp +0 -127
  66. data/vendor/cereal/include/cereal/details/traits.hpp +0 -1411
  67. data/vendor/cereal/include/cereal/details/util.hpp +0 -84
  68. data/vendor/cereal/include/cereal/external/base64.hpp +0 -134
  69. data/vendor/cereal/include/cereal/external/rapidjson/allocators.h +0 -284
  70. data/vendor/cereal/include/cereal/external/rapidjson/cursorstreamwrapper.h +0 -78
  71. data/vendor/cereal/include/cereal/external/rapidjson/document.h +0 -2652
  72. data/vendor/cereal/include/cereal/external/rapidjson/encodedstream.h +0 -299
  73. data/vendor/cereal/include/cereal/external/rapidjson/encodings.h +0 -716
  74. data/vendor/cereal/include/cereal/external/rapidjson/error/en.h +0 -74
  75. data/vendor/cereal/include/cereal/external/rapidjson/error/error.h +0 -161
  76. data/vendor/cereal/include/cereal/external/rapidjson/filereadstream.h +0 -99
  77. data/vendor/cereal/include/cereal/external/rapidjson/filewritestream.h +0 -104
  78. data/vendor/cereal/include/cereal/external/rapidjson/fwd.h +0 -151
  79. data/vendor/cereal/include/cereal/external/rapidjson/internal/biginteger.h +0 -290
  80. data/vendor/cereal/include/cereal/external/rapidjson/internal/diyfp.h +0 -271
  81. data/vendor/cereal/include/cereal/external/rapidjson/internal/dtoa.h +0 -245
  82. data/vendor/cereal/include/cereal/external/rapidjson/internal/ieee754.h +0 -78
  83. data/vendor/cereal/include/cereal/external/rapidjson/internal/itoa.h +0 -308
  84. data/vendor/cereal/include/cereal/external/rapidjson/internal/meta.h +0 -186
  85. data/vendor/cereal/include/cereal/external/rapidjson/internal/pow10.h +0 -55
  86. data/vendor/cereal/include/cereal/external/rapidjson/internal/regex.h +0 -740
  87. data/vendor/cereal/include/cereal/external/rapidjson/internal/stack.h +0 -232
  88. data/vendor/cereal/include/cereal/external/rapidjson/internal/strfunc.h +0 -69
  89. data/vendor/cereal/include/cereal/external/rapidjson/internal/strtod.h +0 -290
  90. data/vendor/cereal/include/cereal/external/rapidjson/internal/swap.h +0 -46
  91. data/vendor/cereal/include/cereal/external/rapidjson/istreamwrapper.h +0 -128
  92. data/vendor/cereal/include/cereal/external/rapidjson/memorybuffer.h +0 -70
  93. data/vendor/cereal/include/cereal/external/rapidjson/memorystream.h +0 -71
  94. data/vendor/cereal/include/cereal/external/rapidjson/msinttypes/inttypes.h +0 -316
  95. data/vendor/cereal/include/cereal/external/rapidjson/msinttypes/stdint.h +0 -300
  96. data/vendor/cereal/include/cereal/external/rapidjson/ostreamwrapper.h +0 -81
  97. data/vendor/cereal/include/cereal/external/rapidjson/pointer.h +0 -1414
  98. data/vendor/cereal/include/cereal/external/rapidjson/prettywriter.h +0 -277
  99. data/vendor/cereal/include/cereal/external/rapidjson/rapidjson.h +0 -656
  100. data/vendor/cereal/include/cereal/external/rapidjson/reader.h +0 -2230
  101. data/vendor/cereal/include/cereal/external/rapidjson/schema.h +0 -2497
  102. data/vendor/cereal/include/cereal/external/rapidjson/stream.h +0 -223
  103. data/vendor/cereal/include/cereal/external/rapidjson/stringbuffer.h +0 -121
  104. data/vendor/cereal/include/cereal/external/rapidjson/writer.h +0 -709
  105. data/vendor/cereal/include/cereal/external/rapidxml/license.txt +0 -52
  106. data/vendor/cereal/include/cereal/external/rapidxml/manual.html +0 -406
  107. data/vendor/cereal/include/cereal/external/rapidxml/rapidxml.hpp +0 -2624
  108. data/vendor/cereal/include/cereal/external/rapidxml/rapidxml_iterators.hpp +0 -175
  109. data/vendor/cereal/include/cereal/external/rapidxml/rapidxml_print.hpp +0 -428
  110. data/vendor/cereal/include/cereal/external/rapidxml/rapidxml_utils.hpp +0 -123
  111. data/vendor/cereal/include/cereal/macros.hpp +0 -154
  112. data/vendor/cereal/include/cereal/specialize.hpp +0 -139
  113. data/vendor/cereal/include/cereal/types/array.hpp +0 -79
  114. data/vendor/cereal/include/cereal/types/atomic.hpp +0 -55
  115. data/vendor/cereal/include/cereal/types/base_class.hpp +0 -203
  116. data/vendor/cereal/include/cereal/types/bitset.hpp +0 -176
  117. data/vendor/cereal/include/cereal/types/boost_variant.hpp +0 -164
  118. data/vendor/cereal/include/cereal/types/chrono.hpp +0 -72
  119. data/vendor/cereal/include/cereal/types/common.hpp +0 -129
  120. data/vendor/cereal/include/cereal/types/complex.hpp +0 -56
  121. data/vendor/cereal/include/cereal/types/concepts/pair_associative_container.hpp +0 -73
  122. data/vendor/cereal/include/cereal/types/deque.hpp +0 -62
  123. data/vendor/cereal/include/cereal/types/forward_list.hpp +0 -68
  124. data/vendor/cereal/include/cereal/types/functional.hpp +0 -43
  125. data/vendor/cereal/include/cereal/types/list.hpp +0 -62
  126. data/vendor/cereal/include/cereal/types/map.hpp +0 -36
  127. data/vendor/cereal/include/cereal/types/memory.hpp +0 -425
  128. data/vendor/cereal/include/cereal/types/optional.hpp +0 -66
  129. data/vendor/cereal/include/cereal/types/polymorphic.hpp +0 -483
  130. data/vendor/cereal/include/cereal/types/queue.hpp +0 -132
  131. data/vendor/cereal/include/cereal/types/set.hpp +0 -103
  132. data/vendor/cereal/include/cereal/types/stack.hpp +0 -76
  133. data/vendor/cereal/include/cereal/types/string.hpp +0 -61
  134. data/vendor/cereal/include/cereal/types/tuple.hpp +0 -123
  135. data/vendor/cereal/include/cereal/types/unordered_map.hpp +0 -36
  136. data/vendor/cereal/include/cereal/types/unordered_set.hpp +0 -99
  137. data/vendor/cereal/include/cereal/types/utility.hpp +0 -47
  138. data/vendor/cereal/include/cereal/types/valarray.hpp +0 -89
  139. data/vendor/cereal/include/cereal/types/variant.hpp +0 -109
  140. data/vendor/cereal/include/cereal/types/vector.hpp +0 -112
  141. data/vendor/cereal/include/cereal/version.hpp +0 -52
  142. data/vendor/isotree/src/Makevars +0 -4
  143. data/vendor/isotree/src/crit.cpp +0 -912
  144. data/vendor/isotree/src/dist.cpp +0 -749
  145. data/vendor/isotree/src/extended.cpp +0 -790
  146. data/vendor/isotree/src/fit_model.cpp +0 -1090
  147. data/vendor/isotree/src/helpers_iforest.cpp +0 -324
  148. data/vendor/isotree/src/isoforest.cpp +0 -771
  149. data/vendor/isotree/src/mult.cpp +0 -607
  150. data/vendor/isotree/src/predict.cpp +0 -853
  151. data/vendor/isotree/src/utils.cpp +0 -1566
@@ -0,0 +1,660 @@
1
+ /**
2
+ * MIT License
3
+ *
4
+ * Copyright (c) 2017 Thibaut Goetghebuer-Planchon <tessil@gmx.com>
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in
14
+ * all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+ #ifndef TSL_ROBIN_SET_H
25
+ #define TSL_ROBIN_SET_H
26
+
27
+ #include <cstddef>
28
+ #include <functional>
29
+ #include <initializer_list>
30
+ #include <memory>
31
+ #include <type_traits>
32
+ #include <utility>
33
+
34
+ #include "robin_hash.h"
35
+
36
+ namespace tsl {
37
+
38
+ /**
39
+ * Implementation of a hash set using open-addressing and the robin hood hashing
40
+ * algorithm with backward shift deletion.
41
+ *
42
+ * For operations modifying the hash set (insert, erase, rehash, ...), the
43
+ * strong exception guarantee is only guaranteed when the expression
44
+ * `std::is_nothrow_swappable<Key>::value &&
45
+ * std::is_nothrow_move_constructible<Key>::value` is true, otherwise if an
46
+ * exception is thrown during the swap or the move, the hash set may end up in a
47
+ * undefined state. Per the standard a `Key` with a noexcept copy constructor
48
+ * and no move constructor also satisfies the
49
+ * `std::is_nothrow_move_constructible<Key>::value` criterion (and will thus
50
+ * guarantee the strong exception for the set).
51
+ *
52
+ * When `StoreHash` is true, 32 bits of the hash are stored alongside the
53
+ * values. It can improve the performance during lookups if the `KeyEqual`
54
+ * function takes time (or engenders a cache-miss for example) as we then
55
+ * compare the stored hashes before comparing the keys. When
56
+ * `tsl::rh::power_of_two_growth_policy` is used as `GrowthPolicy`, it may also
57
+ * speed-up the rehash process as we can avoid to recalculate the hash. When it
58
+ * is detected that storing the hash will not incur any memory penalty due to
59
+ * alignment (i.e. `sizeof(tsl::detail_robin_hash::bucket_entry<ValueType,
60
+ * true>) == sizeof(tsl::detail_robin_hash::bucket_entry<ValueType, false>)`)
61
+ * and `tsl::rh::power_of_two_growth_policy` is used, the hash will be stored
62
+ * even if `StoreHash` is false so that we can speed-up the rehash (but it will
63
+ * not be used on lookups unless `StoreHash` is true).
64
+ *
65
+ * `GrowthPolicy` defines how the set grows and consequently how a hash value is
66
+ * mapped to a bucket. By default the set uses
67
+ * `tsl::rh::power_of_two_growth_policy`. This policy keeps the number of
68
+ * buckets to a power of two and uses a mask to set the hash to a bucket instead
69
+ * of the slow modulo. Other growth policies are available and you may define
70
+ * your own growth policy, check `tsl::rh::power_of_two_growth_policy` for the
71
+ * interface.
72
+ *
73
+ * `Key` must be swappable.
74
+ *
75
+ * `Key` must be copy and/or move constructible.
76
+ *
77
+ * If the destructor of `Key` throws an exception, the behaviour of the class is
78
+ * undefined.
79
+ *
80
+ * Iterators invalidation:
81
+ * - clear, operator=, reserve, rehash: always invalidate the iterators.
82
+ * - insert, emplace, emplace_hint, operator[]: if there is an effective
83
+ * insert, invalidate the iterators.
84
+ * - erase: always invalidate the iterators.
85
+ */
86
+ template <class Key, class Hash = std::hash<Key>,
87
+ class KeyEqual = std::equal_to<Key>,
88
+ class Allocator = std::allocator<Key>, bool StoreHash = false,
89
+ class GrowthPolicy = tsl::rh::power_of_two_growth_policy<2>>
90
+ class robin_set {
91
+ private:
92
+ template <typename U>
93
+ using has_is_transparent = tsl::detail_robin_hash::has_is_transparent<U>;
94
+
95
+ class KeySelect {
96
+ public:
97
+ using key_type = Key;
98
+
99
+ const key_type& operator()(const Key& key) const noexcept { return key; }
100
+
101
+ key_type& operator()(Key& key) noexcept { return key; }
102
+ };
103
+
104
+ using ht = detail_robin_hash::robin_hash<Key, KeySelect, void, Hash, KeyEqual,
105
+ Allocator, StoreHash, GrowthPolicy>;
106
+
107
+ public:
108
+ using key_type = typename ht::key_type;
109
+ using value_type = typename ht::value_type;
110
+ using size_type = typename ht::size_type;
111
+ using difference_type = typename ht::difference_type;
112
+ using hasher = typename ht::hasher;
113
+ using key_equal = typename ht::key_equal;
114
+ using allocator_type = typename ht::allocator_type;
115
+ using reference = typename ht::reference;
116
+ using const_reference = typename ht::const_reference;
117
+ using pointer = typename ht::pointer;
118
+ using const_pointer = typename ht::const_pointer;
119
+ using iterator = typename ht::iterator;
120
+ using const_iterator = typename ht::const_iterator;
121
+
122
+ /*
123
+ * Constructors
124
+ */
125
+ robin_set() : robin_set(ht::DEFAULT_INIT_BUCKETS_SIZE) {}
126
+
127
+ explicit robin_set(size_type bucket_count, const Hash& hash = Hash(),
128
+ const KeyEqual& equal = KeyEqual(),
129
+ const Allocator& alloc = Allocator())
130
+ : m_ht(bucket_count, hash, equal, alloc) {}
131
+
132
+ robin_set(size_type bucket_count, const Allocator& alloc)
133
+ : robin_set(bucket_count, Hash(), KeyEqual(), alloc) {}
134
+
135
+ robin_set(size_type bucket_count, const Hash& hash, const Allocator& alloc)
136
+ : robin_set(bucket_count, hash, KeyEqual(), alloc) {}
137
+
138
+ explicit robin_set(const Allocator& alloc)
139
+ : robin_set(ht::DEFAULT_INIT_BUCKETS_SIZE, alloc) {}
140
+
141
+ template <class InputIt>
142
+ robin_set(InputIt first, InputIt last,
143
+ size_type bucket_count = ht::DEFAULT_INIT_BUCKETS_SIZE,
144
+ const Hash& hash = Hash(), const KeyEqual& equal = KeyEqual(),
145
+ const Allocator& alloc = Allocator())
146
+ : robin_set(bucket_count, hash, equal, alloc) {
147
+ insert(first, last);
148
+ }
149
+
150
+ template <class InputIt>
151
+ robin_set(InputIt first, InputIt last, size_type bucket_count,
152
+ const Allocator& alloc)
153
+ : robin_set(first, last, bucket_count, Hash(), KeyEqual(), alloc) {}
154
+
155
+ template <class InputIt>
156
+ robin_set(InputIt first, InputIt last, size_type bucket_count,
157
+ const Hash& hash, const Allocator& alloc)
158
+ : robin_set(first, last, bucket_count, hash, KeyEqual(), alloc) {}
159
+
160
+ robin_set(std::initializer_list<value_type> init,
161
+ size_type bucket_count = ht::DEFAULT_INIT_BUCKETS_SIZE,
162
+ const Hash& hash = Hash(), const KeyEqual& equal = KeyEqual(),
163
+ const Allocator& alloc = Allocator())
164
+ : robin_set(init.begin(), init.end(), bucket_count, hash, equal, alloc) {}
165
+
166
+ robin_set(std::initializer_list<value_type> init, size_type bucket_count,
167
+ const Allocator& alloc)
168
+ : robin_set(init.begin(), init.end(), bucket_count, Hash(), KeyEqual(),
169
+ alloc) {}
170
+
171
+ robin_set(std::initializer_list<value_type> init, size_type bucket_count,
172
+ const Hash& hash, const Allocator& alloc)
173
+ : robin_set(init.begin(), init.end(), bucket_count, hash, KeyEqual(),
174
+ alloc) {}
175
+
176
+ robin_set& operator=(std::initializer_list<value_type> ilist) {
177
+ m_ht.clear();
178
+
179
+ m_ht.reserve(ilist.size());
180
+ m_ht.insert(ilist.begin(), ilist.end());
181
+
182
+ return *this;
183
+ }
184
+
185
+ allocator_type get_allocator() const { return m_ht.get_allocator(); }
186
+
187
+ /*
188
+ * Iterators
189
+ */
190
+ iterator begin() noexcept { return m_ht.begin(); }
191
+ const_iterator begin() const noexcept { return m_ht.begin(); }
192
+ const_iterator cbegin() const noexcept { return m_ht.cbegin(); }
193
+
194
+ iterator end() noexcept { return m_ht.end(); }
195
+ const_iterator end() const noexcept { return m_ht.end(); }
196
+ const_iterator cend() const noexcept { return m_ht.cend(); }
197
+
198
+ /*
199
+ * Capacity
200
+ */
201
+ bool empty() const noexcept { return m_ht.empty(); }
202
+ size_type size() const noexcept { return m_ht.size(); }
203
+ size_type max_size() const noexcept { return m_ht.max_size(); }
204
+
205
+ /*
206
+ * Modifiers
207
+ */
208
+ void clear() noexcept { m_ht.clear(); }
209
+
210
+ std::pair<iterator, bool> insert(const value_type& value) {
211
+ return m_ht.insert(value);
212
+ }
213
+
214
+ std::pair<iterator, bool> insert(value_type&& value) {
215
+ return m_ht.insert(std::move(value));
216
+ }
217
+
218
+ iterator insert(const_iterator hint, const value_type& value) {
219
+ return m_ht.insert_hint(hint, value);
220
+ }
221
+
222
+ iterator insert(const_iterator hint, value_type&& value) {
223
+ return m_ht.insert_hint(hint, std::move(value));
224
+ }
225
+
226
+ template <class InputIt>
227
+ void insert(InputIt first, InputIt last) {
228
+ m_ht.insert(first, last);
229
+ }
230
+
231
+ void insert(std::initializer_list<value_type> ilist) {
232
+ m_ht.insert(ilist.begin(), ilist.end());
233
+ }
234
+
235
+ /**
236
+ * Due to the way elements are stored, emplace will need to move or copy the
237
+ * key-value once. The method is equivalent to
238
+ * insert(value_type(std::forward<Args>(args)...));
239
+ *
240
+ * Mainly here for compatibility with the std::unordered_map interface.
241
+ */
242
+ template <class... Args>
243
+ std::pair<iterator, bool> emplace(Args&&... args) {
244
+ return m_ht.emplace(std::forward<Args>(args)...);
245
+ }
246
+
247
+ /**
248
+ * Due to the way elements are stored, emplace_hint will need to move or copy
249
+ * the key-value once. The method is equivalent to insert(hint,
250
+ * value_type(std::forward<Args>(args)...));
251
+ *
252
+ * Mainly here for compatibility with the std::unordered_map interface.
253
+ */
254
+ template <class... Args>
255
+ iterator emplace_hint(const_iterator hint, Args&&... args) {
256
+ return m_ht.emplace_hint(hint, std::forward<Args>(args)...);
257
+ }
258
+
259
+ iterator erase(iterator pos) { return m_ht.erase(pos); }
260
+ iterator erase(const_iterator pos) { return m_ht.erase(pos); }
261
+ iterator erase(const_iterator first, const_iterator last) {
262
+ return m_ht.erase(first, last);
263
+ }
264
+ size_type erase(const key_type& key) { return m_ht.erase(key); }
265
+
266
+ /**
267
+ * Use the hash value 'precalculated_hash' instead of hashing the key. The
268
+ * hash value should be the same as hash_function()(key). Useful to speed-up
269
+ * the lookup to the value if you already have the hash.
270
+ */
271
+ size_type erase(const key_type& key, std::size_t precalculated_hash) {
272
+ return m_ht.erase(key, precalculated_hash);
273
+ }
274
+
275
+ /**
276
+ * This overload only participates in the overload resolution if the typedef
277
+ * KeyEqual::is_transparent exists. If so, K must be hashable and comparable
278
+ * to Key.
279
+ */
280
+ template <
281
+ class K, class KE = KeyEqual,
282
+ typename std::enable_if<has_is_transparent<KE>::value>::type* = nullptr>
283
+ size_type erase(const K& key) {
284
+ return m_ht.erase(key);
285
+ }
286
+
287
+ /**
288
+ * @copydoc erase(const K& key)
289
+ *
290
+ * Use the hash value 'precalculated_hash' instead of hashing the key. The
291
+ * hash value should be the same as hash_function()(key). Useful to speed-up
292
+ * the lookup to the value if you already have the hash.
293
+ */
294
+ template <
295
+ class K, class KE = KeyEqual,
296
+ typename std::enable_if<has_is_transparent<KE>::value>::type* = nullptr>
297
+ size_type erase(const K& key, std::size_t precalculated_hash) {
298
+ return m_ht.erase(key, precalculated_hash);
299
+ }
300
+
301
+ void swap(robin_set& other) { other.m_ht.swap(m_ht); }
302
+
303
+ /*
304
+ * Lookup
305
+ */
306
+ size_type count(const Key& key) const { return m_ht.count(key); }
307
+
308
+ /**
309
+ * Use the hash value 'precalculated_hash' instead of hashing the key. The
310
+ * hash value should be the same as hash_function()(key). Useful to speed-up
311
+ * the lookup if you already have the hash.
312
+ */
313
+ size_type count(const Key& key, std::size_t precalculated_hash) const {
314
+ return m_ht.count(key, precalculated_hash);
315
+ }
316
+
317
+ /**
318
+ * This overload only participates in the overload resolution if the typedef
319
+ * KeyEqual::is_transparent exists. If so, K must be hashable and comparable
320
+ * to Key.
321
+ */
322
+ template <
323
+ class K, class KE = KeyEqual,
324
+ typename std::enable_if<has_is_transparent<KE>::value>::type* = nullptr>
325
+ size_type count(const K& key) const {
326
+ return m_ht.count(key);
327
+ }
328
+
329
+ /**
330
+ * @copydoc count(const K& key) const
331
+ *
332
+ * Use the hash value 'precalculated_hash' instead of hashing the key. The
333
+ * hash value should be the same as hash_function()(key). Useful to speed-up
334
+ * the lookup if you already have the hash.
335
+ */
336
+ template <
337
+ class K, class KE = KeyEqual,
338
+ typename std::enable_if<has_is_transparent<KE>::value>::type* = nullptr>
339
+ size_type count(const K& key, std::size_t precalculated_hash) const {
340
+ return m_ht.count(key, precalculated_hash);
341
+ }
342
+
343
+ iterator find(const Key& key) { return m_ht.find(key); }
344
+
345
+ /**
346
+ * Use the hash value 'precalculated_hash' instead of hashing the key. The
347
+ * hash value should be the same as hash_function()(key). Useful to speed-up
348
+ * the lookup if you already have the hash.
349
+ */
350
+ iterator find(const Key& key, std::size_t precalculated_hash) {
351
+ return m_ht.find(key, precalculated_hash);
352
+ }
353
+
354
+ const_iterator find(const Key& key) const { return m_ht.find(key); }
355
+
356
+ /**
357
+ * @copydoc find(const Key& key, std::size_t precalculated_hash)
358
+ */
359
+ const_iterator find(const Key& key, std::size_t precalculated_hash) const {
360
+ return m_ht.find(key, precalculated_hash);
361
+ }
362
+
363
+ /**
364
+ * This overload only participates in the overload resolution if the typedef
365
+ * KeyEqual::is_transparent exists. If so, K must be hashable and comparable
366
+ * to Key.
367
+ */
368
+ template <
369
+ class K, class KE = KeyEqual,
370
+ typename std::enable_if<has_is_transparent<KE>::value>::type* = nullptr>
371
+ iterator find(const K& key) {
372
+ return m_ht.find(key);
373
+ }
374
+
375
+ /**
376
+ * @copydoc find(const K& key)
377
+ *
378
+ * Use the hash value 'precalculated_hash' instead of hashing the key. The
379
+ * hash value should be the same as hash_function()(key). Useful to speed-up
380
+ * the lookup if you already have the hash.
381
+ */
382
+ template <
383
+ class K, class KE = KeyEqual,
384
+ typename std::enable_if<has_is_transparent<KE>::value>::type* = nullptr>
385
+ iterator find(const K& key, std::size_t precalculated_hash) {
386
+ return m_ht.find(key, precalculated_hash);
387
+ }
388
+
389
+ /**
390
+ * @copydoc find(const K& key)
391
+ */
392
+ template <
393
+ class K, class KE = KeyEqual,
394
+ typename std::enable_if<has_is_transparent<KE>::value>::type* = nullptr>
395
+ const_iterator find(const K& key) const {
396
+ return m_ht.find(key);
397
+ }
398
+
399
+ /**
400
+ * @copydoc find(const K& key)
401
+ *
402
+ * Use the hash value 'precalculated_hash' instead of hashing the key. The
403
+ * hash value should be the same as hash_function()(key). Useful to speed-up
404
+ * the lookup if you already have the hash.
405
+ */
406
+ template <
407
+ class K, class KE = KeyEqual,
408
+ typename std::enable_if<has_is_transparent<KE>::value>::type* = nullptr>
409
+ const_iterator find(const K& key, std::size_t precalculated_hash) const {
410
+ return m_ht.find(key, precalculated_hash);
411
+ }
412
+
413
+ bool contains(const Key& key) const { return m_ht.contains(key); }
414
+
415
+ /**
416
+ * Use the hash value 'precalculated_hash' instead of hashing the key. The
417
+ * hash value should be the same as hash_function()(key). Useful to speed-up
418
+ * the lookup if you already have the hash.
419
+ */
420
+ bool contains(const Key& key, std::size_t precalculated_hash) const {
421
+ return m_ht.contains(key, precalculated_hash);
422
+ }
423
+
424
+ /**
425
+ * This overload only participates in the overload resolution if the typedef
426
+ * KeyEqual::is_transparent exists. If so, K must be hashable and comparable
427
+ * to Key.
428
+ */
429
+ template <
430
+ class K, class KE = KeyEqual,
431
+ typename std::enable_if<has_is_transparent<KE>::value>::type* = nullptr>
432
+ bool contains(const K& key) const {
433
+ return m_ht.contains(key);
434
+ }
435
+
436
+ /**
437
+ * @copydoc contains(const K& key) const
438
+ *
439
+ * Use the hash value 'precalculated_hash' instead of hashing the key. The
440
+ * hash value should be the same as hash_function()(key). Useful to speed-up
441
+ * the lookup if you already have the hash.
442
+ */
443
+ template <
444
+ class K, class KE = KeyEqual,
445
+ typename std::enable_if<has_is_transparent<KE>::value>::type* = nullptr>
446
+ bool contains(const K& key, std::size_t precalculated_hash) const {
447
+ return m_ht.contains(key, precalculated_hash);
448
+ }
449
+
450
+ std::pair<iterator, iterator> equal_range(const Key& key) {
451
+ return m_ht.equal_range(key);
452
+ }
453
+
454
+ /**
455
+ * Use the hash value 'precalculated_hash' instead of hashing the key. The
456
+ * hash value should be the same as hash_function()(key). Useful to speed-up
457
+ * the lookup if you already have the hash.
458
+ */
459
+ std::pair<iterator, iterator> equal_range(const Key& key,
460
+ std::size_t precalculated_hash) {
461
+ return m_ht.equal_range(key, precalculated_hash);
462
+ }
463
+
464
+ std::pair<const_iterator, const_iterator> equal_range(const Key& key) const {
465
+ return m_ht.equal_range(key);
466
+ }
467
+
468
+ /**
469
+ * @copydoc equal_range(const Key& key, std::size_t precalculated_hash)
470
+ */
471
+ std::pair<const_iterator, const_iterator> equal_range(
472
+ const Key& key, std::size_t precalculated_hash) const {
473
+ return m_ht.equal_range(key, precalculated_hash);
474
+ }
475
+
476
+ /**
477
+ * This overload only participates in the overload resolution if the typedef
478
+ * KeyEqual::is_transparent exists. If so, K must be hashable and comparable
479
+ * to Key.
480
+ */
481
+ template <
482
+ class K, class KE = KeyEqual,
483
+ typename std::enable_if<has_is_transparent<KE>::value>::type* = nullptr>
484
+ std::pair<iterator, iterator> equal_range(const K& key) {
485
+ return m_ht.equal_range(key);
486
+ }
487
+
488
+ /**
489
+ * @copydoc equal_range(const K& key)
490
+ *
491
+ * Use the hash value 'precalculated_hash' instead of hashing the key. The
492
+ * hash value should be the same as hash_function()(key). Useful to speed-up
493
+ * the lookup if you already have the hash.
494
+ */
495
+ template <
496
+ class K, class KE = KeyEqual,
497
+ typename std::enable_if<has_is_transparent<KE>::value>::type* = nullptr>
498
+ std::pair<iterator, iterator> equal_range(const K& key,
499
+ std::size_t precalculated_hash) {
500
+ return m_ht.equal_range(key, precalculated_hash);
501
+ }
502
+
503
+ /**
504
+ * @copydoc equal_range(const K& key)
505
+ */
506
+ template <
507
+ class K, class KE = KeyEqual,
508
+ typename std::enable_if<has_is_transparent<KE>::value>::type* = nullptr>
509
+ std::pair<const_iterator, const_iterator> equal_range(const K& key) const {
510
+ return m_ht.equal_range(key);
511
+ }
512
+
513
+ /**
514
+ * @copydoc equal_range(const K& key, std::size_t precalculated_hash)
515
+ */
516
+ template <
517
+ class K, class KE = KeyEqual,
518
+ typename std::enable_if<has_is_transparent<KE>::value>::type* = nullptr>
519
+ std::pair<const_iterator, const_iterator> equal_range(
520
+ const K& key, std::size_t precalculated_hash) const {
521
+ return m_ht.equal_range(key, precalculated_hash);
522
+ }
523
+
524
+ /*
525
+ * Bucket interface
526
+ */
527
+ size_type bucket_count() const { return m_ht.bucket_count(); }
528
+ size_type max_bucket_count() const { return m_ht.max_bucket_count(); }
529
+
530
+ /*
531
+ * Hash policy
532
+ */
533
+ float load_factor() const { return m_ht.load_factor(); }
534
+
535
+ float min_load_factor() const { return m_ht.min_load_factor(); }
536
+ float max_load_factor() const { return m_ht.max_load_factor(); }
537
+
538
+ /**
539
+ * Set the `min_load_factor` to `ml`. When the `load_factor` of the set goes
540
+ * below `min_load_factor` after some erase operations, the set will be
541
+ * shrunk when an insertion occurs. The erase method itself never shrinks
542
+ * the set.
543
+ *
544
+ * The default value of `min_load_factor` is 0.0f, the set never shrinks by
545
+ * default.
546
+ */
547
+ void min_load_factor(float ml) { m_ht.min_load_factor(ml); }
548
+ void max_load_factor(float ml) { m_ht.max_load_factor(ml); }
549
+
550
+ void rehash(size_type count_) { m_ht.rehash(count_); }
551
+ void reserve(size_type count_) { m_ht.reserve(count_); }
552
+
553
+ /*
554
+ * Observers
555
+ */
556
+ hasher hash_function() const { return m_ht.hash_function(); }
557
+ key_equal key_eq() const { return m_ht.key_eq(); }
558
+
559
+ /*
560
+ * Other
561
+ */
562
+
563
+ /**
564
+ * Convert a const_iterator to an iterator.
565
+ */
566
+ iterator mutable_iterator(const_iterator pos) {
567
+ return m_ht.mutable_iterator(pos);
568
+ }
569
+
570
+ friend bool operator==(const robin_set& lhs, const robin_set& rhs) {
571
+ if (lhs.size() != rhs.size()) {
572
+ return false;
573
+ }
574
+
575
+ for (const auto& element_lhs : lhs) {
576
+ const auto it_element_rhs = rhs.find(element_lhs);
577
+ if (it_element_rhs == rhs.cend()) {
578
+ return false;
579
+ }
580
+ }
581
+
582
+ return true;
583
+ }
584
+
585
+ /**
586
+ * Serialize the set through the `serializer` parameter.
587
+ *
588
+ * The `serializer` parameter must be a function object that supports the
589
+ * following call:
590
+ * - `template<typename U> void operator()(const U& value);` where the types
591
+ * `std::int16_t`, `std::uint32_t`, `std::uint64_t`, `float` and `Key` must be
592
+ * supported for U.
593
+ *
594
+ * The implementation leaves binary compatibility (endianness, IEEE 754 for
595
+ * floats, ...) of the types it serializes in the hands of the `Serializer`
596
+ * function object if compatibility is required.
597
+ */
598
+ template <class Serializer>
599
+ void serialize(Serializer& serializer) const {
600
+ m_ht.serialize(serializer);
601
+ }
602
+
603
+ /**
604
+ * Deserialize a previously serialized set through the `deserializer`
605
+ * parameter.
606
+ *
607
+ * The `deserializer` parameter must be a function object that supports the
608
+ * following call:
609
+ * - `template<typename U> U operator()();` where the types `std::int16_t`,
610
+ * `std::uint32_t`, `std::uint64_t`, `float` and `Key` must be supported for
611
+ * U.
612
+ *
613
+ * If the deserialized hash set type is hash compatible with the serialized
614
+ * set, the deserialization process can be sped up by setting
615
+ * `hash_compatible` to true. To be hash compatible, the Hash, KeyEqual and
616
+ * GrowthPolicy must behave the same way than the ones used on the serialized
617
+ * set and the StoreHash must have the same value. The `std::size_t` must also
618
+ * be of the same size as the one on the platform used to serialize the set.
619
+ * If these criteria are not met, the behaviour is undefined with
620
+ * `hash_compatible` sets to true.
621
+ *
622
+ * The behaviour is undefined if the type `Key` of the `robin_set` is not the
623
+ * same as the type used during serialization.
624
+ *
625
+ * The implementation leaves binary compatibility (endianness, IEEE 754 for
626
+ * floats, size of int, ...) of the types it deserializes in the hands of the
627
+ * `Deserializer` function object if compatibility is required.
628
+ */
629
+ template <class Deserializer>
630
+ static robin_set deserialize(Deserializer& deserializer,
631
+ bool hash_compatible = false) {
632
+ robin_set set(0);
633
+ set.m_ht.deserialize(deserializer, hash_compatible);
634
+
635
+ return set;
636
+ }
637
+
638
+ friend bool operator!=(const robin_set& lhs, const robin_set& rhs) {
639
+ return !operator==(lhs, rhs);
640
+ }
641
+
642
+ friend void swap(robin_set& lhs, robin_set& rhs) { lhs.swap(rhs); }
643
+
644
+ private:
645
+ ht m_ht;
646
+ };
647
+
648
+ /**
649
+ * Same as `tsl::robin_set<Key, Hash, KeyEqual, Allocator, StoreHash,
650
+ * tsl::rh::prime_growth_policy>`.
651
+ */
652
+ template <class Key, class Hash = std::hash<Key>,
653
+ class KeyEqual = std::equal_to<Key>,
654
+ class Allocator = std::allocator<Key>, bool StoreHash = false>
655
+ using robin_pg_set = robin_set<Key, Hash, KeyEqual, Allocator, StoreHash,
656
+ tsl::rh::prime_growth_policy>;
657
+
658
+ } // end namespace tsl
659
+
660
+ #endif