41 #ifndef PB_DS_HASH_POLICY_HPP
42 #define PB_DS_HASH_POLICY_HPP
50 #include <ext/pb_ds/detail/hash_fn/mask_based_range_hashing.hpp>
51 #include <ext/pb_ds/detail/hash_fn/mod_based_range_hashing.hpp>
52 #include <ext/pb_ds/detail/resize_policy/hash_load_check_resize_trigger_size_base.hpp>
66 #define PB_DS_CLASS_T_DEC template<typename Size_Type>
67 #define PB_DS_CLASS_C_DEC linear_probe_fn<Size_Type>
70 template<
typename Size_Type = std::
size_t>
74 typedef Size_Type size_type;
77 swap(PB_DS_CLASS_C_DEC& other);
82 operator()(size_type i)
const;
85 #include <ext/pb_ds/detail/hash_fn/linear_probe_fn_imp.hpp>
87 #undef PB_DS_CLASS_T_DEC
88 #undef PB_DS_CLASS_C_DEC
90 #define PB_DS_CLASS_T_DEC template<typename Size_Type>
91 #define PB_DS_CLASS_C_DEC quadratic_probe_fn<Size_Type>
94 template<
typename Size_Type = std::
size_t>
95 class quadratic_probe_fn
98 typedef Size_Type size_type;
101 swap(PB_DS_CLASS_C_DEC& other);
106 operator()(size_type i)
const;
109 #include <ext/pb_ds/detail/hash_fn/quadratic_probe_fn_imp.hpp>
111 #undef PB_DS_CLASS_T_DEC
112 #undef PB_DS_CLASS_C_DEC
114 #define PB_DS_CLASS_T_DEC template<typename Size_Type>
115 #define PB_DS_CLASS_C_DEC direct_mask_range_hashing<Size_Type>
118 template<
typename Size_Type = std::
size_t>
119 class direct_mask_range_hashing
120 :
public detail::mask_based_range_hashing<Size_Type>
123 typedef detail::mask_based_range_hashing<Size_Type> mask_based_base;
126 typedef Size_Type size_type;
129 swap(PB_DS_CLASS_C_DEC& other);
133 notify_resized(size_type
size);
138 operator()(size_type hash)
const;
141 #include <ext/pb_ds/detail/hash_fn/direct_mask_range_hashing_imp.hpp>
143 #undef PB_DS_CLASS_T_DEC
144 #undef PB_DS_CLASS_C_DEC
146 #define PB_DS_CLASS_T_DEC template<typename Size_Type>
147 #define PB_DS_CLASS_C_DEC direct_mod_range_hashing<Size_Type>
150 template<
typename Size_Type = std::
size_t>
151 class direct_mod_range_hashing
152 :
public detail::mod_based_range_hashing<Size_Type>
155 typedef Size_Type size_type;
158 swap(PB_DS_CLASS_C_DEC& other);
162 notify_resized(size_type
size);
167 operator()(size_type hash)
const;
170 typedef detail::mod_based_range_hashing<size_type> mod_based_base;
173 #include <ext/pb_ds/detail/hash_fn/direct_mod_range_hashing_imp.hpp>
175 #undef PB_DS_CLASS_T_DEC
176 #undef PB_DS_CLASS_C_DEC
178 #define PB_DS_CLASS_T_DEC template<bool External_Load_Access, typename Size_Type>
179 #define PB_DS_CLASS_C_DEC hash_load_check_resize_trigger<External_Load_Access, Size_Type>
180 #define PB_DS_SIZE_BASE_C_DEC detail::hash_load_check_resize_trigger_size_base<Size_Type, External_Load_Access>
184 template<
bool External_Load_Access = false,
typename Size_Type = std::
size_t>
185 class hash_load_check_resize_trigger :
private PB_DS_SIZE_BASE_C_DEC
188 typedef Size_Type size_type;
192 external_load_access = External_Load_Access
198 hash_load_check_resize_trigger(
float load_min = 0.125,
199 float load_max = 0.5);
202 swap(hash_load_check_resize_trigger& other);
205 ~hash_load_check_resize_trigger();
218 notify_insert_search_start();
221 notify_insert_search_collision();
224 notify_insert_search_end();
227 notify_find_search_start();
230 notify_find_search_collision();
233 notify_find_search_end();
236 notify_erase_search_start();
239 notify_erase_search_collision();
242 notify_erase_search_end();
247 notify_inserted(size_type num_entries);
250 notify_erased(size_type num_entries);
259 notify_resized(size_type new_size);
262 notify_externally_resized(size_type new_size);
265 is_resize_needed()
const;
268 is_grow_needed(size_type
size, size_type num_entries)
const;
272 do_resize(size_type new_size);
274 typedef PB_DS_SIZE_BASE_C_DEC size_base;
276 #ifdef _GLIBCXX_DEBUG
278 assert_valid()
const;
283 size_type m_next_shrink_size;
284 size_type m_next_grow_size;
285 bool m_resize_needed;
288 #include <ext/pb_ds/detail/resize_policy/hash_load_check_resize_trigger_imp.hpp>
290 #undef PB_DS_CLASS_T_DEC
291 #undef PB_DS_CLASS_C_DEC
292 #undef PB_DS_SIZE_BASE_C_DEC
294 #define PB_DS_CLASS_T_DEC template<bool External_Load_Access, typename Size_Type>
295 #define PB_DS_CLASS_C_DEC cc_hash_max_collision_check_resize_trigger<External_Load_Access, Size_Type>
299 template<
bool External_Load_Access = false,
typename Size_Type = std::
size_t>
300 class cc_hash_max_collision_check_resize_trigger
303 typedef Size_Type size_type;
307 external_load_access = External_Load_Access
312 cc_hash_max_collision_check_resize_trigger(
float load = 0.5);
315 swap(PB_DS_CLASS_C_DEC& other);
323 set_load(
float load);
327 notify_insert_search_start();
330 notify_insert_search_collision();
333 notify_insert_search_end();
336 notify_find_search_start();
339 notify_find_search_collision();
342 notify_find_search_end();
345 notify_erase_search_start();
348 notify_erase_search_collision();
351 notify_erase_search_end();
354 notify_inserted(size_type num_entries);
357 notify_erased(size_type num_entries);
365 notify_resized(size_type new_size);
368 notify_externally_resized(size_type new_size);
371 is_resize_needed()
const;
374 is_grow_needed(size_type
size, size_type num_entries)
const;
381 calc_resize_needed();
387 bool m_resize_needed;
390 #include <ext/pb_ds/detail/resize_policy/cc_hash_max_collision_check_resize_trigger_imp.hpp>
392 #undef PB_DS_CLASS_T_DEC
393 #undef PB_DS_CLASS_C_DEC
395 #define PB_DS_CLASS_T_DEC template<typename Size_Type>
396 #define PB_DS_CLASS_C_DEC hash_exponential_size_policy<Size_Type>
400 template<
typename Size_Type = std::
size_t>
401 class hash_exponential_size_policy
404 typedef Size_Type size_type;
410 hash_exponential_size_policy(size_type start_size = 8,
411 size_type grow_factor = 2);
414 swap(PB_DS_CLASS_C_DEC& other);
418 get_nearest_larger_size(size_type
size)
const;
421 get_nearest_smaller_size(size_type
size)
const;
424 size_type m_start_size;
425 size_type m_grow_factor;
428 #include <ext/pb_ds/detail/resize_policy/hash_exponential_size_policy_imp.hpp>
430 #undef PB_DS_CLASS_T_DEC
431 #undef PB_DS_CLASS_C_DEC
433 #define PB_DS_CLASS_T_DEC
434 #define PB_DS_CLASS_C_DEC hash_prime_size_policy
438 class hash_prime_size_policy
442 typedef std::size_t size_type;
447 hash_prime_size_policy(size_type start_size = 8);
450 swap(PB_DS_CLASS_C_DEC& other);
454 get_nearest_larger_size(size_type
size)
const;
457 get_nearest_smaller_size(size_type
size)
const;
460 size_type m_start_size;
463 #include <ext/pb_ds/detail/resize_policy/hash_prime_size_policy_imp.hpp>
465 #undef PB_DS_CLASS_T_DEC
466 #undef PB_DS_CLASS_C_DEC
468 #define PB_DS_CLASS_T_DEC template<typename Size_Policy, typename Trigger_Policy, bool External_Size_Access, typename Size_Type>
470 #define PB_DS_CLASS_C_DEC hash_standard_resize_policy<Size_Policy, Trigger_Policy, External_Size_Access, Size_Type>
473 template<
typename Size_Policy = hash_exponential_size_policy<>,
474 typename Trigger_Policy = hash_load_check_re
size_trigger<>,
475 bool External_Size_Access = false,
476 typename Size_Type = std::
size_t>
477 class hash_standard_resize_policy
478 :
public Size_Policy,
public Trigger_Policy
481 typedef Size_Type size_type;
482 typedef Trigger_Policy trigger_policy;
483 typedef Size_Policy size_policy;
487 external_size_access = External_Size_Access
491 hash_standard_resize_policy();
495 hash_standard_resize_policy(
const Size_Policy& r_size_policy);
501 hash_standard_resize_policy(
const Size_Policy& r_size_policy,
502 const Trigger_Policy& r_trigger_policy);
505 ~hash_standard_resize_policy();
508 swap(PB_DS_CLASS_C_DEC& other);
516 get_size_policy()
const;
520 get_trigger_policy();
523 const Trigger_Policy&
524 get_trigger_policy()
const;
528 get_actual_size()
const;
534 resize(size_type suggested_new_size);
538 notify_insert_search_start();
541 notify_insert_search_collision();
544 notify_insert_search_end();
547 notify_find_search_start();
550 notify_find_search_collision();
553 notify_find_search_end();
556 notify_erase_search_start();
559 notify_erase_search_collision();
562 notify_erase_search_end();
565 notify_inserted(size_type num_e);
568 notify_erased(size_type num_e);
574 notify_resized(size_type new_size);
577 is_resize_needed()
const;
584 get_new_size(size_type
size, size_type num_used_e)
const;
589 do_resize(size_type new_size);
591 typedef Trigger_Policy trigger_policy_base;
593 typedef Size_Policy size_policy_base;
598 #include <ext/pb_ds/detail/resize_policy/hash_standard_resize_policy_imp.hpp>
600 #undef PB_DS_CLASS_T_DEC
601 #undef PB_DS_CLASS_C_DEC