hash_table.hpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. /*
  2. template <class Value, unsigned int Options = 0, class Hash = hash<Value>, class Pred = equal_to<Value>,
  3. class Allocator = allocator<Value> >
  4. class hash_set
  5. {
  6. public:
  7. // types
  8. typedef Value key_type;
  9. typedef key_type value_type;
  10. typedef Hash hasher;
  11. typedef Pred key_equal;
  12. typedef Allocator allocator_type;
  13. typedef value_type& reference;
  14. typedef const value_type& const_reference;
  15. typedef typename allocator_traits<allocator_type>::pointer pointer;
  16. typedef typename allocator_traits<allocator_type>::const_pointer const_pointer;
  17. typedef typename allocator_traits<allocator_type>::size_type size_type;
  18. typedef typename allocator_traits<allocator_type>::difference_type difference_type;
  19. typedef /unspecified/ iterator;
  20. typedef /unspecified/ const_iterator;
  21. typedef /unspecified/ local_iterator;
  22. typedef /unspecified/ const_local_iterator;
  23. hash_set()
  24. noexcept(
  25. is_nothrow_default_constructible<hasher>::value &&
  26. is_nothrow_default_constructible<key_equal>::value &&
  27. is_nothrow_default_constructible<allocator_type>::value);
  28. explicit hash_set(size_type n, const hasher& hf = hasher(),
  29. const key_equal& eql = key_equal(),
  30. const allocator_type& a = allocator_type());
  31. template <class InputIterator>
  32. hash_set(InputIterator f, InputIterator l,
  33. size_type n = 0, const hasher& hf = hasher(),
  34. const key_equal& eql = key_equal(),
  35. const allocator_type& a = allocator_type());
  36. explicit hash_set(const allocator_type&);
  37. hash_set(const hash_set&);
  38. hash_set(const hash_set&, const Allocator&);
  39. hash_set(hash_set&&)
  40. noexcept(
  41. is_nothrow_move_constructible<hasher>::value &&
  42. is_nothrow_move_constructible<key_equal>::value &&
  43. is_nothrow_move_constructible<allocator_type>::value);
  44. hash_set(hash_set&&, const Allocator&);
  45. hash_set(initializer_list<value_type>, size_type n = 0,
  46. const hasher& hf = hasher(), const key_equal& eql = key_equal(),
  47. const allocator_type& a = allocator_type());
  48. ~hash_set();
  49. hash_set& operator=(const hash_set&);
  50. hash_set& operator=(hash_set&&)
  51. noexcept(
  52. allocator_type::propagate_on_container_move_assignment::value &&
  53. is_nothrow_move_assignable<allocator_type>::value &&
  54. is_nothrow_move_assignable<hasher>::value &&
  55. is_nothrow_move_assignable<key_equal>::value);
  56. hash_set& operator=(initializer_list<value_type>);
  57. allocator_type get_allocator() const noexcept;
  58. bool empty() const noexcept;
  59. size_type size() const noexcept;
  60. size_type max_size() const noexcept;
  61. iterator begin() noexcept;
  62. iterator end() noexcept;
  63. const_iterator begin() const noexcept;
  64. const_iterator end() const noexcept;
  65. const_iterator cbegin() const noexcept;
  66. const_iterator cend() const noexcept;
  67. template <class... Args>
  68. pair<iterator, bool> emplace(BOOST_FWD_REF(Args)... args);
  69. template <class... Args>
  70. iterator emplace_hint(const_iterator position, BOOST_FWD_REF(Args)... args);
  71. pair<iterator, bool> insert(const value_type& obj);
  72. pair<iterator, bool> insert(value_type&& obj);
  73. iterator insert(const_iterator hint, const value_type& obj);
  74. iterator insert(const_iterator hint, value_type&& obj);
  75. template <class InputIterator>
  76. void insert(InputIterator first, InputIterator last);
  77. void insert(initializer_list<value_type>);
  78. iterator erase(const_iterator position);
  79. size_type erase(const key_type& k);
  80. iterator erase(const_iterator first, const_iterator last);
  81. void clear() noexcept;
  82. void swap(hash_set&)
  83. noexcept(
  84. (!allocator_type::propagate_on_container_swap::value ||
  85. __is_nothrow_swappable<allocator_type>::value) &&
  86. __is_nothrow_swappable<hasher>::value &&
  87. __is_nothrow_swappable<key_equal>::value);
  88. hasher hash_function() const;
  89. key_equal key_eq() const;
  90. iterator find(const key_type& k);
  91. const_iterator find(const key_type& k) const;
  92. size_type count(const key_type& k) const;
  93. pair<iterator, iterator> equal_range(const key_type& k);
  94. pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
  95. size_type bucket_count() const noexcept;
  96. size_type max_bucket_count() const noexcept;
  97. size_type bucket_size(size_type n) const;
  98. size_type bucket(const key_type& k) const;
  99. local_iterator begin(size_type n);
  100. local_iterator end(size_type n);
  101. const_local_iterator begin(size_type n) const;
  102. const_local_iterator end(size_type n) const;
  103. const_local_iterator cbegin(size_type n) const;
  104. const_local_iterator cend(size_type n) const;
  105. float load_factor() const noexcept;
  106. float max_load_factor() const noexcept;
  107. void max_load_factor(float z);
  108. void rehash(size_type n);
  109. void reserve(size_type n);
  110. };
  111. template <class Key, class T, unsigned int Options = 0, class Hash = hash<Key>, class Pred = equal_to<Key>,
  112. class Allocator = allocator<pair<const Key, T> > >
  113. class hash_map
  114. {
  115. public:
  116. // types
  117. typedef Key key_type;
  118. typedef T mapped_type;
  119. typedef Hash hasher;
  120. typedef Pred key_equal;
  121. typedef Allocator allocator_type;
  122. typedef pair<const key_type, mapped_type> value_type;
  123. typedef value_type& reference;
  124. typedef const value_type& const_reference;
  125. typedef typename allocator_traits<allocator_type>::pointer pointer;
  126. typedef typename allocator_traits<allocator_type>::const_pointer const_pointer;
  127. typedef typename allocator_traits<allocator_type>::size_type size_type;
  128. typedef typename allocator_traits<allocator_type>::difference_type difference_type;
  129. typedef /unspecified/ iterator;
  130. typedef /unspecified/ const_iterator;
  131. typedef /unspecified/ local_iterator;
  132. typedef /unspecified/ const_local_iterator;
  133. hash_map()
  134. noexcept(
  135. is_nothrow_default_constructible<hasher>::value &&
  136. is_nothrow_default_constructible<key_equal>::value &&
  137. is_nothrow_default_constructible<allocator_type>::value);
  138. explicit hash_map(size_type n, const hasher& hf = hasher(),
  139. const key_equal& eql = key_equal(),
  140. const allocator_type& a = allocator_type());
  141. template <class InputIterator>
  142. hash_map(InputIterator f, InputIterator l,
  143. size_type n = 0, const hasher& hf = hasher(),
  144. const key_equal& eql = key_equal(),
  145. const allocator_type& a = allocator_type());
  146. explicit hash_map(const allocator_type&);
  147. hash_map(const hash_map&);
  148. hash_map(const hash_map&, const Allocator&);
  149. hash_map(hash_map&&)
  150. noexcept(
  151. is_nothrow_move_constructible<hasher>::value &&
  152. is_nothrow_move_constructible<key_equal>::value &&
  153. is_nothrow_move_constructible<allocator_type>::value);
  154. hash_map(hash_map&&, const Allocator&);
  155. hash_map(initializer_list<value_type>, size_type n = 0,
  156. const hasher& hf = hasher(), const key_equal& eql = key_equal(),
  157. const allocator_type& a = allocator_type());
  158. ~hash_map();
  159. hash_map& operator=(const hash_map&);
  160. hash_map& operator=(hash_map&&)
  161. noexcept(
  162. allocator_type::propagate_on_container_move_assignment::value &&
  163. is_nothrow_move_assignable<allocator_type>::value &&
  164. is_nothrow_move_assignable<hasher>::value &&
  165. is_nothrow_move_assignable<key_equal>::value);
  166. hash_map& operator=(initializer_list<value_type>);
  167. allocator_type get_allocator() const noexcept;
  168. bool empty() const noexcept;
  169. size_type size() const noexcept;
  170. size_type max_size() const noexcept;
  171. iterator begin() noexcept;
  172. iterator end() noexcept;
  173. const_iterator begin() const noexcept;
  174. const_iterator end() const noexcept;
  175. const_iterator cbegin() const noexcept;
  176. const_iterator cend() const noexcept;
  177. template <class... Args>
  178. pair<iterator, bool> emplace(BOOST_FWD_REF(Args)... args);
  179. template <class... Args>
  180. iterator emplace_hint(const_iterator position, BOOST_FWD_REF(Args)... args);
  181. pair<iterator, bool> insert(const value_type& obj);
  182. template <class P>
  183. pair<iterator, bool> insert(P&& obj);
  184. iterator insert(const_iterator hint, const value_type& obj);
  185. template <class P>
  186. iterator insert(const_iterator hint, P&& obj);
  187. template <class InputIterator>
  188. void insert(InputIterator first, InputIterator last);
  189. void insert(initializer_list<value_type>);
  190. iterator erase(const_iterator position);
  191. size_type erase(const key_type& k);
  192. iterator erase(const_iterator first, const_iterator last);
  193. void clear() noexcept;
  194. void swap(hash_map&)
  195. noexcept(
  196. (!allocator_type::propagate_on_container_swap::value ||
  197. __is_nothrow_swappable<allocator_type>::value) &&
  198. __is_nothrow_swappable<hasher>::value &&
  199. __is_nothrow_swappable<key_equal>::value);
  200. hasher hash_function() const;
  201. key_equal key_eq() const;
  202. iterator find(const key_type& k);
  203. const_iterator find(const key_type& k) const;
  204. size_type count(const key_type& k) const;
  205. pair<iterator, iterator> equal_range(const key_type& k);
  206. pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
  207. mapped_type& operator[](const key_type& k);
  208. mapped_type& operator[](key_type&& k);
  209. mapped_type& at(const key_type& k);
  210. const mapped_type& at(const key_type& k) const;
  211. size_type bucket_count() const noexcept;
  212. size_type max_bucket_count() const noexcept;
  213. size_type bucket_size(size_type n) const;
  214. size_type bucket(const key_type& k) const;
  215. local_iterator begin(size_type n);
  216. local_iterator end(size_type n);
  217. const_local_iterator begin(size_type n) const;
  218. const_local_iterator end(size_type n) const;
  219. const_local_iterator cbegin(size_type n) const;
  220. const_local_iterator cend(size_type n) const;
  221. float load_factor() const noexcept;
  222. float max_load_factor() const noexcept;
  223. void max_load_factor(float z);
  224. void rehash(size_type n);
  225. void reserve(size_type n);
  226. };
  227. */
  228. template <class Key, class Value, class KeyOfValue, unsigned int Options = 0, class Hash = hash<Key>, class Pred = equal_to<Key>,
  229. class Allocator = allocator<Value> >
  230. class hash_table
  231. {
  232. public:
  233. // types
  234. typedef Value key_type;
  235. typedef key_type value_type;
  236. typedef Hash hasher;
  237. typedef Pred key_equal;
  238. typedef Allocator allocator_type;
  239. typedef value_type& reference;
  240. typedef const value_type& const_reference;
  241. typedef typename allocator_traits<allocator_type>::pointer pointer;
  242. typedef typename allocator_traits<allocator_type>::const_pointer const_pointer;
  243. typedef typename allocator_traits<allocator_type>::size_type size_type;
  244. typedef typename allocator_traits<allocator_type>::difference_type difference_type;
  245. typedef /unspecified/ iterator;
  246. typedef /unspecified/ const_iterator;
  247. typedef /unspecified/ local_iterator;
  248. typedef /unspecified/ const_local_iterator;
  249. hash_set()
  250. noexcept(
  251. is_nothrow_default_constructible<hasher>::value &&
  252. is_nothrow_default_constructible<key_equal>::value &&
  253. is_nothrow_default_constructible<allocator_type>::value);
  254. explicit hash_set(size_type n, const hasher& hf = hasher(),
  255. const key_equal& eql = key_equal(),
  256. const allocator_type& a = allocator_type());
  257. template <class InputIterator>
  258. hash_set(InputIterator f, InputIterator l,
  259. size_type n = 0, const hasher& hf = hasher(),
  260. const key_equal& eql = key_equal(),
  261. const allocator_type& a = allocator_type());
  262. explicit hash_set(const allocator_type&);
  263. hash_set(const hash_set&);
  264. hash_set(const hash_set&, const Allocator&);
  265. hash_set(hash_set&&)
  266. noexcept(
  267. is_nothrow_move_constructible<hasher>::value &&
  268. is_nothrow_move_constructible<key_equal>::value &&
  269. is_nothrow_move_constructible<allocator_type>::value);
  270. hash_set(hash_set&&, const Allocator&);
  271. hash_set(initializer_list<value_type>, size_type n = 0,
  272. const hasher& hf = hasher(), const key_equal& eql = key_equal(),
  273. const allocator_type& a = allocator_type());
  274. ~hash_set();
  275. hash_set& operator=(const hash_set&);
  276. hash_set& operator=(hash_set&&)
  277. noexcept(
  278. allocator_type::propagate_on_container_move_assignment::value &&
  279. is_nothrow_move_assignable<allocator_type>::value &&
  280. is_nothrow_move_assignable<hasher>::value &&
  281. is_nothrow_move_assignable<key_equal>::value);
  282. hash_set& operator=(initializer_list<value_type>);
  283. allocator_type get_allocator() const noexcept;
  284. bool empty() const noexcept;
  285. size_type size() const noexcept;
  286. size_type max_size() const noexcept;
  287. iterator begin() noexcept;
  288. iterator end() noexcept;
  289. const_iterator begin() const noexcept;
  290. const_iterator end() const noexcept;
  291. const_iterator cbegin() const noexcept;
  292. const_iterator cend() const noexcept;
  293. template <class... Args>
  294. pair<iterator, bool> emplace(BOOST_FWD_REF(Args)... args);
  295. template <class... Args>
  296. iterator emplace_hint(const_iterator position, BOOST_FWD_REF(Args)... args);
  297. pair<iterator, bool> insert(const value_type& obj);
  298. pair<iterator, bool> insert(value_type&& obj);
  299. iterator insert(const_iterator hint, const value_type& obj);
  300. iterator insert(const_iterator hint, value_type&& obj);
  301. template <class InputIterator>
  302. void insert(InputIterator first, InputIterator last);
  303. void insert(initializer_list<value_type>);
  304. iterator erase(const_iterator position);
  305. size_type erase(const key_type& k);
  306. iterator erase(const_iterator first, const_iterator last);
  307. void clear() noexcept;
  308. void swap(hash_set&)
  309. noexcept(
  310. (!allocator_type::propagate_on_container_swap::value ||
  311. __is_nothrow_swappable<allocator_type>::value) &&
  312. __is_nothrow_swappable<hasher>::value &&
  313. __is_nothrow_swappable<key_equal>::value);
  314. hasher hash_function() const;
  315. key_equal key_eq() const;
  316. iterator find(const key_type& k);
  317. const_iterator find(const key_type& k) const;
  318. size_type count(const key_type& k) const;
  319. pair<iterator, iterator> equal_range(const key_type& k);
  320. pair<const_iterator, const_iterator> equal_range(const key_type& k) const;
  321. size_type bucket_count() const noexcept;
  322. size_type max_bucket_count() const noexcept;
  323. size_type bucket_size(size_type n) const;
  324. size_type bucket(const key_type& k) const;
  325. local_iterator begin(size_type n);
  326. local_iterator end(size_type n);
  327. const_local_iterator begin(size_type n) const;
  328. const_local_iterator end(size_type n) const;
  329. const_local_iterator cbegin(size_type n) const;
  330. const_local_iterator cend(size_type n) const;
  331. float load_factor() const noexcept;
  332. float max_load_factor() const noexcept;
  333. void max_load_factor(float z);
  334. void rehash(size_type n);
  335. void reserve(size_type n);
  336. };