flat_hash.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #pragma once
  2. #include <library/cpp/containers/flat_hash/lib/map.h>
  3. #include <library/cpp/containers/flat_hash/lib/containers.h>
  4. #include <library/cpp/containers/flat_hash/lib/probings.h>
  5. #include <library/cpp/containers/flat_hash/lib/set.h>
  6. #include <library/cpp/containers/flat_hash/lib/size_fitters.h>
  7. #include <library/cpp/containers/flat_hash/lib/expanders.h>
  8. #include <util/str_stl.h>
  9. namespace NPrivate {
  10. template <class Key, class T, class Hash, class KeyEqual, class Probing, class Alloc>
  11. using TFlatHashMapImpl = NFlatHash::TMap<Key, T, Hash, KeyEqual,
  12. NFlatHash::TFlatContainer<std::pair<const Key, T>, Alloc>,
  13. Probing, NFlatHash::TAndSizeFitter,
  14. NFlatHash::TSimpleExpander>;
  15. template <class Key, class T, auto emptyMarker, class Hash, class KeyEqual, class Probing, class Alloc>
  16. using TDenseHashMapImpl =
  17. NFlatHash::TMap<Key, T, Hash, KeyEqual,
  18. NFlatHash::TDenseContainer<std::pair<const Key, T>,
  19. NFlatHash::NMap::TStaticValueMarker<emptyMarker, T>,
  20. Alloc>,
  21. Probing, NFlatHash::TAndSizeFitter, NFlatHash::TSimpleExpander>;
  22. template <class T, class Hash, class KeyEqual, class Probing, class Alloc>
  23. using TFlatHashSetImpl = NFlatHash::TSet<T, Hash, KeyEqual,
  24. NFlatHash::TFlatContainer<T, Alloc>,
  25. Probing, NFlatHash::TAndSizeFitter,
  26. NFlatHash::TSimpleExpander>;
  27. template <class T, auto emptyMarker, class Hash, class KeyEqual, class Probing, class Alloc>
  28. using TDenseHashSetImpl =
  29. NFlatHash::TSet<T, Hash, KeyEqual,
  30. NFlatHash::TDenseContainer<T, NFlatHash::NSet::TStaticValueMarker<emptyMarker>, Alloc>,
  31. Probing, NFlatHash::TAndSizeFitter, NFlatHash::TSimpleExpander>;
  32. } // namespace NPrivate
  33. namespace NFH {
  34. /* flat_map: Fast and highly customizable hash map.
  35. *
  36. * Most features would be available soon.
  37. * Until that time we strongly insist on using only class aliases listed below.
  38. */
  39. /* Simpliest open addressing hash map.
  40. * Uses additional array to denote status of every bucket.
  41. * Default probing is linear.
  42. * Currently available probings:
  43. * * TLinearProbing
  44. * * TQuadraticProbing
  45. * * TDenseProbing
  46. */
  47. template <class Key,
  48. class T,
  49. class Hash = THash<Key>,
  50. class KeyEqual = std::equal_to<>,
  51. class Probing = NFlatHash::TLinearProbing,
  52. class Alloc = std::allocator<std::pair<const Key, T>>>
  53. using TFlatHashMap = NPrivate::TFlatHashMapImpl<Key, T, Hash, KeyEqual, Probing, Alloc>;
  54. /* Open addressing table with user specified marker for empty buckets.
  55. * Currently available probings:
  56. * * TLinearProbing
  57. * * TQuadraticProbing
  58. * * TDenseProbing
  59. */
  60. template <class Key,
  61. class T,
  62. auto emptyMarker,
  63. class Hash = THash<Key>,
  64. class KeyEqual = std::equal_to<>,
  65. class Probing = NFlatHash::TDenseProbing,
  66. class Alloc = std::allocator<std::pair<const Key, T>>>
  67. using TDenseHashMapStaticMarker = NPrivate::TDenseHashMapImpl<Key, T, emptyMarker,
  68. Hash, KeyEqual, Probing, Alloc>;
  69. /* flat_set: Fast and highly customizable hash set.
  70. *
  71. * Most features would be available soon.
  72. * Until that time we strongly insist on using only class aliases listed below.
  73. */
  74. /* Simpliest open addressing hash map.
  75. * Uses additional array to denote status of every bucket.
  76. * Default probing is linear.
  77. * Currently available probings:
  78. * * TLinearProbing
  79. * * TQuadraticProbing
  80. * * TDenseProbing
  81. */
  82. template <class T,
  83. class Hash = THash<T>,
  84. class KeyEqual = std::equal_to<>,
  85. class Probing = NFlatHash::TLinearProbing,
  86. class Alloc = std::allocator<T>>
  87. using TFlatHashSet = NPrivate::TFlatHashSetImpl<T, Hash, KeyEqual, Probing, Alloc>;
  88. /* Open addressing table with user specified marker for empty buckets.
  89. * Currently available probings:
  90. * * TLinearProbing
  91. * * TQuadraticProbing
  92. * * TDenseProbing
  93. */
  94. template <class T,
  95. auto emptyMarker,
  96. class Hash = THash<T>,
  97. class KeyEqual = std::equal_to<>,
  98. class Probing = NFlatHash::TDenseProbing,
  99. class Alloc = std::allocator<T>>
  100. using TDenseHashSetStaticMarker = NPrivate::TDenseHashSetImpl<T, emptyMarker,
  101. Hash, KeyEqual, Probing, Alloc>;
  102. } // namespace NFH