unordered_set.hpp 90 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160
  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Copyright Olaf Krzikalla 2004-2006.
  4. // (C) Copyright Ion Gaztanaga 2006-2013
  5. //
  6. // Distributed under the Boost Software License, Version 1.0.
  7. // (See accompanying file LICENSE_1_0.txt or copy at
  8. // http://www.boost.org/LICENSE_1_0.txt)
  9. //
  10. // See http://www.boost.org/libs/intrusive for documentation.
  11. //
  12. /////////////////////////////////////////////////////////////////////////////
  13. #ifndef BOOST_INTRUSIVE_UNORDERED_SET_HPP
  14. #define BOOST_INTRUSIVE_UNORDERED_SET_HPP
  15. #include <boost/intrusive/detail/config_begin.hpp>
  16. #include <boost/intrusive/intrusive_fwd.hpp>
  17. #include <boost/intrusive/hashtable.hpp>
  18. #include <boost/move/move.hpp>
  19. #include <iterator>
  20. namespace boost {
  21. namespace intrusive {
  22. //! The class template unordered_set is an intrusive container, that mimics most of
  23. //! the interface of std::tr1::unordered_set as described in the C++ TR1.
  24. //!
  25. //! unordered_set is a semi-intrusive container: each object to be stored in the
  26. //! container must contain a proper hook, but the container also needs
  27. //! additional auxiliary memory to work: unordered_set needs a pointer to an array
  28. //! of type `bucket_type` to be passed in the constructor. This bucket array must
  29. //! have at least the same lifetime as the container. This makes the use of
  30. //! unordered_set more complicated than purely intrusive containers.
  31. //! `bucket_type` is default-constructible, copyable and assignable
  32. //!
  33. //! The template parameter \c T is the type to be managed by the container.
  34. //! The user can specify additional options and if no options are provided
  35. //! default options are used.
  36. //!
  37. //! The container supports the following options:
  38. //! \c base_hook<>/member_hook<>/value_traits<>,
  39. //! \c constant_time_size<>, \c size_type<>, \c hash<> and \c equal<>
  40. //! \c bucket_traits<>, \c power_2_buckets<> and \c cache_begin<>.
  41. //!
  42. //! unordered_set only provides forward iterators but it provides 4 iterator types:
  43. //! iterator and const_iterator to navigate through the whole container and
  44. //! local_iterator and const_local_iterator to navigate through the values
  45. //! stored in a single bucket. Local iterators are faster and smaller.
  46. //!
  47. //! It's not recommended to use non constant-time size unordered_sets because several
  48. //! key functions, like "empty()", become non-constant time functions. Non
  49. //! constant-time size unordered_sets are mainly provided to support auto-unlink hooks.
  50. //!
  51. //! unordered_set, unlike std::unordered_set, does not make automatic rehashings nor
  52. //! offers functions related to a load factor. Rehashing can be explicitly requested
  53. //! and the user must provide a new bucket array that will be used from that moment.
  54. //!
  55. //! Since no automatic rehashing is done, iterators are never invalidated when
  56. //! inserting or erasing elements. Iterators are only invalidated when rehasing.
  57. #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
  58. template<class T, class ...Options>
  59. #else
  60. template<class ValueTraits, class Hash, class Equal, class SizeType, class BucketTraits, std::size_t BoolFlags>
  61. #endif
  62. class unordered_set_impl
  63. : public hashtable_impl<ValueTraits, Hash, Equal, SizeType, BucketTraits, BoolFlags>
  64. {
  65. /// @cond
  66. private:
  67. typedef hashtable_impl<ValueTraits, Hash, Equal, SizeType, BucketTraits, BoolFlags> table_type;
  68. //! This class is
  69. //! movable
  70. BOOST_MOVABLE_BUT_NOT_COPYABLE(unordered_set_impl)
  71. typedef table_type implementation_defined;
  72. /// @endcond
  73. public:
  74. typedef typename implementation_defined::value_type value_type;
  75. typedef typename implementation_defined::value_traits value_traits;
  76. typedef typename implementation_defined::bucket_traits bucket_traits;
  77. typedef typename implementation_defined::pointer pointer;
  78. typedef typename implementation_defined::const_pointer const_pointer;
  79. typedef typename implementation_defined::reference reference;
  80. typedef typename implementation_defined::const_reference const_reference;
  81. typedef typename implementation_defined::difference_type difference_type;
  82. typedef typename implementation_defined::size_type size_type;
  83. typedef typename implementation_defined::key_type key_type;
  84. typedef typename implementation_defined::key_equal key_equal;
  85. typedef typename implementation_defined::hasher hasher;
  86. typedef typename implementation_defined::bucket_type bucket_type;
  87. typedef typename implementation_defined::bucket_ptr bucket_ptr;
  88. typedef typename implementation_defined::iterator iterator;
  89. typedef typename implementation_defined::const_iterator const_iterator;
  90. typedef typename implementation_defined::insert_commit_data insert_commit_data;
  91. typedef typename implementation_defined::local_iterator local_iterator;
  92. typedef typename implementation_defined::const_local_iterator const_local_iterator;
  93. typedef typename implementation_defined::node_traits node_traits;
  94. typedef typename implementation_defined::node node;
  95. typedef typename implementation_defined::node_ptr node_ptr;
  96. typedef typename implementation_defined::const_node_ptr const_node_ptr;
  97. typedef typename implementation_defined::node_algorithms node_algorithms;
  98. public:
  99. //! <b>Requires</b>: buckets must not be being used by any other resource.
  100. //!
  101. //! <b>Effects</b>: Constructs an empty unordered_set_impl, storing a reference
  102. //! to the bucket array and copies of the hasher and equal functors.
  103. //!
  104. //! <b>Complexity</b>: Constant.
  105. //!
  106. //! <b>Throws</b>: If value_traits::node_traits::node
  107. //! constructor throws (this does not happen with predefined Boost.Intrusive hooks)
  108. //! or the copy constructor or invocation of Hash or Equal throws.
  109. //!
  110. //! <b>Notes</b>: buckets array must be disposed only after
  111. //! *this is disposed.
  112. explicit unordered_set_impl( const bucket_traits &b_traits
  113. , const hasher & hash_func = hasher()
  114. , const key_equal &equal_func = key_equal()
  115. , const value_traits &v_traits = value_traits())
  116. : table_type(b_traits, hash_func, equal_func, v_traits)
  117. {}
  118. //! <b>Requires</b>: buckets must not be being used by any other resource
  119. //! and Dereferencing iterator must yield an lvalue of type value_type.
  120. //!
  121. //! <b>Effects</b>: Constructs an empty unordered_set and inserts elements from
  122. //! [b, e).
  123. //!
  124. //! <b>Complexity</b>: If N is std::distance(b, e): Average case is O(N)
  125. //! (with a good hash function and with buckets_len >= N),worst case O(N2).
  126. //!
  127. //! <b>Throws</b>: If value_traits::node_traits::node
  128. //! constructor throws (this does not happen with predefined Boost.Intrusive hooks)
  129. //! or the copy constructor or invocation of hasher or key_equal throws.
  130. //!
  131. //! <b>Notes</b>: buckets array must be disposed only after
  132. //! *this is disposed.
  133. template<class Iterator>
  134. unordered_set_impl( Iterator b
  135. , Iterator e
  136. , const bucket_traits &b_traits
  137. , const hasher & hash_func = hasher()
  138. , const key_equal &equal_func = key_equal()
  139. , const value_traits &v_traits = value_traits())
  140. : table_type(b_traits, hash_func, equal_func, v_traits)
  141. { table_type::insert_unique(b, e); }
  142. //! <b>Effects</b>: to-do
  143. //!
  144. unordered_set_impl(BOOST_RV_REF(unordered_set_impl) x)
  145. : table_type(::boost::move(static_cast<table_type&>(x)))
  146. {}
  147. //! <b>Effects</b>: to-do
  148. //!
  149. unordered_set_impl& operator=(BOOST_RV_REF(unordered_set_impl) x)
  150. { return static_cast<unordered_set_impl&>(table_type::operator=(::boost::move(static_cast<table_type&>(x)))); }
  151. #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
  152. //! <b>Effects</b>: Detaches all elements from this. The objects in the unordered_set
  153. //! are not deleted (i.e. no destructors are called).
  154. //!
  155. //! <b>Complexity</b>: Linear to the number of elements in the unordered_set, if
  156. //! it's a safe-mode or auto-unlink value. Otherwise constant.
  157. //!
  158. //! <b>Throws</b>: Nothing.
  159. ~unordered_set_impl()
  160. {}
  161. //! <b>Effects</b>: Returns an iterator pointing to the beginning of the unordered_set.
  162. //!
  163. //! <b>Complexity</b>: Constant time if `cache_begin<>` is true. Amortized
  164. //! constant time with worst case (empty unordered_set) O(this->bucket_count())
  165. //!
  166. //! <b>Throws</b>: Nothing.
  167. iterator begin()
  168. { return table_type::begin(); }
  169. //! <b>Effects</b>: Returns a const_iterator pointing to the beginning
  170. //! of the unordered_set.
  171. //!
  172. //! <b>Complexity</b>: Constant time if `cache_begin<>` is true. Amortized
  173. //! constant time with worst case (empty unordered_set) O(this->bucket_count())
  174. //!
  175. //! <b>Throws</b>: Nothing.
  176. const_iterator begin() const
  177. { return table_type::begin(); }
  178. //! <b>Effects</b>: Returns a const_iterator pointing to the beginning
  179. //! of the unordered_set.
  180. //!
  181. //! <b>Complexity</b>: Constant time if `cache_begin<>` is true. Amortized
  182. //! constant time with worst case (empty unordered_set) O(this->bucket_count())
  183. //!
  184. //! <b>Throws</b>: Nothing.
  185. const_iterator cbegin() const
  186. { return table_type::cbegin(); }
  187. //! <b>Effects</b>: Returns an iterator pointing to the end of the unordered_set.
  188. //!
  189. //! <b>Complexity</b>: Constant.
  190. //!
  191. //! <b>Throws</b>: Nothing.
  192. iterator end()
  193. { return table_type::end(); }
  194. //! <b>Effects</b>: Returns a const_iterator pointing to the end of the unordered_set.
  195. //!
  196. //! <b>Complexity</b>: Constant.
  197. //!
  198. //! <b>Throws</b>: Nothing.
  199. const_iterator end() const
  200. { return table_type::end(); }
  201. //! <b>Effects</b>: Returns a const_iterator pointing to the end of the unordered_set.
  202. //!
  203. //! <b>Complexity</b>: Constant.
  204. //!
  205. //! <b>Throws</b>: Nothing.
  206. const_iterator cend() const
  207. { return table_type::cend(); }
  208. //! <b>Effects</b>: Returns the hasher object used by the unordered_set.
  209. //!
  210. //! <b>Complexity</b>: Constant.
  211. //!
  212. //! <b>Throws</b>: If hasher copy-constructor throws.
  213. hasher hash_function() const
  214. { return table_type::hash_function(); }
  215. //! <b>Effects</b>: Returns the key_equal object used by the unordered_set.
  216. //!
  217. //! <b>Complexity</b>: Constant.
  218. //!
  219. //! <b>Throws</b>: If key_equal copy-constructor throws.
  220. key_equal key_eq() const
  221. { return table_type::key_eq(); }
  222. //! <b>Effects</b>: Returns true if the container is empty.
  223. //!
  224. //! <b>Complexity</b>: if constant-time size and cache_last options are disabled,
  225. //! average constant time (worst case, with empty() == true: O(this->bucket_count()).
  226. //! Otherwise constant.
  227. //!
  228. //! <b>Throws</b>: Nothing.
  229. bool empty() const
  230. { return table_type::empty(); }
  231. //! <b>Effects</b>: Returns the number of elements stored in the unordered_set.
  232. //!
  233. //! <b>Complexity</b>: Linear to elements contained in *this if
  234. //! constant-time size option is disabled. Constant-time otherwise.
  235. //!
  236. //! <b>Throws</b>: Nothing.
  237. size_type size() const
  238. { return table_type::size(); }
  239. //! <b>Requires</b>: the hasher and the equality function unqualified swap
  240. //! call should not throw.
  241. //!
  242. //! <b>Effects</b>: Swaps the contents of two unordered_sets.
  243. //! Swaps also the contained bucket array and equality and hasher functors.
  244. //!
  245. //! <b>Complexity</b>: Constant.
  246. //!
  247. //! <b>Throws</b>: If the swap() call for the comparison or hash functors
  248. //! found using ADL throw. Basic guarantee.
  249. void swap(unordered_set_impl& other)
  250. { table_type::swap(other.table_); }
  251. //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
  252. //! Cloner should yield to nodes that compare equal and produce the same
  253. //! hash than the original node.
  254. //!
  255. //! <b>Effects</b>: Erases all the elements from *this
  256. //! calling Disposer::operator()(pointer), clones all the
  257. //! elements from src calling Cloner::operator()(const_reference )
  258. //! and inserts them on *this. The hash function and the equality
  259. //! predicate are copied from the source.
  260. //!
  261. //! If store_hash option is true, this method does not use the hash function.
  262. //!
  263. //! If any operation throws, all cloned elements are unlinked and disposed
  264. //! calling Disposer::operator()(pointer).
  265. //!
  266. //! <b>Complexity</b>: Linear to erased plus inserted elements.
  267. //!
  268. //! <b>Throws</b>: If cloner or hasher throw or hash or equality predicate copying
  269. //! throws. Basic guarantee.
  270. template <class Cloner, class Disposer>
  271. void clone_from(const unordered_set_impl &src, Cloner cloner, Disposer disposer)
  272. { table_type::clone_from(src.table_, cloner, disposer); }
  273. #endif //#ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
  274. //! <b>Requires</b>: value must be an lvalue
  275. //!
  276. //! <b>Effects</b>: Tries to inserts value into the unordered_set.
  277. //!
  278. //! <b>Returns</b>: If the value
  279. //! is not already present inserts it and returns a pair containing the
  280. //! iterator to the new value and true. If there is an equivalent value
  281. //! returns a pair containing an iterator to the already present value
  282. //! and false.
  283. //!
  284. //! <b>Complexity</b>: Average case O(1), worst case O(this->size()).
  285. //!
  286. //! <b>Throws</b>: If the internal hasher or the equality functor throws. Strong guarantee.
  287. //!
  288. //! <b>Note</b>: Does not affect the validity of iterators and references.
  289. //! No copy-constructors are called.
  290. std::pair<iterator, bool> insert(reference value)
  291. { return table_type::insert_unique(value); }
  292. //! <b>Requires</b>: Dereferencing iterator must yield an lvalue
  293. //! of type value_type.
  294. //!
  295. //! <b>Effects</b>: Equivalent to this->insert(t) for each element in [b, e).
  296. //!
  297. //! <b>Complexity</b>: Average case O(N), where N is std::distance(b, e).
  298. //! Worst case O(N*this->size()).
  299. //!
  300. //! <b>Throws</b>: If the internal hasher or the equality functor throws. Basic guarantee.
  301. //!
  302. //! <b>Note</b>: Does not affect the validity of iterators and references.
  303. //! No copy-constructors are called.
  304. template<class Iterator>
  305. void insert(Iterator b, Iterator e)
  306. { table_type::insert_unique(b, e); }
  307. //! <b>Requires</b>: "hasher" must be a hash function that induces
  308. //! the same hash values as the stored hasher. The difference is that
  309. //! "hasher" hashes the given key instead of the value_type.
  310. //!
  311. //! "key_value_equal" must be a equality function that induces
  312. //! the same equality as key_equal. The difference is that
  313. //! "key_value_equal" compares an arbitrary key with the contained values.
  314. //!
  315. //! <b>Effects</b>: Checks if a value can be inserted in the unordered_set, using
  316. //! a user provided key instead of the value itself.
  317. //!
  318. //! <b>Returns</b>: If there is an equivalent value
  319. //! returns a pair containing an iterator to the already present value
  320. //! and false. If the value can be inserted returns true in the returned
  321. //! pair boolean and fills "commit_data" that is meant to be used with
  322. //! the "insert_commit" function.
  323. //!
  324. //! <b>Complexity</b>: Average case O(1), worst case O(this->size()).
  325. //!
  326. //! <b>Throws</b>: If hasher or key_value_equal throw. Strong guarantee.
  327. //!
  328. //! <b>Notes</b>: This function is used to improve performance when constructing
  329. //! a value_type is expensive: if there is an equivalent value
  330. //! the constructed object must be discarded. Many times, the part of the
  331. //! node that is used to impose the hash or the equality is much cheaper to
  332. //! construct than the value_type and this function offers the possibility to
  333. //! use that the part to check if the insertion will be successful.
  334. //!
  335. //! If the check is successful, the user can construct the value_type and use
  336. //! "insert_commit" to insert the object in constant-time.
  337. //!
  338. //! "commit_data" remains valid for a subsequent "insert_commit" only if no more
  339. //! objects are inserted or erased from the unordered_set.
  340. //!
  341. //! After a successful rehashing insert_commit_data remains valid.
  342. template<class KeyType, class KeyHasher, class KeyValueEqual>
  343. std::pair<iterator, bool> insert_check
  344. (const KeyType &key, KeyHasher hasher, KeyValueEqual key_value_equal, insert_commit_data &commit_data)
  345. { return table_type::insert_unique_check(key, hasher, key_value_equal, commit_data); }
  346. //! <b>Requires</b>: value must be an lvalue of type value_type. commit_data
  347. //! must have been obtained from a previous call to "insert_check".
  348. //! No objects should have been inserted or erased from the unordered_set between
  349. //! the "insert_check" that filled "commit_data" and the call to "insert_commit".
  350. //!
  351. //! <b>Effects</b>: Inserts the value in the unordered_set using the information obtained
  352. //! from the "commit_data" that a previous "insert_check" filled.
  353. //!
  354. //! <b>Returns</b>: An iterator to the newly inserted object.
  355. //!
  356. //! <b>Complexity</b>: Constant time.
  357. //!
  358. //! <b>Throws</b>: Nothing.
  359. //!
  360. //! <b>Notes</b>: This function has only sense if a "insert_check" has been
  361. //! previously executed to fill "commit_data". No value should be inserted or
  362. //! erased between the "insert_check" and "insert_commit" calls.
  363. //!
  364. //! After a successful rehashing insert_commit_data remains valid.
  365. iterator insert_commit(reference value, const insert_commit_data &commit_data)
  366. { return table_type::insert_unique_commit(value, commit_data); }
  367. #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
  368. //! <b>Effects</b>: Erases the element pointed to by i.
  369. //!
  370. //! <b>Complexity</b>: Average case O(1), worst case O(this->size()).
  371. //!
  372. //! <b>Throws</b>: Nothing.
  373. //!
  374. //! <b>Note</b>: Invalidates the iterators (but not the references)
  375. //! to the erased element. No destructors are called.
  376. void erase(const_iterator i)
  377. { table_type::erase(i); }
  378. //! <b>Effects</b>: Erases the range pointed to by b end e.
  379. //!
  380. //! <b>Complexity</b>: Average case O(std::distance(b, e)),
  381. //! worst case O(this->size()).
  382. //!
  383. //! <b>Throws</b>: Nothing.
  384. //!
  385. //! <b>Note</b>: Invalidates the iterators (but not the references)
  386. //! to the erased elements. No destructors are called.
  387. void erase(const_iterator b, const_iterator e)
  388. { table_type::erase(b, e); }
  389. //! <b>Effects</b>: Erases all the elements with the given value.
  390. //!
  391. //! <b>Returns</b>: The number of erased elements.
  392. //!
  393. //! <b>Complexity</b>: Average case O(this->count(value)).
  394. //! Worst case O(this->size()).
  395. //!
  396. //! <b>Throws</b>: If the internal hasher or the equality functor throws. Basic guarantee.
  397. //!
  398. //! <b>Note</b>: Invalidates the iterators (but not the references)
  399. //! to the erased elements. No destructors are called.
  400. size_type erase(const_reference value)
  401. { return table_type::erase(value); }
  402. //! <b>Requires</b>: "hasher" must be a hash function that induces
  403. //! the same hash values as the stored hasher. The difference is that
  404. //! "hasher" hashes the given key instead of the value_type.
  405. //!
  406. //! "key_value_equal" must be a equality function that induces
  407. //! the same equality as key_equal. The difference is that
  408. //! "key_value_equal" compares an arbitrary key with the contained values.
  409. //!
  410. //! <b>Effects</b>: Erases all the elements that have the same hash and
  411. //! compare equal with the given key.
  412. //!
  413. //! <b>Returns</b>: The number of erased elements.
  414. //!
  415. //! <b>Complexity</b>: Average case O(this->count(value)).
  416. //! Worst case O(this->size()).
  417. //!
  418. //! <b>Throws</b>: If hash_func or equal_func throw. Basic guarantee.
  419. //!
  420. //! <b>Note</b>: Invalidates the iterators (but not the references)
  421. //! to the erased elements. No destructors are called.
  422. template<class KeyType, class KeyHasher, class KeyValueEqual>
  423. size_type erase(const KeyType& key, KeyHasher hash_func, KeyValueEqual equal_func)
  424. { return table_type::erase(key, hash_func, equal_func); }
  425. //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
  426. //!
  427. //! <b>Effects</b>: Erases the element pointed to by i.
  428. //! Disposer::operator()(pointer) is called for the removed element.
  429. //!
  430. //! <b>Complexity</b>: Average case O(1), worst case O(this->size()).
  431. //!
  432. //! <b>Throws</b>: Nothing.
  433. //!
  434. //! <b>Note</b>: Invalidates the iterators
  435. //! to the erased elements.
  436. template<class Disposer>
  437. void erase_and_dispose(const_iterator i, Disposer disposer
  438. /// @cond
  439. , typename detail::enable_if_c<!detail::is_convertible<Disposer, const_iterator>::value >::type * = 0
  440. /// @endcond
  441. )
  442. { table_type::erase_and_dispose(i, disposer); }
  443. //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
  444. //!
  445. //! <b>Effects</b>: Erases the range pointed to by b end e.
  446. //! Disposer::operator()(pointer) is called for the removed elements.
  447. //!
  448. //! <b>Complexity</b>: Average case O(std::distance(b, e)),
  449. //! worst case O(this->size()).
  450. //!
  451. //! <b>Throws</b>: Nothing.
  452. //!
  453. //! <b>Note</b>: Invalidates the iterators
  454. //! to the erased elements.
  455. template<class Disposer>
  456. void erase_and_dispose(const_iterator b, const_iterator e, Disposer disposer)
  457. { table_type::erase_and_dispose(b, e, disposer); }
  458. //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
  459. //!
  460. //! <b>Effects</b>: Erases all the elements with the given value.
  461. //! Disposer::operator()(pointer) is called for the removed elements.
  462. //!
  463. //! <b>Returns</b>: The number of erased elements.
  464. //!
  465. //! <b>Complexity</b>: Average case O(this->count(value)).
  466. //! Worst case O(this->size()).
  467. //!
  468. //! <b>Throws</b>: If the internal hasher or the equality functor throws. Basic guarantee.
  469. //!
  470. //! <b>Note</b>: Invalidates the iterators (but not the references)
  471. //! to the erased elements. No destructors are called.
  472. template<class Disposer>
  473. size_type erase_and_dispose(const_reference value, Disposer disposer)
  474. { return table_type::erase_and_dispose(value, disposer); }
  475. //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
  476. //!
  477. //! <b>Effects</b>: Erases all the elements with the given key.
  478. //! according to the comparison functor "equal_func".
  479. //! Disposer::operator()(pointer) is called for the removed elements.
  480. //!
  481. //! <b>Returns</b>: The number of erased elements.
  482. //!
  483. //! <b>Complexity</b>: Average case O(this->count(value)).
  484. //! Worst case O(this->size()).
  485. //!
  486. //! <b>Throws</b>: If hash_func or equal_func throw. Basic guarantee.
  487. //!
  488. //! <b>Note</b>: Invalidates the iterators
  489. //! to the erased elements.
  490. template<class KeyType, class KeyHasher, class KeyValueEqual, class Disposer>
  491. size_type erase_and_dispose(const KeyType& key, KeyHasher hash_func, KeyValueEqual equal_func, Disposer disposer)
  492. { return table_type::erase_and_dispose(key, hash_func, equal_func, disposer); }
  493. //! <b>Effects</b>: Erases all of the elements.
  494. //!
  495. //! <b>Complexity</b>: Linear to the number of elements on the container.
  496. //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise.
  497. //!
  498. //! <b>Throws</b>: Nothing.
  499. //!
  500. //! <b>Note</b>: Invalidates the iterators (but not the references)
  501. //! to the erased elements. No destructors are called.
  502. void clear()
  503. { return table_type::clear(); }
  504. //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
  505. //!
  506. //! <b>Effects</b>: Erases all of the elements.
  507. //!
  508. //! <b>Complexity</b>: Linear to the number of elements on the container.
  509. //! Disposer::operator()(pointer) is called for the removed elements.
  510. //!
  511. //! <b>Throws</b>: Nothing.
  512. //!
  513. //! <b>Note</b>: Invalidates the iterators (but not the references)
  514. //! to the erased elements. No destructors are called.
  515. template<class Disposer>
  516. void clear_and_dispose(Disposer disposer)
  517. { return table_type::clear_and_dispose(disposer); }
  518. //! <b>Effects</b>: Returns the number of contained elements with the given value
  519. //!
  520. //! <b>Complexity</b>: Average case O(1), worst case O(this->size()).
  521. //!
  522. //! <b>Throws</b>: If the internal hasher or the equality functor throws.
  523. size_type count(const_reference value) const
  524. { return table_type::find(value) != end(); }
  525. //! <b>Requires</b>: "hash_func" must be a hash function that induces
  526. //! the same hash values as the stored hasher. The difference is that
  527. //! "hash_func" hashes the given key instead of the value_type.
  528. //!
  529. //! "equal_func" must be a equality function that induces
  530. //! the same equality as key_equal. The difference is that
  531. //! "equal_func" compares an arbitrary key with the contained values.
  532. //!
  533. //! <b>Effects</b>: Returns the number of contained elements with the given key
  534. //!
  535. //! <b>Complexity</b>: Average case O(1), worst case O(this->size()).
  536. //!
  537. //! <b>Throws</b>: If hash_func or equal_func throw.
  538. template<class KeyType, class KeyHasher, class KeyValueEqual>
  539. size_type count(const KeyType& key, KeyHasher hash_func, KeyValueEqual equal_func) const
  540. { return table_type::find(key, hash_func, equal_func) != end(); }
  541. //! <b>Effects</b>: Finds an iterator to the first element is equal to
  542. //! "value" or end() if that element does not exist.
  543. //!
  544. //! <b>Complexity</b>: Average case O(1), worst case O(this->size()).
  545. //!
  546. //! <b>Throws</b>: If the internal hasher or the equality functor throws.
  547. iterator find(const_reference value)
  548. { return table_type::find(value); }
  549. //! <b>Requires</b>: "hash_func" must be a hash function that induces
  550. //! the same hash values as the stored hasher. The difference is that
  551. //! "hash_func" hashes the given key instead of the value_type.
  552. //!
  553. //! "equal_func" must be a equality function that induces
  554. //! the same equality as key_equal. The difference is that
  555. //! "equal_func" compares an arbitrary key with the contained values.
  556. //!
  557. //! <b>Effects</b>: Finds an iterator to the first element whose key is
  558. //! "key" according to the given hasher and equality functor or end() if
  559. //! that element does not exist.
  560. //!
  561. //! <b>Complexity</b>: Average case O(1), worst case O(this->size()).
  562. //!
  563. //! <b>Throws</b>: If hash_func or equal_func throw.
  564. //!
  565. //! <b>Note</b>: This function is used when constructing a value_type
  566. //! is expensive and the value_type can be compared with a cheaper
  567. //! key type. Usually this key is part of the value_type.
  568. template<class KeyType, class KeyHasher, class KeyValueEqual>
  569. iterator find(const KeyType& key, KeyHasher hash_func, KeyValueEqual equal_func)
  570. { return table_type::find(key, hash_func, equal_func); }
  571. //! <b>Effects</b>: Finds a const_iterator to the first element whose key is
  572. //! "key" or end() if that element does not exist.
  573. //!
  574. //! <b>Complexity</b>: Average case O(1), worst case O(this->size()).
  575. //!
  576. //! <b>Throws</b>: If the internal hasher or the equality functor throws.
  577. const_iterator find(const_reference value) const
  578. { return table_type::find(value); }
  579. //! <b>Requires</b>: "hash_func" must be a hash function that induces
  580. //! the same hash values as the stored hasher. The difference is that
  581. //! "hash_func" hashes the given key instead of the value_type.
  582. //!
  583. //! "equal_func" must be a equality function that induces
  584. //! the same equality as key_equal. The difference is that
  585. //! "equal_func" compares an arbitrary key with the contained values.
  586. //!
  587. //! <b>Effects</b>: Finds an iterator to the first element whose key is
  588. //! "key" according to the given hasher and equality functor or end() if
  589. //! that element does not exist.
  590. //!
  591. //! <b>Complexity</b>: Average case O(1), worst case O(this->size()).
  592. //!
  593. //! <b>Throws</b>: If hash_func or equal_func throw.
  594. //!
  595. //! <b>Note</b>: This function is used when constructing a value_type
  596. //! is expensive and the value_type can be compared with a cheaper
  597. //! key type. Usually this key is part of the value_type.
  598. template<class KeyType, class KeyHasher, class KeyValueEqual>
  599. const_iterator find(const KeyType& key, KeyHasher hash_func, KeyValueEqual equal_func) const
  600. { return table_type::find(key, hash_func, equal_func); }
  601. //! <b>Effects</b>: Returns a range containing all elements with values equivalent
  602. //! to value. Returns std::make_pair(this->end(), this->end()) if no such
  603. //! elements exist.
  604. //!
  605. //! <b>Complexity</b>: Average case O(this->count(value)). Worst case O(this->size()).
  606. //!
  607. //! <b>Throws</b>: If the internal hasher or the equality functor throws.
  608. std::pair<iterator,iterator> equal_range(const_reference value)
  609. { return table_type::equal_range(value); }
  610. //! <b>Requires</b>: "hash_func" must be a hash function that induces
  611. //! the same hash values as the stored hasher. The difference is that
  612. //! "hash_func" hashes the given key instead of the value_type.
  613. //!
  614. //! "equal_func" must be a equality function that induces
  615. //! the same equality as key_equal. The difference is that
  616. //! "equal_func" compares an arbitrary key with the contained values.
  617. //!
  618. //! <b>Effects</b>: Returns a range containing all elements with equivalent
  619. //! keys. Returns std::make_pair(this->end(), this->end()) if no such
  620. //! elements exist.
  621. //!
  622. //! <b>Complexity</b>: Average case O(this->count(key, hash_func, hash_func)).
  623. //! Worst case O(this->size()).
  624. //!
  625. //! <b>Throws</b>: If hash_func or the equal_func throw.
  626. //!
  627. //! <b>Note</b>: This function is used when constructing a value_type
  628. //! is expensive and the value_type can be compared with a cheaper
  629. //! key type. Usually this key is part of the value_type.
  630. template<class KeyType, class KeyHasher, class KeyValueEqual>
  631. std::pair<iterator,iterator> equal_range(const KeyType& key, KeyHasher hash_func, KeyValueEqual equal_func)
  632. { return table_type::equal_range(key, hash_func, equal_func); }
  633. //! <b>Effects</b>: Returns a range containing all elements with values equivalent
  634. //! to value. Returns std::make_pair(this->end(), this->end()) if no such
  635. //! elements exist.
  636. //!
  637. //! <b>Complexity</b>: Average case O(this->count(value)). Worst case O(this->size()).
  638. //!
  639. //! <b>Throws</b>: If the internal hasher or the equality functor throws.
  640. std::pair<const_iterator, const_iterator>
  641. equal_range(const_reference value) const
  642. { return table_type::equal_range(value); }
  643. //! <b>Requires</b>: "hash_func" must be a hash function that induces
  644. //! the same hash values as the stored hasher. The difference is that
  645. //! "hash_func" hashes the given key instead of the value_type.
  646. //!
  647. //! "equal_func" must be a equality function that induces
  648. //! the same equality as key_equal. The difference is that
  649. //! "equal_func" compares an arbitrary key with the contained values.
  650. //!
  651. //! <b>Effects</b>: Returns a range containing all elements with equivalent
  652. //! keys. Returns std::make_pair(this->end(), this->end()) if no such
  653. //! elements exist.
  654. //!
  655. //! <b>Complexity</b>: Average case O(this->count(key, hash_func, equal_func)).
  656. //! Worst case O(this->size()).
  657. //!
  658. //! <b>Throws</b>: If the hash_func or equal_func throw.
  659. //!
  660. //! <b>Note</b>: This function is used when constructing a value_type
  661. //! is expensive and the value_type can be compared with a cheaper
  662. //! key type. Usually this key is part of the value_type.
  663. template<class KeyType, class KeyHasher, class KeyValueEqual>
  664. std::pair<const_iterator, const_iterator>
  665. equal_range(const KeyType& key, KeyHasher hash_func, KeyValueEqual equal_func) const
  666. { return table_type::equal_range(key, hash_func, equal_func); }
  667. //! <b>Requires</b>: value must be an lvalue and shall be in a unordered_set of
  668. //! appropriate type. Otherwise the behavior is undefined.
  669. //!
  670. //! <b>Effects</b>: Returns: a valid iterator belonging to the unordered_set
  671. //! that points to the value
  672. //!
  673. //! <b>Complexity</b>: Constant.
  674. //!
  675. //! <b>Throws</b>: If the internal hash function throws.
  676. iterator iterator_to(reference value)
  677. { return table_type::iterator_to(value); }
  678. //! <b>Requires</b>: value must be an lvalue and shall be in a unordered_set of
  679. //! appropriate type. Otherwise the behavior is undefined.
  680. //!
  681. //! <b>Effects</b>: Returns: a valid const_iterator belonging to the
  682. //! unordered_set that points to the value
  683. //!
  684. //! <b>Complexity</b>: Constant.
  685. //!
  686. //! <b>Throws</b>: If the internal hash function throws.
  687. const_iterator iterator_to(const_reference value) const
  688. { return table_type::iterator_to(value); }
  689. //! <b>Requires</b>: value must be an lvalue and shall be in a unordered_set of
  690. //! appropriate type. Otherwise the behavior is undefined.
  691. //!
  692. //! <b>Effects</b>: Returns: a valid local_iterator belonging to the unordered_set
  693. //! that points to the value
  694. //!
  695. //! <b>Complexity</b>: Constant.
  696. //!
  697. //! <b>Throws</b>: Nothing.
  698. //!
  699. //! <b>Note</b>: This static function is available only if the <i>value traits</i>
  700. //! is stateless.
  701. static local_iterator s_local_iterator_to(reference value)
  702. { return table_type::s_local_iterator_to(value); }
  703. //! <b>Requires</b>: value must be an lvalue and shall be in a unordered_set of
  704. //! appropriate type. Otherwise the behavior is undefined.
  705. //!
  706. //! <b>Effects</b>: Returns: a valid const_local_iterator belonging to
  707. //! the unordered_set that points to the value
  708. //!
  709. //! <b>Complexity</b>: Constant.
  710. //!
  711. //! <b>Throws</b>: Nothing.
  712. //!
  713. //! <b>Note</b>: This static function is available only if the <i>value traits</i>
  714. //! is stateless.
  715. static const_local_iterator s_local_iterator_to(const_reference value)
  716. { return table_type::s_local_iterator_to(value); }
  717. //! <b>Requires</b>: value must be an lvalue and shall be in a unordered_set of
  718. //! appropriate type. Otherwise the behavior is undefined.
  719. //!
  720. //! <b>Effects</b>: Returns: a valid local_iterator belonging to the unordered_set
  721. //! that points to the value
  722. //!
  723. //! <b>Complexity</b>: Constant.
  724. //!
  725. //! <b>Throws</b>: Nothing.
  726. local_iterator local_iterator_to(reference value)
  727. { return table_type::local_iterator_to(value); }
  728. //! <b>Requires</b>: value must be an lvalue and shall be in a unordered_set of
  729. //! appropriate type. Otherwise the behavior is undefined.
  730. //!
  731. //! <b>Effects</b>: Returns: a valid const_local_iterator belonging to
  732. //! the unordered_set that points to the value
  733. //!
  734. //! <b>Complexity</b>: Constant.
  735. //!
  736. //! <b>Throws</b>: Nothing.
  737. const_local_iterator local_iterator_to(const_reference value) const
  738. { return table_type::local_iterator_to(value); }
  739. //! <b>Effects</b>: Returns the number of buckets passed in the constructor
  740. //! or the last rehash function.
  741. //!
  742. //! <b>Complexity</b>: Constant.
  743. //!
  744. //! <b>Throws</b>: Nothing.
  745. size_type bucket_count() const
  746. { return table_type::bucket_count(); }
  747. //! <b>Requires</b>: n is in the range [0, this->bucket_count()).
  748. //!
  749. //! <b>Effects</b>: Returns the number of elements in the nth bucket.
  750. //!
  751. //! <b>Complexity</b>: Constant.
  752. //!
  753. //! <b>Throws</b>: Nothing.
  754. size_type bucket_size(size_type n) const
  755. { return table_type::bucket_size(n); }
  756. //! <b>Effects</b>: Returns the index of the bucket in which elements
  757. //! with keys equivalent to k would be found, if any such element existed.
  758. //!
  759. //! <b>Complexity</b>: Constant.
  760. //!
  761. //! <b>Throws</b>: If the hash functor throws.
  762. //!
  763. //! <b>Note</b>: the return value is in the range [0, this->bucket_count()).
  764. size_type bucket(const value_type& k) const
  765. { return table_type::bucket(k); }
  766. //! <b>Requires</b>: "hash_func" must be a hash function that induces
  767. //! the same hash values as the stored hasher. The difference is that
  768. //! "hash_func" hashes the given key instead of the value_type.
  769. //!
  770. //! <b>Effects</b>: Returns the index of the bucket in which elements
  771. //! with keys equivalent to k would be found, if any such element existed.
  772. //!
  773. //! <b>Complexity</b>: Constant.
  774. //!
  775. //! <b>Throws</b>: If hash_func throws.
  776. //!
  777. //! <b>Note</b>: the return value is in the range [0, this->bucket_count()).
  778. template<class KeyType, class KeyHasher>
  779. size_type bucket(const KeyType& k, KeyHasher hash_func) const
  780. { return table_type::bucket(k, hash_func); }
  781. //! <b>Effects</b>: Returns the bucket array pointer passed in the constructor
  782. //! or the last rehash function.
  783. //!
  784. //! <b>Complexity</b>: Constant.
  785. //!
  786. //! <b>Throws</b>: Nothing.
  787. bucket_ptr bucket_pointer() const
  788. { return table_type::bucket_pointer(); }
  789. //! <b>Requires</b>: n is in the range [0, this->bucket_count()).
  790. //!
  791. //! <b>Effects</b>: Returns a local_iterator pointing to the beginning
  792. //! of the sequence stored in the bucket n.
  793. //!
  794. //! <b>Complexity</b>: Constant.
  795. //!
  796. //! <b>Throws</b>: Nothing.
  797. //!
  798. //! <b>Note</b>: [this->begin(n), this->end(n)) is a valid range
  799. //! containing all of the elements in the nth bucket.
  800. local_iterator begin(size_type n)
  801. { return table_type::begin(n); }
  802. //! <b>Requires</b>: n is in the range [0, this->bucket_count()).
  803. //!
  804. //! <b>Effects</b>: Returns a const_local_iterator pointing to the beginning
  805. //! of the sequence stored in the bucket n.
  806. //!
  807. //! <b>Complexity</b>: Constant.
  808. //!
  809. //! <b>Throws</b>: Nothing.
  810. //!
  811. //! <b>Note</b>: [this->begin(n), this->end(n)) is a valid range
  812. //! containing all of the elements in the nth bucket.
  813. const_local_iterator begin(size_type n) const
  814. { return table_type::begin(n); }
  815. //! <b>Requires</b>: n is in the range [0, this->bucket_count()).
  816. //!
  817. //! <b>Effects</b>: Returns a const_local_iterator pointing to the beginning
  818. //! of the sequence stored in the bucket n.
  819. //!
  820. //! <b>Complexity</b>: Constant.
  821. //!
  822. //! <b>Throws</b>: Nothing.
  823. //!
  824. //! <b>Note</b>: [this->begin(n), this->end(n)) is a valid range
  825. //! containing all of the elements in the nth bucket.
  826. const_local_iterator cbegin(size_type n) const
  827. { return table_type::cbegin(n); }
  828. //! <b>Requires</b>: n is in the range [0, this->bucket_count()).
  829. //!
  830. //! <b>Effects</b>: Returns a local_iterator pointing to the end
  831. //! of the sequence stored in the bucket n.
  832. //!
  833. //! <b>Complexity</b>: Constant.
  834. //!
  835. //! <b>Throws</b>: Nothing.
  836. //!
  837. //! <b>Note</b>: [this->begin(n), this->end(n)) is a valid range
  838. //! containing all of the elements in the nth bucket.
  839. local_iterator end(size_type n)
  840. { return table_type::end(n); }
  841. //! <b>Requires</b>: n is in the range [0, this->bucket_count()).
  842. //!
  843. //! <b>Effects</b>: Returns a const_local_iterator pointing to the end
  844. //! of the sequence stored in the bucket n.
  845. //!
  846. //! <b>Complexity</b>: Constant.
  847. //!
  848. //! <b>Throws</b>: Nothing.
  849. //!
  850. //! <b>Note</b>: [this->begin(n), this->end(n)) is a valid range
  851. //! containing all of the elements in the nth bucket.
  852. const_local_iterator end(size_type n) const
  853. { return table_type::end(n); }
  854. //! <b>Requires</b>: n is in the range [0, this->bucket_count()).
  855. //!
  856. //! <b>Effects</b>: Returns a const_local_iterator pointing to the end
  857. //! of the sequence stored in the bucket n.
  858. //!
  859. //! <b>Complexity</b>: Constant.
  860. //!
  861. //! <b>Throws</b>: Nothing.
  862. //!
  863. //! <b>Note</b>: [this->begin(n), this->end(n)) is a valid range
  864. //! containing all of the elements in the nth bucket.
  865. const_local_iterator cend(size_type n) const
  866. { return table_type::cend(n); }
  867. //! <b>Requires</b>: new_buckets must be a pointer to a new bucket array
  868. //! or the same as the old bucket array. new_size is the length of the
  869. //! the array pointed by new_buckets. If new_buckets == this->bucket_pointer()
  870. //! n can be bigger or smaller than this->bucket_count().
  871. //!
  872. //! <b>Effects</b>: Updates the internal reference with the new bucket erases
  873. //! the values from the old bucket and inserts then in the new one.
  874. //!
  875. //! If store_hash option is true, this method does not use the hash function.
  876. //!
  877. //! <b>Complexity</b>: Average case linear in this->size(), worst case quadratic.
  878. //!
  879. //! <b>Throws</b>: If the hasher functor throws. Basic guarantee.
  880. void rehash(const bucket_traits &new_bucket_traits)
  881. { table_type::rehash(new_bucket_traits); }
  882. //! <b>Requires</b>:
  883. //!
  884. //! <b>Effects</b>:
  885. //!
  886. //! <b>Complexity</b>:
  887. //!
  888. //! <b>Throws</b>:
  889. //!
  890. //! <b>Note</b>: this method is only available if incremental<true> option is activated.
  891. bool incremental_rehash(bool grow = true)
  892. { return table_type::incremental_rehash(grow); }
  893. //! <b>Note</b>: this method is only available if incremental<true> option is activated.
  894. bool incremental_rehash(const bucket_traits &new_bucket_traits)
  895. { return table_type::incremental_rehash(new_bucket_traits); }
  896. //! <b>Requires</b>:
  897. //!
  898. //! <b>Effects</b>:
  899. //!
  900. //! <b>Complexity</b>:
  901. //!
  902. //! <b>Throws</b>:
  903. size_type split_count() const
  904. { return table_type::split_count(); }
  905. //! <b>Effects</b>: Returns the nearest new bucket count optimized for
  906. //! the container that is bigger than n. This suggestion can be used
  907. //! to create bucket arrays with a size that will usually improve
  908. //! container's performance. If such value does not exist, the
  909. //! higher possible value is returned.
  910. //!
  911. //! <b>Complexity</b>: Amortized constant time.
  912. //!
  913. //! <b>Throws</b>: Nothing.
  914. static size_type suggested_upper_bucket_count(size_type n)
  915. { return table_type::suggested_upper_bucket_count(n); }
  916. //! <b>Effects</b>: Returns the nearest new bucket count optimized for
  917. //! the container that is smaller than n. This suggestion can be used
  918. //! to create bucket arrays with a size that will usually improve
  919. //! container's performance. If such value does not exist, the
  920. //! lower possible value is returned.
  921. //!
  922. //! <b>Complexity</b>: Amortized constant time.
  923. //!
  924. //! <b>Throws</b>: Nothing.
  925. static size_type suggested_lower_bucket_count(size_type n)
  926. { return table_type::suggested_lower_bucket_count(n); }
  927. #endif // #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
  928. };
  929. //! Helper metafunction to define an \c unordered_set that yields to the same type when the
  930. //! same options (either explicitly or implicitly) are used.
  931. #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
  932. template<class T, class ...Options>
  933. #else
  934. template<class T, class O1 = void, class O2 = void
  935. , class O3 = void, class O4 = void
  936. , class O5 = void, class O6 = void
  937. , class O7 = void, class O8 = void
  938. , class O9 = void, class O10= void
  939. >
  940. #endif
  941. struct make_unordered_set
  942. {
  943. /// @cond
  944. typedef typename pack_options
  945. < hashtable_defaults,
  946. #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
  947. O1, O2, O3, O4, O5, O6, O7, O8, O9, O10
  948. #else
  949. Options...
  950. #endif
  951. >::type packed_options;
  952. typedef typename detail::get_value_traits
  953. <T, typename packed_options::proto_value_traits>::type value_traits;
  954. typedef typename make_real_bucket_traits
  955. <T, true, packed_options>::type real_bucket_traits;
  956. typedef unordered_set_impl
  957. < value_traits
  958. , typename packed_options::hash
  959. , typename packed_options::equal
  960. , typename packed_options::size_type
  961. , real_bucket_traits
  962. , (std::size_t(true)*hash_bool_flags::unique_keys_pos)
  963. | (std::size_t(packed_options::constant_time_size)*hash_bool_flags::constant_time_size_pos)
  964. | (std::size_t(packed_options::power_2_buckets)*hash_bool_flags::power_2_buckets_pos)
  965. | (std::size_t(packed_options::cache_begin)*hash_bool_flags::cache_begin_pos)
  966. | (std::size_t(packed_options::compare_hash)*hash_bool_flags::compare_hash_pos)
  967. | (std::size_t(packed_options::incremental)*hash_bool_flags::incremental_pos)
  968. > implementation_defined;
  969. /// @endcond
  970. typedef implementation_defined type;
  971. };
  972. #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED
  973. #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
  974. template<class T, class O1, class O2, class O3, class O4, class O5, class O6, class O7, class O8, class O9, class O10>
  975. #else
  976. template<class T, class ...Options>
  977. #endif
  978. class unordered_set
  979. : public make_unordered_set<T,
  980. #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
  981. O1, O2, O3, O4, O5, O6, O7, O8, O9, O10
  982. #else
  983. Options...
  984. #endif
  985. >::type
  986. {
  987. typedef typename make_unordered_set
  988. <T,
  989. #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
  990. O1, O2, O3, O4, O5, O6, O7, O8, O9, O10
  991. #else
  992. Options...
  993. #endif
  994. >::type Base;
  995. //Assert if passed value traits are compatible with the type
  996. BOOST_STATIC_ASSERT((detail::is_same<typename Base::value_traits::value_type, T>::value));
  997. BOOST_MOVABLE_BUT_NOT_COPYABLE(unordered_set)
  998. public:
  999. typedef typename Base::value_traits value_traits;
  1000. typedef typename Base::bucket_traits bucket_traits;
  1001. typedef typename Base::iterator iterator;
  1002. typedef typename Base::const_iterator const_iterator;
  1003. typedef typename Base::bucket_ptr bucket_ptr;
  1004. typedef typename Base::size_type size_type;
  1005. typedef typename Base::hasher hasher;
  1006. typedef typename Base::key_equal key_equal;
  1007. explicit unordered_set ( const bucket_traits &b_traits
  1008. , const hasher & hash_func = hasher()
  1009. , const key_equal &equal_func = key_equal()
  1010. , const value_traits &v_traits = value_traits())
  1011. : Base(b_traits, hash_func, equal_func, v_traits)
  1012. {}
  1013. template<class Iterator>
  1014. unordered_set ( Iterator b
  1015. , Iterator e
  1016. , const bucket_traits &b_traits
  1017. , const hasher & hash_func = hasher()
  1018. , const key_equal &equal_func = key_equal()
  1019. , const value_traits &v_traits = value_traits())
  1020. : Base(b, e, b_traits, hash_func, equal_func, v_traits)
  1021. {}
  1022. unordered_set(BOOST_RV_REF(unordered_set) x)
  1023. : Base(::boost::move(static_cast<Base&>(x)))
  1024. {}
  1025. unordered_set& operator=(BOOST_RV_REF(unordered_set) x)
  1026. { return static_cast<unordered_set&>(this->Base::operator=(::boost::move(static_cast<Base&>(x)))); }
  1027. };
  1028. #endif
  1029. //! The class template unordered_multiset is an intrusive container, that mimics most of
  1030. //! the interface of std::tr1::unordered_multiset as described in the C++ TR1.
  1031. //!
  1032. //! unordered_multiset is a semi-intrusive container: each object to be stored in the
  1033. //! container must contain a proper hook, but the container also needs
  1034. //! additional auxiliary memory to work: unordered_multiset needs a pointer to an array
  1035. //! of type `bucket_type` to be passed in the constructor. This bucket array must
  1036. //! have at least the same lifetime as the container. This makes the use of
  1037. //! unordered_multiset more complicated than purely intrusive containers.
  1038. //! `bucket_type` is default-constructible, copyable and assignable
  1039. //!
  1040. //! The template parameter \c T is the type to be managed by the container.
  1041. //! The user can specify additional options and if no options are provided
  1042. //! default options are used.
  1043. //!
  1044. //! The container supports the following options:
  1045. //! \c base_hook<>/member_hook<>/value_traits<>,
  1046. //! \c constant_time_size<>, \c size_type<>, \c hash<> and \c equal<>
  1047. //! \c bucket_traits<>, \c power_2_buckets<> and \c cache_begin<>.
  1048. //!
  1049. //! unordered_multiset only provides forward iterators but it provides 4 iterator types:
  1050. //! iterator and const_iterator to navigate through the whole container and
  1051. //! local_iterator and const_local_iterator to navigate through the values
  1052. //! stored in a single bucket. Local iterators are faster and smaller.
  1053. //!
  1054. //! It's not recommended to use non constant-time size unordered_multisets because several
  1055. //! key functions, like "empty()", become non-constant time functions. Non
  1056. //! constant-time size unordered_multisets are mainly provided to support auto-unlink hooks.
  1057. //!
  1058. //! unordered_multiset, unlike std::unordered_set, does not make automatic rehashings nor
  1059. //! offers functions related to a load factor. Rehashing can be explicitly requested
  1060. //! and the user must provide a new bucket array that will be used from that moment.
  1061. //!
  1062. //! Since no automatic rehashing is done, iterators are never invalidated when
  1063. //! inserting or erasing elements. Iterators are only invalidated when rehasing.
  1064. #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
  1065. template<class T, class ...Options>
  1066. #else
  1067. template<class ValueTraits, class Hash, class Equal, class SizeType, class BucketTraits, std::size_t BoolFlags>
  1068. #endif
  1069. class unordered_multiset_impl
  1070. : public hashtable_impl<ValueTraits, Hash, Equal, SizeType, BucketTraits, BoolFlags>
  1071. {
  1072. /// @cond
  1073. private:
  1074. typedef hashtable_impl<ValueTraits, Hash, Equal, SizeType, BucketTraits, BoolFlags> table_type;
  1075. /// @endcond
  1076. //Movable
  1077. BOOST_MOVABLE_BUT_NOT_COPYABLE(unordered_multiset_impl)
  1078. typedef table_type implementation_defined;
  1079. public:
  1080. typedef typename implementation_defined::value_type value_type;
  1081. typedef typename implementation_defined::value_traits value_traits;
  1082. typedef typename implementation_defined::bucket_traits bucket_traits;
  1083. typedef typename implementation_defined::pointer pointer;
  1084. typedef typename implementation_defined::const_pointer const_pointer;
  1085. typedef typename implementation_defined::reference reference;
  1086. typedef typename implementation_defined::const_reference const_reference;
  1087. typedef typename implementation_defined::difference_type difference_type;
  1088. typedef typename implementation_defined::size_type size_type;
  1089. typedef typename implementation_defined::key_type key_type;
  1090. typedef typename implementation_defined::key_equal key_equal;
  1091. typedef typename implementation_defined::hasher hasher;
  1092. typedef typename implementation_defined::bucket_type bucket_type;
  1093. typedef typename implementation_defined::bucket_ptr bucket_ptr;
  1094. typedef typename implementation_defined::iterator iterator;
  1095. typedef typename implementation_defined::const_iterator const_iterator;
  1096. typedef typename implementation_defined::insert_commit_data insert_commit_data;
  1097. typedef typename implementation_defined::local_iterator local_iterator;
  1098. typedef typename implementation_defined::const_local_iterator const_local_iterator;
  1099. typedef typename implementation_defined::node_traits node_traits;
  1100. typedef typename implementation_defined::node node;
  1101. typedef typename implementation_defined::node_ptr node_ptr;
  1102. typedef typename implementation_defined::const_node_ptr const_node_ptr;
  1103. typedef typename implementation_defined::node_algorithms node_algorithms;
  1104. public:
  1105. //! <b>Requires</b>: buckets must not be being used by any other resource.
  1106. //!
  1107. //! <b>Effects</b>: Constructs an empty unordered_multiset, storing a reference
  1108. //! to the bucket array and copies of the hasher and equal functors.
  1109. //!
  1110. //! <b>Complexity</b>: Constant.
  1111. //!
  1112. //! <b>Throws</b>: If value_traits::node_traits::node
  1113. //! constructor throws (this does not happen with predefined Boost.Intrusive hooks)
  1114. //! or the copy constructor or invocation of Hash or Equal throws.
  1115. //!
  1116. //! <b>Notes</b>: buckets array must be disposed only after
  1117. //! *this is disposed.
  1118. explicit unordered_multiset_impl ( const bucket_traits &b_traits
  1119. , const hasher & hash_func = hasher()
  1120. , const key_equal &equal_func = key_equal()
  1121. , const value_traits &v_traits = value_traits())
  1122. : table_type(b_traits, hash_func, equal_func, v_traits)
  1123. {}
  1124. //! <b>Requires</b>: buckets must not be being used by any other resource
  1125. //! and Dereferencing iterator must yield an lvalue of type value_type.
  1126. //!
  1127. //! <b>Effects</b>: Constructs an empty unordered_multiset and inserts elements from
  1128. //! [b, e).
  1129. //!
  1130. //! <b>Complexity</b>: If N is std::distance(b, e): Average case is O(N)
  1131. //! (with a good hash function and with buckets_len >= N),worst case O(N2).
  1132. //!
  1133. //! <b>Throws</b>: If value_traits::node_traits::node
  1134. //! constructor throws (this does not happen with predefined Boost.Intrusive hooks)
  1135. //! or the copy constructor or invocation of hasher or key_equal throws.
  1136. //!
  1137. //! <b>Notes</b>: buckets array must be disposed only after
  1138. //! *this is disposed.
  1139. template<class Iterator>
  1140. unordered_multiset_impl ( Iterator b
  1141. , Iterator e
  1142. , const bucket_traits &b_traits
  1143. , const hasher & hash_func = hasher()
  1144. , const key_equal &equal_func = key_equal()
  1145. , const value_traits &v_traits = value_traits())
  1146. : table_type(b_traits, hash_func, equal_func, v_traits)
  1147. { table_type::insert_equal(b, e); }
  1148. //! <b>Effects</b>: to-do
  1149. //!
  1150. unordered_multiset_impl(BOOST_RV_REF(unordered_multiset_impl) x)
  1151. : table_type(::boost::move(static_cast<table_type&>(x)))
  1152. {}
  1153. //! <b>Effects</b>: to-do
  1154. //!
  1155. unordered_multiset_impl& operator=(BOOST_RV_REF(unordered_multiset_impl) x)
  1156. { return static_cast<unordered_multiset_impl&>(table_type::operator=(::boost::move(static_cast<table_type&>(x)))); }
  1157. #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
  1158. //! <b>Effects</b>: Detaches all elements from this. The objects in the unordered_multiset
  1159. //! are not deleted (i.e. no destructors are called).
  1160. //!
  1161. //! <b>Complexity</b>: Linear to the number of elements in the unordered_multiset, if
  1162. //! it's a safe-mode or auto-unlink value. Otherwise constant.
  1163. //!
  1164. //! <b>Throws</b>: Nothing.
  1165. ~unordered_multiset_impl()
  1166. {}
  1167. //! <b>Effects</b>: Returns an iterator pointing to the beginning of the unordered_multiset.
  1168. //!
  1169. //! <b>Complexity</b>: Constant time if `cache_begin<>` is true. Amortized
  1170. //! constant time with worst case (empty unordered_set) O(this->bucket_count())
  1171. //!
  1172. //! <b>Throws</b>: Nothing.
  1173. iterator begin()
  1174. { return table_type::begin(); }
  1175. //! <b>Effects</b>: Returns a const_iterator pointing to the beginning
  1176. //! of the unordered_multiset.
  1177. //!
  1178. //! <b>Complexity</b>: Constant time if `cache_begin<>` is true. Amortized
  1179. //! constant time with worst case (empty unordered_set) O(this->bucket_count())
  1180. //!
  1181. //! <b>Throws</b>: Nothing.
  1182. const_iterator begin() const
  1183. { return table_type::begin(); }
  1184. //! <b>Effects</b>: Returns a const_iterator pointing to the beginning
  1185. //! of the unordered_multiset.
  1186. //!
  1187. //! <b>Complexity</b>: Constant time if `cache_begin<>` is true. Amortized
  1188. //! constant time with worst case (empty unordered_set) O(this->bucket_count())
  1189. //!
  1190. //! <b>Throws</b>: Nothing.
  1191. const_iterator cbegin() const
  1192. { return table_type::cbegin(); }
  1193. //! <b>Effects</b>: Returns an iterator pointing to the end of the unordered_multiset.
  1194. //!
  1195. //! <b>Complexity</b>: Constant.
  1196. //!
  1197. //! <b>Throws</b>: Nothing.
  1198. iterator end()
  1199. { return table_type::end(); }
  1200. //! <b>Effects</b>: Returns a const_iterator pointing to the end of the unordered_multiset.
  1201. //!
  1202. //! <b>Complexity</b>: Constant.
  1203. //!
  1204. //! <b>Throws</b>: Nothing.
  1205. const_iterator end() const
  1206. { return table_type::end(); }
  1207. //! <b>Effects</b>: Returns a const_iterator pointing to the end of the unordered_multiset.
  1208. //!
  1209. //! <b>Complexity</b>: Constant.
  1210. //!
  1211. //! <b>Throws</b>: Nothing.
  1212. const_iterator cend() const
  1213. { return table_type::cend(); }
  1214. //! <b>Effects</b>: Returns the hasher object used by the unordered_set.
  1215. //!
  1216. //! <b>Complexity</b>: Constant.
  1217. //!
  1218. //! <b>Throws</b>: If hasher copy-constructor throws.
  1219. hasher hash_function() const
  1220. { return table_type::hash_function(); }
  1221. //! <b>Effects</b>: Returns the key_equal object used by the unordered_multiset.
  1222. //!
  1223. //! <b>Complexity</b>: Constant.
  1224. //!
  1225. //! <b>Throws</b>: If key_equal copy-constructor throws.
  1226. key_equal key_eq() const
  1227. { return table_type::key_eq(); }
  1228. //! <b>Effects</b>: Returns true if the container is empty.
  1229. //!
  1230. //! <b>Complexity</b>: if constant-time size and cache_last options are disabled,
  1231. //! average constant time (worst case, with empty() == true: O(this->bucket_count()).
  1232. //! Otherwise constant.
  1233. //!
  1234. //! <b>Throws</b>: Nothing.
  1235. bool empty() const
  1236. { return table_type::empty(); }
  1237. //! <b>Effects</b>: Returns the number of elements stored in the unordered_multiset.
  1238. //!
  1239. //! <b>Complexity</b>: Linear to elements contained in *this if
  1240. //! constant-time size option is disabled. Constant-time otherwise.
  1241. //!
  1242. //! <b>Throws</b>: Nothing.
  1243. size_type size() const
  1244. { return table_type::size(); }
  1245. //! <b>Requires</b>: the hasher and the equality function unqualified swap
  1246. //! call should not throw.
  1247. //!
  1248. //! <b>Effects</b>: Swaps the contents of two unordered_multisets.
  1249. //! Swaps also the contained bucket array and equality and hasher functors.
  1250. //!
  1251. //!
  1252. //! <b>Complexity</b>: Constant.
  1253. //!
  1254. //! <b>Throws</b>: If the swap() call for the comparison or hash functors
  1255. //! found using ADL throw. Basic guarantee.
  1256. void swap(unordered_multiset_impl& other)
  1257. { table_type::swap(other.table_); }
  1258. //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
  1259. //! Cloner should yield to nodes that compare equal and produce the same
  1260. //! hash than the original node.
  1261. //!
  1262. //! <b>Effects</b>: Erases all the elements from *this
  1263. //! calling Disposer::operator()(pointer), clones all the
  1264. //! elements from src calling Cloner::operator()(const_reference )
  1265. //! and inserts them on *this. The hash function and the equality
  1266. //! predicate are copied from the source.
  1267. //!
  1268. //! If store_hash option is true, this method does not use the hash function.
  1269. //!
  1270. //! If any operation throws, all cloned elements are unlinked and disposed
  1271. //! calling Disposer::operator()(pointer).
  1272. //!
  1273. //! <b>Complexity</b>: Linear to erased plus inserted elements.
  1274. //!
  1275. //! <b>Throws</b>: If cloner or hasher throw or hash or equality predicate copying
  1276. //! throws. Basic guarantee.
  1277. template <class Cloner, class Disposer>
  1278. void clone_from(const unordered_multiset_impl &src, Cloner cloner, Disposer disposer)
  1279. { table_type::clone_from(src.table_, cloner, disposer); }
  1280. #endif // #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
  1281. //! <b>Requires</b>: value must be an lvalue
  1282. //!
  1283. //! <b>Effects</b>: Inserts value into the unordered_multiset.
  1284. //!
  1285. //! <b>Returns</b>: An iterator to the new inserted value.
  1286. //!
  1287. //! <b>Complexity</b>: Average case O(1), worst case O(this->size()).
  1288. //!
  1289. //! <b>Throws</b>: If the internal hasher or the equality functor throws. Strong guarantee.
  1290. //!
  1291. //! <b>Note</b>: Does not affect the validity of iterators and references.
  1292. //! No copy-constructors are called.
  1293. iterator insert(reference value)
  1294. { return table_type::insert_equal(value); }
  1295. //! <b>Requires</b>: Dereferencing iterator must yield an lvalue
  1296. //! of type value_type.
  1297. //!
  1298. //! <b>Effects</b>: Equivalent to this->insert(t) for each element in [b, e).
  1299. //!
  1300. //! <b>Complexity</b>: Average case is O(N), where N is the
  1301. //! size of the range.
  1302. //!
  1303. //! <b>Throws</b>: If the internal hasher or the equality functor throws. Basic guarantee.
  1304. //!
  1305. //! <b>Note</b>: Does not affect the validity of iterators and references.
  1306. //! No copy-constructors are called.
  1307. template<class Iterator>
  1308. void insert(Iterator b, Iterator e)
  1309. { table_type::insert_equal(b, e); }
  1310. #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
  1311. //! <b>Effects</b>: Erases the element pointed to by i.
  1312. //!
  1313. //! <b>Complexity</b>: Average case O(1), worst case O(this->size()).
  1314. //!
  1315. //! <b>Throws</b>: Nothing.
  1316. //!
  1317. //! <b>Note</b>: Invalidates the iterators (but not the references)
  1318. //! to the erased element. No destructors are called.
  1319. void erase(const_iterator i)
  1320. { table_type::erase(i); }
  1321. //! <b>Effects</b>: Erases the range pointed to by b end e.
  1322. //!
  1323. //! <b>Complexity</b>: Average case O(std::distance(b, e)),
  1324. //! worst case O(this->size()).
  1325. //!
  1326. //! <b>Throws</b>: Nothing.
  1327. //!
  1328. //! <b>Note</b>: Invalidates the iterators (but not the references)
  1329. //! to the erased elements. No destructors are called.
  1330. void erase(const_iterator b, const_iterator e)
  1331. { table_type::erase(b, e); }
  1332. //! <b>Effects</b>: Erases all the elements with the given value.
  1333. //!
  1334. //! <b>Returns</b>: The number of erased elements.
  1335. //!
  1336. //! <b>Complexity</b>: Average case O(this->count(value)).
  1337. //! Worst case O(this->size()).
  1338. //!
  1339. //! <b>Throws</b>: If the internal hasher or the equality functor throws. Basic guarantee.
  1340. //!
  1341. //! <b>Note</b>: Invalidates the iterators (but not the references)
  1342. //! to the erased elements. No destructors are called.
  1343. size_type erase(const_reference value)
  1344. { return table_type::erase(value); }
  1345. //! <b>Requires</b>: "hash_func" must be a hash function that induces
  1346. //! the same hash values as the stored hasher. The difference is that
  1347. //! "hash_func" hashes the given key instead of the value_type.
  1348. //!
  1349. //! "key_value_equal" must be a equality function that induces
  1350. //! the same equality as key_equal. The difference is that
  1351. //! "key_value_equal" compares an arbitrary key with the contained values.
  1352. //!
  1353. //! <b>Effects</b>: Erases all the elements that have the same hash and
  1354. //! compare equal with the given key.
  1355. //!
  1356. //! <b>Returns</b>: The number of erased elements.
  1357. //!
  1358. //! <b>Complexity</b>: Average case O(this->count(value)).
  1359. //! Worst case O(this->size()).
  1360. //!
  1361. //! <b>Throws</b>: If the hash_func or the equal_func functors throws.
  1362. //! Basic guarantee.
  1363. //!
  1364. //! <b>Note</b>: Invalidates the iterators (but not the references)
  1365. //! to the erased elements. No destructors are called.
  1366. template<class KeyType, class KeyHasher, class KeyValueEqual>
  1367. size_type erase(const KeyType& key, KeyHasher hash_func, KeyValueEqual equal_func)
  1368. { return table_type::erase(key, hash_func, equal_func); }
  1369. //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
  1370. //!
  1371. //! <b>Effects</b>: Erases the element pointed to by i.
  1372. //! Disposer::operator()(pointer) is called for the removed element.
  1373. //!
  1374. //! <b>Complexity</b>: Average case O(1), worst case O(this->size()).
  1375. //!
  1376. //! <b>Throws</b>: Nothing.
  1377. //!
  1378. //! <b>Note</b>: Invalidates the iterators
  1379. //! to the erased elements.
  1380. template<class Disposer>
  1381. void erase_and_dispose(const_iterator i, Disposer disposer
  1382. /// @cond
  1383. , typename detail::enable_if_c<!detail::is_convertible<Disposer, const_iterator>::value >::type * = 0
  1384. /// @endcond
  1385. )
  1386. { table_type::erase_and_dispose(i, disposer); }
  1387. #if !defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED)
  1388. template<class Disposer>
  1389. void erase_and_dispose(const_iterator i, Disposer disposer)
  1390. { this->erase_and_dispose(const_iterator(i), disposer); }
  1391. #endif
  1392. //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
  1393. //!
  1394. //! <b>Effects</b>: Erases the range pointed to by b end e.
  1395. //! Disposer::operator()(pointer) is called for the removed elements.
  1396. //!
  1397. //! <b>Complexity</b>: Average case O(std::distance(b, e)),
  1398. //! worst case O(this->size()).
  1399. //!
  1400. //! <b>Throws</b>: Nothing.
  1401. //!
  1402. //! <b>Note</b>: Invalidates the iterators
  1403. //! to the erased elements.
  1404. template<class Disposer>
  1405. void erase_and_dispose(const_iterator b, const_iterator e, Disposer disposer)
  1406. { table_type::erase_and_dispose(b, e, disposer); }
  1407. //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
  1408. //!
  1409. //! <b>Effects</b>: Erases all the elements with the given value.
  1410. //! Disposer::operator()(pointer) is called for the removed elements.
  1411. //!
  1412. //! <b>Returns</b>: The number of erased elements.
  1413. //!
  1414. //! <b>Complexity</b>: Average case O(this->count(value)).
  1415. //! Worst case O(this->size()).
  1416. //!
  1417. //! <b>Throws</b>: If the internal hasher or the equality functor throws. Basic guarantee.
  1418. //!
  1419. //! <b>Note</b>: Invalidates the iterators (but not the references)
  1420. //! to the erased elements. No destructors are called.
  1421. template<class Disposer>
  1422. size_type erase_and_dispose(const_reference value, Disposer disposer)
  1423. { return table_type::erase_and_dispose(value, disposer); }
  1424. //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
  1425. //!
  1426. //! <b>Effects</b>: Erases all the elements with the given key.
  1427. //! according to the comparison functor "equal_func".
  1428. //! Disposer::operator()(pointer) is called for the removed elements.
  1429. //!
  1430. //! <b>Returns</b>: The number of erased elements.
  1431. //!
  1432. //! <b>Complexity</b>: Average case O(this->count(value)).
  1433. //! Worst case O(this->size()).
  1434. //!
  1435. //! <b>Throws</b>: If hash_func or equal_func throw. Basic guarantee.
  1436. //!
  1437. //! <b>Note</b>: Invalidates the iterators
  1438. //! to the erased elements.
  1439. template<class KeyType, class KeyHasher, class KeyValueEqual, class Disposer>
  1440. size_type erase_and_dispose(const KeyType& key, KeyHasher hash_func, KeyValueEqual equal_func, Disposer disposer)
  1441. { return table_type::erase_and_dispose(key, hash_func, equal_func, disposer); }
  1442. //! <b>Effects</b>: Erases all the elements of the container.
  1443. //!
  1444. //! <b>Complexity</b>: Linear to the number of elements on the container.
  1445. //! if it's a safe-mode or auto-unlink value_type. Constant time otherwise.
  1446. //!
  1447. //! <b>Throws</b>: Nothing.
  1448. //!
  1449. //! <b>Note</b>: Invalidates the iterators (but not the references)
  1450. //! to the erased elements. No destructors are called.
  1451. void clear()
  1452. { return table_type::clear(); }
  1453. //! <b>Requires</b>: Disposer::operator()(pointer) shouldn't throw.
  1454. //!
  1455. //! <b>Effects</b>: Erases all the elements of the container.
  1456. //!
  1457. //! <b>Complexity</b>: Linear to the number of elements on the container.
  1458. //! Disposer::operator()(pointer) is called for the removed elements.
  1459. //!
  1460. //! <b>Throws</b>: Nothing.
  1461. //!
  1462. //! <b>Note</b>: Invalidates the iterators (but not the references)
  1463. //! to the erased elements. No destructors are called.
  1464. template<class Disposer>
  1465. void clear_and_dispose(Disposer disposer)
  1466. { return table_type::clear_and_dispose(disposer); }
  1467. //! <b>Effects</b>: Returns the number of contained elements with the given key
  1468. //!
  1469. //! <b>Complexity</b>: Average case O(1), worst case O(this->size()).
  1470. //!
  1471. //! <b>Throws</b>: If the internal hasher or the equality functor throws.
  1472. size_type count(const_reference value) const
  1473. { return table_type::count(value); }
  1474. //! <b>Requires</b>: "hash_func" must be a hash function that induces
  1475. //! the same hash values as the stored hasher. The difference is that
  1476. //! "hash_func" hashes the given key instead of the value_type.
  1477. //!
  1478. //! "key_value_equal" must be a equality function that induces
  1479. //! the same equality as key_equal. The difference is that
  1480. //! "key_value_equal" compares an arbitrary key with the contained values.
  1481. //!
  1482. //! <b>Effects</b>: Returns the number of contained elements with the given key
  1483. //!
  1484. //! <b>Complexity</b>: Average case O(1), worst case O(this->size()).
  1485. //!
  1486. //! <b>Throws</b>: If the internal hasher or the equality functor throws.
  1487. template<class KeyType, class KeyHasher, class KeyValueEqual>
  1488. size_type count(const KeyType& key, KeyHasher hash_func, KeyValueEqual equal_func) const
  1489. { return table_type::count(key, hash_func, equal_func); }
  1490. //! <b>Effects</b>: Finds an iterator to the first element whose value is
  1491. //! "value" or end() if that element does not exist.
  1492. //!
  1493. //! <b>Complexity</b>: Average case O(1), worst case O(this->size()).
  1494. //!
  1495. //! <b>Throws</b>: If the internal hasher or the equality functor throws.
  1496. iterator find(const_reference value)
  1497. { return table_type::find(value); }
  1498. //! <b>Requires</b>: "hash_func" must be a hash function that induces
  1499. //! the same hash values as the stored hasher. The difference is that
  1500. //! "hash_func" hashes the given key instead of the value_type.
  1501. //!
  1502. //! "key_value_equal" must be a equality function that induces
  1503. //! the same equality as key_equal. The difference is that
  1504. //! "key_value_equal" compares an arbitrary key with the contained values.
  1505. //!
  1506. //! <b>Effects</b>: Finds an iterator to the first element whose key is
  1507. //! "key" according to the given hasher and equality functor or end() if
  1508. //! that element does not exist.
  1509. //!
  1510. //! <b>Complexity</b>: Average case O(1), worst case O(this->size()).
  1511. //!
  1512. //! <b>Throws</b>: If the internal hasher or the equality functor throws.
  1513. //!
  1514. //! <b>Note</b>: This function is used when constructing a value_type
  1515. //! is expensive and the value_type can be compared with a cheaper
  1516. //! key type. Usually this key is part of the value_type.
  1517. template<class KeyType, class KeyHasher, class KeyValueEqual>
  1518. iterator find(const KeyType& key, KeyHasher hash_func, KeyValueEqual equal_func)
  1519. { return table_type::find(key, hash_func, equal_func); }
  1520. //! <b>Effects</b>: Finds a const_iterator to the first element whose key is
  1521. //! "key" or end() if that element does not exist.
  1522. //!
  1523. //! <b>Complexity</b>: Average case O(1), worst case O(this->size()).
  1524. //!
  1525. //! <b>Throws</b>: If the internal hasher or the equality functor throws.
  1526. const_iterator find(const_reference value) const
  1527. { return table_type::find(value); }
  1528. //! <b>Requires</b>: "hash_func" must be a hash function that induces
  1529. //! the same hash values as the stored hasher. The difference is that
  1530. //! "hash_func" hashes the given key instead of the value_type.
  1531. //!
  1532. //! "key_value_equal" must be a equality function that induces
  1533. //! the same equality as key_equal. The difference is that
  1534. //! "key_value_equal" compares an arbitrary key with the contained values.
  1535. //!
  1536. //! <b>Effects</b>: Finds an iterator to the first element whose key is
  1537. //! "key" according to the given hasher and equality functor or end() if
  1538. //! that element does not exist.
  1539. //!
  1540. //! <b>Complexity</b>: Average case O(1), worst case O(this->size()).
  1541. //!
  1542. //! <b>Throws</b>: If the internal hasher or the equality functor throws.
  1543. //!
  1544. //! <b>Note</b>: This function is used when constructing a value_type
  1545. //! is expensive and the value_type can be compared with a cheaper
  1546. //! key type. Usually this key is part of the value_type.
  1547. template<class KeyType, class KeyHasher, class KeyValueEqual>
  1548. const_iterator find(const KeyType& key, KeyHasher hash_func, KeyValueEqual equal_func) const
  1549. { return table_type::find(key, hash_func, equal_func); }
  1550. //! <b>Effects</b>: Returns a range containing all elements with values equivalent
  1551. //! to value. Returns std::make_pair(this->end(), this->end()) if no such
  1552. //! elements exist.
  1553. //!
  1554. //! <b>Complexity</b>: Average case O(this->count(value)). Worst case O(this->size()).
  1555. //!
  1556. //! <b>Throws</b>: If the internal hasher or the equality functor throws.
  1557. std::pair<iterator,iterator> equal_range(const_reference value)
  1558. { return table_type::equal_range(value); }
  1559. //! <b>Requires</b>: "hash_func" must be a hash function that induces
  1560. //! the same hash values as the stored hasher. The difference is that
  1561. //! "hash_func" hashes the given key instead of the value_type.
  1562. //!
  1563. //! "key_value_equal" must be a equality function that induces
  1564. //! the same equality as key_equal. The difference is that
  1565. //! "key_value_equal" compares an arbitrary key with the contained values.
  1566. //!
  1567. //! <b>Effects</b>: Returns a range containing all elements with equivalent
  1568. //! keys. Returns std::make_pair(this->end(), this->end()) if no such
  1569. //! elements exist.
  1570. //!
  1571. //! <b>Complexity</b>: Average case O(this->count(key, hash_func, equal_func)).
  1572. //! Worst case O(this->size()).
  1573. //!
  1574. //! <b>Throws</b>: If the internal hasher or the equality functor throws.
  1575. //!
  1576. //! <b>Note</b>: This function is used when constructing a value_type
  1577. //! is expensive and the value_type can be compared with a cheaper
  1578. //! key type. Usually this key is part of the value_type.
  1579. template<class KeyType, class KeyHasher, class KeyValueEqual>
  1580. std::pair<iterator,iterator> equal_range
  1581. (const KeyType& key, KeyHasher hash_func, KeyValueEqual equal_func)
  1582. { return table_type::equal_range(key, hash_func, equal_func); }
  1583. //! <b>Effects</b>: Returns a range containing all elements with values equivalent
  1584. //! to value. Returns std::make_pair(this->end(), this->end()) if no such
  1585. //! elements exist.
  1586. //!
  1587. //! <b>Complexity</b>: Average case O(this->count(value)). Worst case O(this->size()).
  1588. //!
  1589. //! <b>Throws</b>: If the internal hasher or the equality functor throws.
  1590. std::pair<const_iterator, const_iterator>
  1591. equal_range(const_reference value) const
  1592. { return table_type::equal_range(value); }
  1593. //! <b>Requires</b>: "hash_func" must be a hash function that induces
  1594. //! the same hash values as the stored hasher. The difference is that
  1595. //! "hash_func" hashes the given key instead of the value_type.
  1596. //!
  1597. //! "key_value_equal" must be a equality function that induces
  1598. //! the same equality as key_equal. The difference is that
  1599. //! "key_value_equal" compares an arbitrary key with the contained values.
  1600. //!
  1601. //! <b>Effects</b>: Returns a range containing all elements with equivalent
  1602. //! keys. Returns std::make_pair(this->end(), this->end()) if no such
  1603. //! elements exist.
  1604. //!
  1605. //! <b>Complexity</b>: Average case O(this->count(key, hash_func, equal_func)).
  1606. //! Worst case O(this->size()).
  1607. //!
  1608. //! <b>Throws</b>: If the internal hasher or the equality functor throws.
  1609. //!
  1610. //! <b>Note</b>: This function is used when constructing a value_type
  1611. //! is expensive and the value_type can be compared with a cheaper
  1612. //! key type. Usually this key is part of the value_type.
  1613. template<class KeyType, class KeyHasher, class KeyValueEqual>
  1614. std::pair<const_iterator, const_iterator>
  1615. equal_range(const KeyType& key, KeyHasher hash_func, KeyValueEqual equal_func) const
  1616. { return table_type::equal_range(key, hash_func, equal_func); }
  1617. //! <b>Requires</b>: value must be an lvalue and shall be in a unordered_multiset of
  1618. //! appropriate type. Otherwise the behavior is undefined.
  1619. //!
  1620. //! <b>Effects</b>: Returns: a valid iterator belonging to the unordered_multiset
  1621. //! that points to the value
  1622. //!
  1623. //! <b>Complexity</b>: Constant.
  1624. //!
  1625. //! <b>Throws</b>: If the hash function throws.
  1626. iterator iterator_to(reference value)
  1627. { return table_type::iterator_to(value); }
  1628. //! <b>Requires</b>: value must be an lvalue and shall be in a unordered_multiset of
  1629. //! appropriate type. Otherwise the behavior is undefined.
  1630. //!
  1631. //! <b>Effects</b>: Returns: a valid const_iterator belonging to the
  1632. //! unordered_multiset that points to the value
  1633. //!
  1634. //! <b>Complexity</b>: Constant.
  1635. //!
  1636. //! <b>Throws</b>: If the hash function throws.
  1637. const_iterator iterator_to(const_reference value) const
  1638. { return table_type::iterator_to(value); }
  1639. //! <b>Requires</b>: value must be an lvalue and shall be in a unordered_set of
  1640. //! appropriate type. Otherwise the behavior is undefined.
  1641. //!
  1642. //! <b>Effects</b>: Returns: a valid local_iterator belonging to the unordered_set
  1643. //! that points to the value
  1644. //!
  1645. //! <b>Complexity</b>: Constant.
  1646. //!
  1647. //! <b>Throws</b>: Nothing.
  1648. //!
  1649. //! <b>Note</b>: This static function is available only if the <i>value traits</i>
  1650. //! is stateless.
  1651. static local_iterator s_local_iterator_to(reference value)
  1652. { return table_type::s_local_iterator_to(value); }
  1653. //! <b>Requires</b>: value must be an lvalue and shall be in a unordered_set of
  1654. //! appropriate type. Otherwise the behavior is undefined.
  1655. //!
  1656. //! <b>Effects</b>: Returns: a valid const_local_iterator belonging to
  1657. //! the unordered_set that points to the value
  1658. //!
  1659. //! <b>Complexity</b>: Constant.
  1660. //!
  1661. //! <b>Throws</b>: Nothing.
  1662. //!
  1663. //! <b>Note</b>: This static function is available only if the <i>value traits</i>
  1664. //! is stateless.
  1665. static const_local_iterator s_local_iterator_to(const_reference value)
  1666. { return table_type::s_local_iterator_to(value); }
  1667. //! <b>Requires</b>: value must be an lvalue and shall be in a unordered_set of
  1668. //! appropriate type. Otherwise the behavior is undefined.
  1669. //!
  1670. //! <b>Effects</b>: Returns: a valid local_iterator belonging to the unordered_set
  1671. //! that points to the value
  1672. //!
  1673. //! <b>Complexity</b>: Constant.
  1674. //!
  1675. //! <b>Throws</b>: Nothing.
  1676. local_iterator local_iterator_to(reference value)
  1677. { return table_type::local_iterator_to(value); }
  1678. //! <b>Requires</b>: value must be an lvalue and shall be in a unordered_set of
  1679. //! appropriate type. Otherwise the behavior is undefined.
  1680. //!
  1681. //! <b>Effects</b>: Returns: a valid const_local_iterator belonging to
  1682. //! the unordered_set that points to the value
  1683. //!
  1684. //! <b>Complexity</b>: Constant.
  1685. //!
  1686. //! <b>Throws</b>: Nothing.
  1687. const_local_iterator local_iterator_to(const_reference value) const
  1688. { return table_type::local_iterator_to(value); }
  1689. //! <b>Effects</b>: Returns the number of buckets passed in the constructor
  1690. //! or the last rehash function.
  1691. //!
  1692. //! <b>Complexity</b>: Constant.
  1693. //!
  1694. //! <b>Throws</b>: Nothing.
  1695. size_type bucket_count() const
  1696. { return table_type::bucket_count(); }
  1697. //! <b>Requires</b>: n is in the range [0, this->bucket_count()).
  1698. //!
  1699. //! <b>Effects</b>: Returns the number of elements in the nth bucket.
  1700. //!
  1701. //! <b>Complexity</b>: Constant.
  1702. //!
  1703. //! <b>Throws</b>: Nothing.
  1704. size_type bucket_size(size_type n) const
  1705. { return table_type::bucket_size(n); }
  1706. //! <b>Effects</b>: Returns the index of the bucket in which elements
  1707. //! with keys equivalent to k would be found, if any such element existed.
  1708. //!
  1709. //! <b>Complexity</b>: Constant.
  1710. //!
  1711. //! <b>Throws</b>: If the hash functor throws.
  1712. //!
  1713. //! <b>Note</b>: the return value is in the range [0, this->bucket_count()).
  1714. size_type bucket(const value_type& k) const
  1715. { return table_type::bucket(k); }
  1716. //! <b>Requires</b>: "hash_func" must be a hash function that induces
  1717. //! the same hash values as the stored hasher. The difference is that
  1718. //! "hash_func" hashes the given key instead of the value_type.
  1719. //!
  1720. //! <b>Effects</b>: Returns the index of the bucket in which elements
  1721. //! with keys equivalent to k would be found, if any such element existed.
  1722. //!
  1723. //! <b>Complexity</b>: Constant.
  1724. //!
  1725. //! <b>Throws</b>: If the hash functor throws.
  1726. //!
  1727. //! <b>Note</b>: the return value is in the range [0, this->bucket_count()).
  1728. template<class KeyType, class KeyHasher>
  1729. size_type bucket(const KeyType& k, const KeyHasher &hash_func) const
  1730. { return table_type::bucket(k, hash_func); }
  1731. //! <b>Effects</b>: Returns the bucket array pointer passed in the constructor
  1732. //! or the last rehash function.
  1733. //!
  1734. //! <b>Complexity</b>: Constant.
  1735. //!
  1736. //! <b>Throws</b>: Nothing.
  1737. bucket_ptr bucket_pointer() const
  1738. { return table_type::bucket_pointer(); }
  1739. //! <b>Requires</b>: n is in the range [0, this->bucket_count()).
  1740. //!
  1741. //! <b>Effects</b>: Returns a local_iterator pointing to the beginning
  1742. //! of the sequence stored in the bucket n.
  1743. //!
  1744. //! <b>Complexity</b>: Constant.
  1745. //!
  1746. //! <b>Throws</b>: Nothing.
  1747. //!
  1748. //! <b>Note</b>: [this->begin(n), this->end(n)) is a valid range
  1749. //! containing all of the elements in the nth bucket.
  1750. local_iterator begin(size_type n)
  1751. { return table_type::begin(n); }
  1752. //! <b>Requires</b>: n is in the range [0, this->bucket_count()).
  1753. //!
  1754. //! <b>Effects</b>: Returns a const_local_iterator pointing to the beginning
  1755. //! of the sequence stored in the bucket n.
  1756. //!
  1757. //! <b>Complexity</b>: Constant.
  1758. //!
  1759. //! <b>Throws</b>: Nothing.
  1760. //!
  1761. //! <b>Note</b>: [this->begin(n), this->end(n)) is a valid range
  1762. //! containing all of the elements in the nth bucket.
  1763. const_local_iterator begin(size_type n) const
  1764. { return table_type::begin(n); }
  1765. //! <b>Requires</b>: n is in the range [0, this->bucket_count()).
  1766. //!
  1767. //! <b>Effects</b>: Returns a const_local_iterator pointing to the beginning
  1768. //! of the sequence stored in the bucket n.
  1769. //!
  1770. //! <b>Complexity</b>: Constant.
  1771. //!
  1772. //! <b>Throws</b>: Nothing.
  1773. //!
  1774. //! <b>Note</b>: [this->begin(n), this->end(n)) is a valid range
  1775. //! containing all of the elements in the nth bucket.
  1776. const_local_iterator cbegin(size_type n) const
  1777. { return table_type::cbegin(n); }
  1778. //! <b>Requires</b>: n is in the range [0, this->bucket_count()).
  1779. //!
  1780. //! <b>Effects</b>: Returns a local_iterator pointing to the end
  1781. //! of the sequence stored in the bucket n.
  1782. //!
  1783. //! <b>Complexity</b>: Constant.
  1784. //!
  1785. //! <b>Throws</b>: Nothing.
  1786. //!
  1787. //! <b>Note</b>: [this->begin(n), this->end(n)) is a valid range
  1788. //! containing all of the elements in the nth bucket.
  1789. local_iterator end(size_type n)
  1790. { return table_type::end(n); }
  1791. //! <b>Requires</b>: n is in the range [0, this->bucket_count()).
  1792. //!
  1793. //! <b>Effects</b>: Returns a const_local_iterator pointing to the end
  1794. //! of the sequence stored in the bucket n.
  1795. //!
  1796. //! <b>Complexity</b>: Constant.
  1797. //!
  1798. //! <b>Throws</b>: Nothing.
  1799. //!
  1800. //! <b>Note</b>: [this->begin(n), this->end(n)) is a valid range
  1801. //! containing all of the elements in the nth bucket.
  1802. const_local_iterator end(size_type n) const
  1803. { return table_type::end(n); }
  1804. //! <b>Requires</b>: n is in the range [0, this->bucket_count()).
  1805. //!
  1806. //! <b>Effects</b>: Returns a const_local_iterator pointing to the end
  1807. //! of the sequence stored in the bucket n.
  1808. //!
  1809. //! <b>Complexity</b>: Constant.
  1810. //!
  1811. //! <b>Throws</b>: Nothing.
  1812. //!
  1813. //! <b>Note</b>: [this->begin(n), this->end(n)) is a valid range
  1814. //! containing all of the elements in the nth bucket.
  1815. const_local_iterator cend(size_type n) const
  1816. { return table_type::cend(n); }
  1817. //! <b>Requires</b>: new_buckets must be a pointer to a new bucket array
  1818. //! or the same as the old bucket array. new_size is the length of the
  1819. //! the array pointed by new_buckets. If new_buckets == this->bucket_pointer()
  1820. //! n can be bigger or smaller than this->bucket_count().
  1821. //!
  1822. //! <b>Effects</b>: Updates the internal reference with the new bucket erases
  1823. //! the values from the old bucket and inserts then in the new one.
  1824. //!
  1825. //! If store_hash option is true, this method does not use the hash function.
  1826. //!
  1827. //! <b>Complexity</b>: Average case linear in this->size(), worst case quadratic.
  1828. //!
  1829. //! <b>Throws</b>: If the hasher functor throws.
  1830. void rehash(const bucket_traits &new_bucket_traits)
  1831. { table_type::rehash(new_bucket_traits); }
  1832. //! <b>Requires</b>:
  1833. //!
  1834. //! <b>Effects</b>:
  1835. //!
  1836. //! <b>Complexity</b>:
  1837. //!
  1838. //! <b>Throws</b>:
  1839. //!
  1840. //! <b>Note</b>: this method is only available if incremental<true> option is activated.
  1841. bool incremental_rehash(bool grow = true)
  1842. { return table_type::incremental_rehash(grow); }
  1843. //! <b>Note</b>: this method is only available if incremental<true> option is activated.
  1844. bool incremental_rehash(const bucket_traits &new_bucket_traits)
  1845. { return table_type::incremental_rehash(new_bucket_traits); }
  1846. //! <b>Requires</b>:
  1847. //!
  1848. //! <b>Effects</b>:
  1849. //!
  1850. //! <b>Complexity</b>:
  1851. //!
  1852. //! <b>Throws</b>:
  1853. size_type split_count() const
  1854. { return table_type::split_count(); }
  1855. //! <b>Effects</b>: Returns the nearest new bucket count optimized for
  1856. //! the container that is bigger than n. This suggestion can be used
  1857. //! to create bucket arrays with a size that will usually improve
  1858. //! container's performance. If such value does not exist, the
  1859. //! higher possible value is returned.
  1860. //!
  1861. //! <b>Complexity</b>: Amortized constant time.
  1862. //!
  1863. //! <b>Throws</b>: Nothing.
  1864. static size_type suggested_upper_bucket_count(size_type n)
  1865. { return table_type::suggested_upper_bucket_count(n); }
  1866. //! <b>Effects</b>: Returns the nearest new bucket count optimized for
  1867. //! the container that is smaller than n. This suggestion can be used
  1868. //! to create bucket arrays with a size that will usually improve
  1869. //! container's performance. If such value does not exist, the
  1870. //! lower possible value is returned.
  1871. //!
  1872. //! <b>Complexity</b>: Amortized constant time.
  1873. //!
  1874. //! <b>Throws</b>: Nothing.
  1875. static size_type suggested_lower_bucket_count(size_type n)
  1876. { return table_type::suggested_lower_bucket_count(n); }
  1877. #endif // #ifdef BOOST_INTRUSIVE_DOXYGEN_INVOKED
  1878. };
  1879. //! Helper metafunction to define an \c unordered_multiset that yields to the same type when the
  1880. //! same options (either explicitly or implicitly) are used.
  1881. #if defined(BOOST_INTRUSIVE_DOXYGEN_INVOKED) || defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
  1882. template<class T, class ...Options>
  1883. #else
  1884. template<class T, class O1 = void, class O2 = void
  1885. , class O3 = void, class O4 = void
  1886. , class O5 = void, class O6 = void
  1887. , class O7 = void, class O8 = void
  1888. , class O9 = void, class O10= void
  1889. >
  1890. #endif
  1891. struct make_unordered_multiset
  1892. {
  1893. /// @cond
  1894. typedef typename pack_options
  1895. < hashtable_defaults,
  1896. #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
  1897. O1, O2, O3, O4, O5, O6, O7, O8, O9, O10
  1898. #else
  1899. Options...
  1900. #endif
  1901. >::type packed_options;
  1902. typedef typename detail::get_value_traits
  1903. <T, typename packed_options::proto_value_traits>::type value_traits;
  1904. typedef typename make_real_bucket_traits
  1905. <T, true, packed_options>::type real_bucket_traits;
  1906. typedef unordered_multiset_impl
  1907. < value_traits
  1908. , typename packed_options::hash
  1909. , typename packed_options::equal
  1910. , typename packed_options::size_type
  1911. , real_bucket_traits
  1912. , (std::size_t(false)*hash_bool_flags::unique_keys_pos)
  1913. | (std::size_t(packed_options::constant_time_size)*hash_bool_flags::constant_time_size_pos)
  1914. | (std::size_t(packed_options::power_2_buckets)*hash_bool_flags::power_2_buckets_pos)
  1915. | (std::size_t(packed_options::cache_begin)*hash_bool_flags::cache_begin_pos)
  1916. | (std::size_t(packed_options::compare_hash)*hash_bool_flags::compare_hash_pos)
  1917. | (std::size_t(packed_options::incremental)*hash_bool_flags::incremental_pos)
  1918. > implementation_defined;
  1919. /// @endcond
  1920. typedef implementation_defined type;
  1921. };
  1922. #ifndef BOOST_INTRUSIVE_DOXYGEN_INVOKED
  1923. #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
  1924. template<class T, class O1, class O2, class O3, class O4, class O5, class O6, class O7, class O8, class O9, class O10>
  1925. #else
  1926. template<class T, class ...Options>
  1927. #endif
  1928. class unordered_multiset
  1929. : public make_unordered_multiset<T,
  1930. #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
  1931. O1, O2, O3, O4, O5, O6, O7, O8, O9, O10
  1932. #else
  1933. Options...
  1934. #endif
  1935. >::type
  1936. {
  1937. typedef typename make_unordered_multiset
  1938. <T,
  1939. #if !defined(BOOST_INTRUSIVE_VARIADIC_TEMPLATES)
  1940. O1, O2, O3, O4, O5, O6, O7, O8, O9, O10
  1941. #else
  1942. Options...
  1943. #endif
  1944. >::type Base;
  1945. //Assert if passed value traits are compatible with the type
  1946. BOOST_STATIC_ASSERT((detail::is_same<typename Base::value_traits::value_type, T>::value));
  1947. BOOST_MOVABLE_BUT_NOT_COPYABLE(unordered_multiset)
  1948. public:
  1949. typedef typename Base::value_traits value_traits;
  1950. typedef typename Base::bucket_traits bucket_traits;
  1951. typedef typename Base::iterator iterator;
  1952. typedef typename Base::const_iterator const_iterator;
  1953. typedef typename Base::bucket_ptr bucket_ptr;
  1954. typedef typename Base::size_type size_type;
  1955. typedef typename Base::hasher hasher;
  1956. typedef typename Base::key_equal key_equal;
  1957. explicit unordered_multiset( const bucket_traits &b_traits
  1958. , const hasher & hash_func = hasher()
  1959. , const key_equal &equal_func = key_equal()
  1960. , const value_traits &v_traits = value_traits())
  1961. : Base(b_traits, hash_func, equal_func, v_traits)
  1962. {}
  1963. template<class Iterator>
  1964. unordered_multiset( Iterator b
  1965. , Iterator e
  1966. , const bucket_traits &b_traits
  1967. , const hasher & hash_func = hasher()
  1968. , const key_equal &equal_func = key_equal()
  1969. , const value_traits &v_traits = value_traits())
  1970. : Base(b, e, b_traits, hash_func, equal_func, v_traits)
  1971. {}
  1972. unordered_multiset(BOOST_RV_REF(unordered_multiset) x)
  1973. : Base(::boost::move(static_cast<Base&>(x)))
  1974. {}
  1975. unordered_multiset& operator=(BOOST_RV_REF(unordered_multiset) x)
  1976. { return static_cast<unordered_multiset&>(this->Base::operator=(::boost::move(static_cast<Base&>(x)))); }
  1977. };
  1978. #endif
  1979. } //namespace intrusive
  1980. } //namespace boost
  1981. #include <boost/intrusive/detail/config_end.hpp>
  1982. #endif //BOOST_INTRUSIVE_UNORDERED_SET_HPP