00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #ifndef PB_DS_ASSOC_CNTNR_HPP
00042 #define PB_DS_ASSOC_CNTNR_HPP
00043
00044 #include <ext/typelist.h>
00045 #include <ext/pb_ds/tag_and_trait.hpp>
00046 #include <ext/pb_ds/detail/standard_policies.hpp>
00047 #include <ext/pb_ds/detail/container_base_dispatch.hpp>
00048 #include <ext/pb_ds/detail/basic_tree_policy/traits.hpp>
00049
00050 namespace __gnu_pbds
00051 {
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067 #define PB_DS_BASE_C_DEC \
00068 detail::container_base_dispatch<Key, Mapped, Tag, Policy_Tl, Allocator>::type
00069
00070
00071 template<typename Key,
00072 typename Mapped,
00073 typename Tag,
00074 typename Policy_Tl,
00075 typename Allocator>
00076 class container_base : public PB_DS_BASE_C_DEC
00077 {
00078 private:
00079 typedef typename PB_DS_BASE_C_DEC base_type;
00080
00081 public:
00082 typedef Tag container_category;
00083 typedef Allocator allocator_type;
00084 typedef typename allocator_type::size_type size_type;
00085 typedef typename allocator_type::difference_type difference_type;
00086
00087
00088 typedef typename allocator_type::template rebind<Key>::other::value_type key_type;
00089 typedef typename allocator_type::template rebind<key_type>::other key_rebind;
00090 typedef typename key_rebind::reference key_reference;
00091 typedef typename key_rebind::const_reference const_key_reference;
00092 typedef typename key_rebind::pointer key_pointer;
00093 typedef typename key_rebind::const_pointer const_key_pointer;
00094
00095
00096 typedef Mapped mapped_type;
00097 typedef typename allocator_type::template rebind<mapped_type>::other mapped_rebind;
00098 typedef typename mapped_rebind::reference mapped_reference;
00099 typedef typename mapped_rebind::const_reference const_mapped_reference;
00100 typedef typename mapped_rebind::pointer mapped_pointer;
00101 typedef typename mapped_rebind::const_pointer const_mapped_pointer;
00102
00103
00104 typedef typename base_type::value_type value_type;
00105 typedef typename allocator_type::template rebind<value_type>::other value_rebind;
00106 typedef typename value_rebind::reference reference;
00107 typedef typename value_rebind::const_reference const_reference;
00108 typedef typename value_rebind::pointer pointer;
00109 typedef typename value_rebind::const_pointer const_pointer;
00110
00111
00112 typedef typename base_type::iterator iterator;
00113 typedef typename base_type::const_iterator const_iterator;
00114 typedef typename base_type::point_iterator point_iterator;
00115 typedef typename base_type::const_point_iterator const_point_iterator;
00116
00117 virtual
00118 ~container_base() { }
00119
00120 protected:
00121 #define PB_DS_CLASS_NAME container_base
00122 #include <ext/pb_ds/detail/constructors_destructor_fn_imps.hpp>
00123 #undef PB_DS_CLASS_NAME
00124 };
00125
00126 #undef PB_DS_BASE_C_DEC
00127
00128
00129 #define PB_DS_BASE_C_DEC \
00130 container_base<Key, Mapped, Tag, typename __gnu_cxx::typelist::append< \
00131 typename __gnu_cxx::typelist::create4<Hash_Fn, Eq_Fn, Resize_Policy, detail::integral_constant<int, Store_Hash> >::type, Policy_TL>::type, Allocator>
00132
00133
00134 template<typename Key,
00135 typename Mapped,
00136 typename Hash_Fn,
00137 typename Eq_Fn,
00138 typename Resize_Policy,
00139 bool Store_Hash,
00140 typename Tag,
00141 typename Policy_TL,
00142 typename Allocator>
00143 class basic_hash_table : public PB_DS_BASE_C_DEC
00144 {
00145 private:
00146 typedef PB_DS_BASE_C_DEC base_type;
00147
00148 public:
00149 virtual
00150 ~basic_hash_table() { }
00151
00152 protected:
00153 #define PB_DS_CLASS_NAME basic_hash_table
00154 #include <ext/pb_ds/detail/constructors_destructor_fn_imps.hpp>
00155 #undef PB_DS_CLASS_NAME
00156
00157 private:
00158 basic_hash_table&
00159 operator=(const base_type&);
00160 };
00161
00162 #undef PB_DS_BASE_C_DEC
00163
00164
00165 #define PB_DS_BASE_C_DEC \
00166 basic_hash_table<Key, Mapped, Hash_Fn, Eq_Fn, Resize_Policy, Store_Hash, \
00167 cc_hash_tag, \
00168 typename __gnu_cxx::typelist::create1<Comb_Hash_Fn>::type, Allocator>
00169
00170
00171 template<typename Key,
00172 typename Mapped,
00173 typename Hash_Fn = typename detail::default_hash_fn<Key>::type,
00174 typename Eq_Fn = typename detail::default_eq_fn<Key>::type,
00175 typename Comb_Hash_Fn = detail::default_comb_hash_fn::type,
00176 typename Resize_Policy = typename detail::default_resize_policy<Comb_Hash_Fn>::type,
00177 bool Store_Hash = detail::default_store_hash,
00178 typename Allocator = std::allocator<char> >
00179 class cc_hash_table : public PB_DS_BASE_C_DEC
00180 {
00181 private:
00182 typedef PB_DS_BASE_C_DEC base_type;
00183
00184 public:
00185 typedef Hash_Fn hash_fn;
00186 typedef Eq_Fn eq_fn;
00187 typedef Resize_Policy resize_policy;
00188 typedef Comb_Hash_Fn comb_hash_fn;
00189
00190
00191 cc_hash_table() { }
00192
00193
00194
00195 cc_hash_table(const hash_fn& h)
00196 : base_type(h) { }
00197
00198
00199
00200
00201
00202 cc_hash_table(const hash_fn& h, const eq_fn& e)
00203 : base_type(h, e) { }
00204
00205
00206
00207
00208
00209
00210 cc_hash_table(const hash_fn& h, const eq_fn& e, const comb_hash_fn& ch)
00211 : base_type(h, e, ch) { }
00212
00213
00214
00215
00216
00217
00218
00219 cc_hash_table(const hash_fn& h, const eq_fn& e, const comb_hash_fn& ch,
00220 const resize_policy& rp)
00221 : base_type(h, e, ch, rp) { }
00222
00223
00224
00225
00226 template<typename It>
00227 cc_hash_table(It first, It last)
00228 { base_type::copy_from_range(first, last); }
00229
00230
00231
00232
00233 template<typename It>
00234 cc_hash_table(It first, It last, const hash_fn& h)
00235 : base_type(h)
00236 { copy_from_range(first, last); }
00237
00238
00239
00240
00241
00242
00243
00244 template<typename It>
00245 cc_hash_table(It first, It last, const hash_fn& h, const eq_fn& e)
00246 : base_type(h, e)
00247 { copy_from_range(first, last); }
00248
00249
00250
00251
00252
00253
00254
00255
00256 template<typename It>
00257 cc_hash_table(It first, It last, const hash_fn& h, const eq_fn& e,
00258 const comb_hash_fn& ch)
00259 : base_type(h, e, ch)
00260 { copy_from_range(first, last); }
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270 template<typename It>
00271 cc_hash_table(It first, It last, const hash_fn& h, const eq_fn& e,
00272 const comb_hash_fn& ch, const resize_policy& rp)
00273 : base_type(h, e, ch, rp)
00274 { copy_from_range(first, last); }
00275
00276 cc_hash_table(const cc_hash_table& other)
00277 : base_type((const base_type&)other)
00278 { }
00279
00280 virtual
00281 ~cc_hash_table() { }
00282
00283 cc_hash_table&
00284 operator=(const cc_hash_table& other)
00285 {
00286 if (this != &other)
00287 {
00288 cc_hash_table tmp(other);
00289 swap(tmp);
00290 }
00291 return *this;
00292 }
00293
00294 void
00295 swap(cc_hash_table& other)
00296 { base_type::swap(other); }
00297 };
00298
00299 #undef PB_DS_BASE_C_DEC
00300
00301
00302 #define PB_DS_BASE_C_DEC \
00303 basic_hash_table<Key, Mapped, Hash_Fn, Eq_Fn, Resize_Policy, Store_Hash, \
00304 gp_hash_tag, \
00305 typename __gnu_cxx::typelist::create2<Comb_Probe_Fn, Probe_Fn>::type, Allocator>
00306
00307
00308 template<typename Key,
00309 typename Mapped,
00310 typename Hash_Fn = typename detail::default_hash_fn<Key>::type,
00311 typename Eq_Fn = typename detail::default_eq_fn<Key>::type,
00312 typename Comb_Probe_Fn = detail::default_comb_hash_fn::type,
00313 typename Probe_Fn = typename detail::default_probe_fn<Comb_Probe_Fn>::type,
00314 typename Resize_Policy = typename detail::default_resize_policy<Comb_Probe_Fn>::type,
00315 bool Store_Hash = detail::default_store_hash,
00316 typename Allocator = std::allocator<char> >
00317 class gp_hash_table : public PB_DS_BASE_C_DEC
00318 {
00319 private:
00320 typedef PB_DS_BASE_C_DEC base_type;
00321
00322 public:
00323 typedef Hash_Fn hash_fn;
00324 typedef Eq_Fn eq_fn;
00325 typedef Comb_Probe_Fn comb_probe_fn;
00326 typedef Probe_Fn probe_fn;
00327 typedef Resize_Policy resize_policy;
00328
00329
00330 gp_hash_table() { }
00331
00332
00333
00334 gp_hash_table(const hash_fn& h)
00335 : base_type(h) { }
00336
00337
00338
00339
00340
00341 gp_hash_table(const hash_fn& h, const eq_fn& e)
00342 : base_type(h, e) { }
00343
00344
00345
00346
00347
00348
00349 gp_hash_table(const hash_fn& h, const eq_fn& e, const comb_probe_fn& cp)
00350 : base_type(h, e, cp) { }
00351
00352
00353
00354
00355
00356
00357
00358 gp_hash_table(const hash_fn& h, const eq_fn& e, const comb_probe_fn& cp,
00359 const probe_fn& p)
00360 : base_type(h, e, cp, p) { }
00361
00362
00363
00364
00365
00366
00367
00368
00369 gp_hash_table(const hash_fn& h, const eq_fn& e, const comb_probe_fn& cp,
00370 const probe_fn& p, const resize_policy& rp)
00371 : base_type(h, e, cp, p, rp) { }
00372
00373
00374
00375
00376 template<typename It>
00377 gp_hash_table(It first, It last)
00378 { base_type::copy_from_range(first, last); }
00379
00380
00381
00382
00383
00384 template<typename It>
00385 gp_hash_table(It first, It last, const hash_fn& h)
00386 : base_type(h)
00387 { base_type::copy_from_range(first, last); }
00388
00389
00390
00391
00392
00393
00394
00395 template<typename It>
00396 gp_hash_table(It first, It last, const hash_fn& h, const eq_fn& e)
00397 : base_type(h, e)
00398 { base_type::copy_from_range(first, last); }
00399
00400
00401
00402
00403
00404
00405
00406
00407 template<typename It>
00408 gp_hash_table(It first, It last, const hash_fn& h, const eq_fn& e,
00409 const comb_probe_fn& cp)
00410 : base_type(h, e, cp)
00411 { base_type::copy_from_range(first, last); }
00412
00413
00414
00415
00416
00417
00418
00419
00420
00421 template<typename It>
00422 gp_hash_table(It first, It last, const hash_fn& h, const eq_fn& e,
00423 const comb_probe_fn& cp, const probe_fn& p)
00424 : base_type(h, e, cp, p)
00425 { base_type::copy_from_range(first, last); }
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437 template<typename It>
00438 gp_hash_table(It first, It last, const hash_fn& h, const eq_fn& e,
00439 const comb_probe_fn& cp, const probe_fn& p,
00440 const resize_policy& rp)
00441 : base_type(h, e, cp, p, rp)
00442 { base_type::copy_from_range(first, last); }
00443
00444 gp_hash_table(const gp_hash_table& other)
00445 : base_type((const base_type&)other)
00446 { }
00447
00448 virtual
00449 ~gp_hash_table() { }
00450
00451 gp_hash_table&
00452 operator=(const gp_hash_table& other)
00453 {
00454 if (this != &other)
00455 {
00456 gp_hash_table tmp(other);
00457 swap(tmp);
00458 }
00459 return *this;
00460 }
00461
00462 void
00463 swap(gp_hash_table& other)
00464 { base_type::swap(other); }
00465 };
00466
00467 #undef PB_DS_BASE_C_DEC
00468
00469
00470 #define PB_DS_BASE_C_DEC \
00471 container_base<Key, Mapped, Tag, Policy_Tl, Allocator>
00472
00473
00474 template<typename Key, typename Mapped, typename Tag,
00475 typename Node_Update, typename Policy_Tl, typename Allocator>
00476 class basic_tree : public PB_DS_BASE_C_DEC
00477 {
00478 private:
00479 typedef PB_DS_BASE_C_DEC base_type;
00480
00481 public:
00482 typedef Node_Update node_update;
00483
00484 virtual
00485 ~basic_tree() { }
00486
00487 protected:
00488 #define PB_DS_CLASS_NAME basic_tree
00489 #include <ext/pb_ds/detail/constructors_destructor_fn_imps.hpp>
00490 #undef PB_DS_CLASS_NAME
00491 };
00492
00493 #undef PB_DS_BASE_C_DEC
00494
00495
00496 #define PB_DS_TREE_NODE_AND_IT_TRAITS_C_DEC \
00497 detail::tree_traits<Key, Mapped,Cmp_Fn,Node_Update,Tag, Allocator>
00498
00499 #define PB_DS_BASE_C_DEC \
00500 basic_tree<Key,Mapped,Tag,typename PB_DS_TREE_NODE_AND_IT_TRAITS_C_DEC::node_update, \
00501 typename __gnu_cxx::typelist::create2<Cmp_Fn, PB_DS_TREE_NODE_AND_IT_TRAITS_C_DEC >::type, Allocator>
00502
00503
00504 template<typename Key, typename Mapped, typename Cmp_Fn = std::less<Key>,
00505 typename Tag = rb_tree_tag,
00506 template<typename Const_Node_Iterator, typename Node_Iterator, typename Cmp_Fn_, typename Allocator_>
00507 class Node_Update = __gnu_pbds::null_tree_node_update,
00508 typename Allocator = std::allocator<char> >
00509 class tree : public PB_DS_BASE_C_DEC
00510 {
00511 private:
00512 typedef PB_DS_BASE_C_DEC base_type;
00513
00514 public:
00515
00516 typedef Cmp_Fn cmp_fn;
00517
00518 tree() { }
00519
00520
00521
00522 tree(const cmp_fn& c)
00523 : base_type(c) { }
00524
00525
00526
00527
00528 template<typename It>
00529 tree(It first, It last)
00530 { base_type::copy_from_range(first, last); }
00531
00532
00533
00534
00535
00536 template<typename It>
00537 tree(It first, It last, const cmp_fn& c)
00538 : base_type(c)
00539 { base_type::copy_from_range(first, last); }
00540
00541 tree(const tree& other)
00542 : base_type((const base_type&)other) { }
00543
00544 virtual
00545 ~tree() { }
00546
00547 tree&
00548 operator=(const tree& other)
00549 {
00550 if (this != &other)
00551 {
00552 tree tmp(other);
00553 swap(tmp);
00554 }
00555 return *this;
00556 }
00557
00558 void
00559 swap(tree& other)
00560 { base_type::swap(other); }
00561 };
00562
00563 #undef PB_DS_BASE_C_DEC
00564 #undef PB_DS_TREE_NODE_AND_IT_TRAITS_C_DEC
00565
00566
00567 #define PB_DS_TRIE_NODE_AND_ITS_TRAITS \
00568 detail::trie_traits<Key,Mapped,E_Access_Traits,Node_Update,Tag,Allocator>
00569
00570 #define PB_DS_BASE_C_DEC \
00571 basic_tree<Key,Mapped,Tag, typename PB_DS_TRIE_NODE_AND_ITS_TRAITS::node_update, \
00572 typename __gnu_cxx::typelist::create2<E_Access_Traits, PB_DS_TRIE_NODE_AND_ITS_TRAITS >::type, Allocator>
00573
00574
00575 template<typename Key,
00576 typename Mapped,
00577 typename E_Access_Traits = typename detail::default_trie_e_access_traits<Key>::type,
00578 typename Tag = pat_trie_tag,
00579 template<typename Const_Node_Iterator,
00580 typename Node_Iterator,
00581 typename E_Access_Traits_,
00582 typename Allocator_>
00583 class Node_Update = null_trie_node_update,
00584 typename Allocator = std::allocator<char> >
00585 class trie : public PB_DS_BASE_C_DEC
00586 {
00587 private:
00588 typedef PB_DS_BASE_C_DEC base_type;
00589
00590 public:
00591
00592 typedef E_Access_Traits e_access_traits;
00593
00594 trie() { }
00595
00596
00597
00598
00599 trie(const e_access_traits& t)
00600 : base_type(t) { }
00601
00602
00603
00604
00605 template<typename It>
00606 trie(It first, It last)
00607 { base_type::copy_from_range(first, last); }
00608
00609
00610
00611
00612 template<typename It>
00613 trie(It first, It last, const e_access_traits& t)
00614 : base_type(t)
00615 { base_type::copy_from_range(first, last); }
00616
00617 trie(const trie& other)
00618 : base_type((const base_type&)other) { }
00619
00620 virtual
00621 ~trie() { }
00622
00623 trie&
00624 operator=(const trie& other)
00625 {
00626 if (this != &other)
00627 {
00628 trie tmp(other);
00629 swap(tmp);
00630 }
00631 return *this;
00632 }
00633
00634 void
00635 swap(trie& other)
00636 { base_type::swap(other); }
00637 };
00638
00639 #undef PB_DS_BASE_C_DEC
00640 #undef PB_DS_TRIE_NODE_AND_ITS_TRAITS
00641
00642
00643 #define PB_DS_BASE_C_DEC \
00644 container_base<Key, Mapped, list_update_tag, \
00645 typename __gnu_cxx::typelist::create2<Eq_Fn, Update_Policy>::type, Allocator>
00646
00647
00648 template<typename Key,
00649 typename Mapped,
00650 class Eq_Fn = typename detail::default_eq_fn<Key>::type,
00651 class Update_Policy = detail::default_update_policy::type,
00652 class Allocator = std::allocator<char> >
00653 class list_update : public PB_DS_BASE_C_DEC
00654 {
00655 private:
00656 typedef PB_DS_BASE_C_DEC base_type;
00657
00658 public:
00659 typedef Eq_Fn eq_fn;
00660 typedef Update_Policy update_policy;
00661 typedef Allocator allocator;
00662
00663 list_update() { }
00664
00665
00666
00667
00668 template<typename It>
00669 list_update(It first, It last)
00670 { base_type::copy_from_range(first, last); }
00671
00672 list_update(const list_update& other)
00673 : base_type((const base_type&)other) { }
00674
00675 virtual
00676 ~list_update() { }
00677
00678 list_update&
00679 operator=(const list_update& other)
00680 {
00681 if (this !=& other)
00682 {
00683 list_update tmp(other);
00684 swap(tmp);
00685 }
00686 return *this;
00687 }
00688
00689 void
00690 swap(list_update& other)
00691 { base_type::swap(other); }
00692 };
00693
00694 #undef PB_DS_BASE_C_DEC
00695
00696
00697 }
00698
00699 #endif