libstdc++
container_base_dispatch.hpp
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 // Copyright (C) 2005, 2006, 2009, 2011 Free Software Foundation, Inc.
00004 //
00005 // This file is part of the GNU ISO C++ Library.  This library is free
00006 // software; you can redistribute it and/or modify it under the terms
00007 // of the GNU General Public License as published by the Free Software
00008 // Foundation; either version 3, or (at your option) any later
00009 // version.
00010 
00011 // This library is distributed in the hope that it will be useful, but
00012 // WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // General Public License for more details.
00015 
00016 // Under Section 7 of GPL version 3, you are granted additional
00017 // permissions described in the GCC Runtime Library Exception, version
00018 // 3.1, as published by the Free Software Foundation.
00019 
00020 // You should have received a copy of the GNU General Public License and
00021 // a copy of the GCC Runtime Library Exception along with this program;
00022 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
00023 // <http://www.gnu.org/licenses/>.
00024 
00025 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
00026 
00027 // Permission to use, copy, modify, sell, and distribute this software
00028 // is hereby granted without fee, provided that the above copyright
00029 // notice appears in all copies, and that both that copyright notice
00030 // and this permission notice appear in supporting documentation. None
00031 // of the above authors, nor IBM Haifa Research Laboratories, make any
00032 // representation about the suitability of this software for any
00033 // purpose. It is provided "as is" without express or implied
00034 // warranty.
00035 
00036 /**
00037  * @file container_base_dispatch.hpp
00038  * Contains associative container dispatching.
00039  */
00040 
00041 #ifndef PB_DS_ASSOC_CNTNR_BASE_DS_DISPATCHER_HPP
00042 #define PB_DS_ASSOC_CNTNR_BASE_DS_DISPATCHER_HPP
00043 
00044 #include <ext/typelist.h>
00045 
00046 #define PB_DS_ASSERT_VALID(X)                       \
00047   _GLIBCXX_DEBUG_ONLY(X.assert_valid(__FILE__, __LINE__);)
00048 
00049 #define PB_DS_DEBUG_VERIFY(_Cond)                   \
00050   _GLIBCXX_DEBUG_VERIFY_AT(_Cond,                   \
00051                _M_message(#_Cond" assertion from %1;:%2;")  \
00052                ._M_string(__FILE__)._M_integer(__LINE__)    \
00053                ,__file,__line)
00054 
00055 #define PB_DS_CHECK_KEY_EXISTS(_Key)                    \
00056   _GLIBCXX_DEBUG_ONLY(debug_base::check_key_exists(_Key, __FILE__, __LINE__);)
00057 
00058 #define PB_DS_CHECK_KEY_DOES_NOT_EXIST(_Key)                \
00059   _GLIBCXX_DEBUG_ONLY(debug_base::check_key_does_not_exist(_Key,    \
00060                                __FILE__, __LINE__);)
00061 
00062 #define PB_DS_DATA_TRUE_INDICATOR
00063 #define PB_DS_V2F(X) (X).first
00064 #define PB_DS_V2S(X) (X).second
00065 #define PB_DS_EP2VP(X)& ((X)->m_value)
00066 #include <ext/pb_ds/detail/list_update_map_/lu_map_.hpp>
00067 #include <ext/pb_ds/detail/bin_search_tree_/bin_search_tree_.hpp>
00068 #include <ext/pb_ds/detail/rb_tree_map_/rb_tree_.hpp>
00069 #include <ext/pb_ds/detail/splay_tree_/splay_tree_.hpp>
00070 #include <ext/pb_ds/detail/ov_tree_map_/ov_tree_map_.hpp>
00071 #include <ext/pb_ds/detail/cc_hash_table_map_/cc_ht_map_.hpp>
00072 #include <ext/pb_ds/detail/gp_hash_table_map_/gp_ht_map_.hpp>
00073 #include <ext/pb_ds/detail/pat_trie_/pat_trie_.hpp>
00074 #undef PB_DS_DATA_TRUE_INDICATOR
00075 #undef PB_DS_V2F
00076 #undef PB_DS_V2S
00077 #undef PB_DS_EP2VP
00078 
00079 #define PB_DS_DATA_FALSE_INDICATOR
00080 #define PB_DS_V2F(X) (X)
00081 #define PB_DS_V2S(X) Mapped_Data()
00082 #define PB_DS_EP2VP(X)& ((X)->m_value.first)
00083 #include <ext/pb_ds/detail/list_update_map_/lu_map_.hpp>
00084 #include <ext/pb_ds/detail/bin_search_tree_/bin_search_tree_.hpp>
00085 #include <ext/pb_ds/detail/rb_tree_map_/rb_tree_.hpp>
00086 #include <ext/pb_ds/detail/splay_tree_/splay_tree_.hpp>
00087 #include <ext/pb_ds/detail/ov_tree_map_/ov_tree_map_.hpp>
00088 #include <ext/pb_ds/detail/cc_hash_table_map_/cc_ht_map_.hpp>
00089 #include <ext/pb_ds/detail/gp_hash_table_map_/gp_ht_map_.hpp>
00090 #include <ext/pb_ds/detail/pat_trie_/pat_trie_.hpp>
00091 #undef PB_DS_DATA_FALSE_INDICATOR
00092 #undef PB_DS_V2F
00093 #undef PB_DS_V2S
00094 #undef PB_DS_EP2VP
00095 
00096 #undef PB_DS_CHECK_KEY_DOES_NOT_EXIST
00097 #undef PB_DS_CHECK_KEY_EXISTS
00098 #undef PB_DS_DEBUG_VERIFY
00099 #undef PB_DS_ASSERT_VALID
00100 
00101 namespace __gnu_pbds
00102 {
00103 namespace detail
00104 {
00105   /// Specialization for list-update map.
00106   template<typename Key, typename Mapped, typename _Alloc, typename Policy_Tl>
00107     struct container_base_dispatch<Key, Mapped, _Alloc, list_update_tag,
00108                    Policy_Tl>
00109     {
00110     private:
00111       typedef __gnu_cxx::typelist::at_index<Policy_Tl, 0>   at0;
00112       typedef typename at0::type                    at0t;
00113       typedef __gnu_cxx::typelist::at_index<Policy_Tl, 1>   at1;
00114       typedef typename at1::type                    at1t;
00115 
00116     public:
00117       /// Dispatched type.
00118       typedef lu_map<Key, Mapped, at0t, _Alloc, at1t>   type;
00119     };
00120 
00121   /// Specialization for list-update set.
00122   template<typename Key, typename _Alloc, typename Policy_Tl>
00123     struct container_base_dispatch<Key, null_type, _Alloc, list_update_tag,
00124                    Policy_Tl>
00125     {
00126     private:
00127       typedef __gnu_cxx::typelist::at_index<Policy_Tl, 0>   at0;
00128       typedef typename at0::type                    at0t;
00129       typedef __gnu_cxx::typelist::at_index<Policy_Tl, 1>   at1;
00130       typedef typename at1::type                    at1t;
00131 
00132     public:
00133       /// Dispatched type.
00134       typedef lu_set<Key, null_type, at0t, _Alloc, at1t> type;
00135     };
00136 
00137   /// Specialization for PATRICIA trie map.
00138   template<typename Key, typename Mapped, typename _Alloc, typename Policy_Tl>
00139   struct container_base_dispatch<Key, Mapped, _Alloc, pat_trie_tag, Policy_Tl>
00140     {
00141     private:
00142       typedef __gnu_cxx::typelist::at_index<Policy_Tl, 1>   at1;
00143       typedef typename at1::type                    at1t;
00144 
00145     public:
00146       typedef pat_trie_map<Key, Mapped, at1t, _Alloc>       type;
00147     };
00148 
00149   /// Specialization for PATRICIA trie set.
00150   template<typename Key, typename _Alloc, typename Policy_Tl>
00151     struct container_base_dispatch<Key, null_type, _Alloc, pat_trie_tag,
00152                    Policy_Tl>
00153     {
00154     private:
00155       typedef __gnu_cxx::typelist::at_index<Policy_Tl, 1>   at1;
00156       typedef typename at1::type                    at1t;
00157 
00158     public:
00159       /// Dispatched type.
00160       typedef pat_trie_set<Key, null_type, at1t, _Alloc> type;
00161     };
00162 
00163   /// Specialization for R-B tree map.
00164   template<typename Key, typename Mapped, typename _Alloc, typename Policy_Tl>
00165     struct container_base_dispatch<Key, Mapped, _Alloc, rb_tree_tag, Policy_Tl>
00166     {
00167     private:
00168       typedef __gnu_cxx::typelist::at_index<Policy_Tl, 0>   at0;
00169       typedef typename at0::type                    at0t;
00170       typedef __gnu_cxx::typelist::at_index<Policy_Tl, 1>   at1;
00171       typedef typename at1::type                    at1t;
00172 
00173     public:
00174       /// Dispatched type.
00175       typedef rb_tree_map<Key, Mapped, at0t, at1t, _Alloc>  type;
00176     };
00177 
00178   /// Specialization for R-B tree set.
00179   template<typename Key, typename _Alloc, typename Policy_Tl>
00180     struct container_base_dispatch<Key, null_type, _Alloc, rb_tree_tag,
00181                    Policy_Tl>
00182     {
00183     private:
00184       typedef __gnu_cxx::typelist::at_index<Policy_Tl, 0>   at0;
00185       typedef typename at0::type                    at0t;
00186       typedef __gnu_cxx::typelist::at_index<Policy_Tl, 1>   at1;
00187       typedef typename at1::type                    at1t;
00188 
00189     public:
00190       typedef rb_tree_set<Key, null_type, at0t, at1t, _Alloc> type;
00191     };
00192 
00193   /// Specialization splay tree map.
00194   template<typename Key, typename Mapped, typename _Alloc, typename Policy_Tl>
00195   struct container_base_dispatch<Key, Mapped, _Alloc, splay_tree_tag,
00196                    Policy_Tl>
00197     {
00198     private:
00199       typedef __gnu_cxx::typelist::at_index<Policy_Tl, 0>   at0;
00200       typedef typename at0::type                    at0t;
00201       typedef __gnu_cxx::typelist::at_index<Policy_Tl, 1>   at1;
00202       typedef typename at1::type                    at1t;
00203 
00204     public:
00205       /// Dispatched type.
00206       typedef splay_tree_map<Key, Mapped, at0t, at1t, _Alloc>   type;
00207     };
00208 
00209   /// Specialization splay tree set.
00210   template<typename Key, typename _Alloc, typename Policy_Tl>
00211     struct container_base_dispatch<Key, null_type, _Alloc, splay_tree_tag,
00212                    Policy_Tl>
00213     {
00214     private:
00215       typedef __gnu_cxx::typelist::at_index<Policy_Tl, 0>   at0;
00216       typedef typename at0::type                    at0t;
00217       typedef __gnu_cxx::typelist::at_index<Policy_Tl, 1>   at1;
00218       typedef typename at1::type                    at1t;
00219 
00220     public:
00221       /// Dispatched type.
00222       typedef splay_tree_set<Key, null_type, at0t, at1t, _Alloc> type;
00223   };
00224 
00225     /// Specialization ordered-vector tree map.
00226   template<typename Key, typename Mapped, typename _Alloc, typename Policy_Tl>
00227     struct container_base_dispatch<Key, Mapped, _Alloc, ov_tree_tag, Policy_Tl>
00228     {
00229     private:
00230       typedef __gnu_cxx::typelist::at_index<Policy_Tl, 0>   at0;
00231       typedef typename at0::type                    at0t;
00232       typedef __gnu_cxx::typelist::at_index<Policy_Tl, 1>   at1;
00233       typedef typename at1::type                    at1t;
00234 
00235     public:
00236       /// Dispatched type.
00237       typedef ov_tree_map<Key, Mapped, at0t, at1t, _Alloc>  type;
00238   };
00239 
00240     /// Specialization ordered-vector tree set.
00241   template<typename Key, typename _Alloc, typename Policy_Tl>
00242     struct container_base_dispatch<Key, null_type, _Alloc, ov_tree_tag,
00243                    Policy_Tl>
00244     {
00245     private:
00246       typedef __gnu_cxx::typelist::at_index<Policy_Tl, 0>   at0;
00247       typedef typename at0::type                    at0t;
00248       typedef __gnu_cxx::typelist::at_index<Policy_Tl, 1>   at1;
00249       typedef typename at1::type                    at1t;
00250 
00251     public:
00252       /// Dispatched type.
00253       typedef ov_tree_set<Key, null_type, at0t, at1t, _Alloc> type;
00254   };
00255 
00256     /// Specialization colision-chaining hash map.
00257   template<typename Key, typename Mapped, typename _Alloc, typename Policy_Tl>
00258     struct container_base_dispatch<Key, Mapped, _Alloc, cc_hash_tag, Policy_Tl>
00259     {
00260     private:
00261       typedef __gnu_cxx::typelist::at_index<Policy_Tl, 0>   at0;
00262       typedef typename at0::type                    at0t;
00263       typedef __gnu_cxx::typelist::at_index<Policy_Tl, 1>   at1;
00264       typedef typename at1::type                    at1t;
00265       typedef __gnu_cxx::typelist::at_index<Policy_Tl, 2>   at2;
00266       typedef typename at2::type                    at2t;
00267       typedef __gnu_cxx::typelist::at_index<Policy_Tl, 3>   at3;
00268       typedef typename at3::type                at3t;
00269       typedef __gnu_cxx::typelist::at_index<Policy_Tl, 4>   at4;
00270       typedef typename at4::type                    at4t;
00271 
00272     public:
00273       /// Dispatched type.
00274       typedef cc_ht_map<Key, Mapped, at0t, at1t, _Alloc, 
00275             at3t::value, at4t, at2t>            type;
00276   };
00277 
00278     /// Specialization colision-chaining hash set.
00279   template<typename Key, typename _Alloc, typename Policy_Tl>
00280     struct container_base_dispatch<Key, null_type, _Alloc, cc_hash_tag,
00281                    Policy_Tl>
00282     {
00283     private:
00284       typedef __gnu_cxx::typelist::at_index<Policy_Tl, 0>   at0;
00285       typedef typename at0::type                    at0t;
00286       typedef __gnu_cxx::typelist::at_index<Policy_Tl, 1>   at1;
00287       typedef typename at1::type                    at1t;
00288       typedef __gnu_cxx::typelist::at_index<Policy_Tl, 2>   at2;
00289       typedef typename at2::type                    at2t;
00290       typedef __gnu_cxx::typelist::at_index<Policy_Tl, 3>   at3;
00291       typedef typename at3::type                at3t;
00292       typedef __gnu_cxx::typelist::at_index<Policy_Tl, 4>   at4;
00293       typedef typename at4::type                    at4t;
00294 
00295     public:
00296       /// Dispatched type.
00297       typedef cc_ht_set<Key, null_type, at0t, at1t, _Alloc,
00298                  at3t::value, at4t, at2t>       type;
00299   };
00300 
00301     /// Specialization general-probe hash map.
00302   template<typename Key, typename Mapped, typename _Alloc, typename Policy_Tl>
00303     struct container_base_dispatch<Key, Mapped, _Alloc, gp_hash_tag, Policy_Tl>
00304     {
00305     private:
00306       typedef __gnu_cxx::typelist::at_index<Policy_Tl, 0>   at0;
00307       typedef typename at0::type                    at0t;
00308       typedef __gnu_cxx::typelist::at_index<Policy_Tl, 1>   at1;
00309       typedef typename at1::type                    at1t;
00310       typedef __gnu_cxx::typelist::at_index<Policy_Tl, 2>   at2;
00311       typedef typename at2::type                    at2t;
00312       typedef __gnu_cxx::typelist::at_index<Policy_Tl, 3>   at3;
00313       typedef typename at3::type                at3t;
00314       typedef __gnu_cxx::typelist::at_index<Policy_Tl, 4>   at4;
00315       typedef typename at4::type                    at4t;
00316       typedef __gnu_cxx::typelist::at_index<Policy_Tl, 5>   at5;
00317       typedef typename at5::type                    at5t;
00318 
00319     public:
00320       /// Dispatched type.
00321       typedef gp_ht_map<Key, Mapped, at0t, at1t, _Alloc, 
00322             at3t::value, at4t, at5t, at2t>      type;
00323   };
00324 
00325     /// Specialization general-probe hash set.
00326   template<typename Key, typename _Alloc, typename Policy_Tl>
00327     struct container_base_dispatch<Key, null_type, _Alloc, gp_hash_tag,
00328                    Policy_Tl>
00329     {
00330     private:
00331       typedef __gnu_cxx::typelist::at_index<Policy_Tl, 0>   at0;
00332       typedef typename at0::type                    at0t;
00333       typedef __gnu_cxx::typelist::at_index<Policy_Tl, 1>   at1;
00334       typedef typename at1::type                    at1t;
00335       typedef __gnu_cxx::typelist::at_index<Policy_Tl, 2>   at2;
00336       typedef typename at2::type                    at2t;
00337       typedef __gnu_cxx::typelist::at_index<Policy_Tl, 3>   at3;
00338       typedef typename at3::type                at3t;
00339       typedef __gnu_cxx::typelist::at_index<Policy_Tl, 4>   at4;
00340       typedef typename at4::type                    at4t;
00341       typedef __gnu_cxx::typelist::at_index<Policy_Tl, 5>   at5;
00342       typedef typename at5::type                    at5t;
00343 
00344     public:
00345       /// Dispatched type.
00346       typedef gp_ht_set<Key, null_type, at0t, at1t, _Alloc,
00347             at3t::value, at4t, at5t, at2t>      type;
00348   };
00349 } // namespace detail
00350 } // namespace __gnu_pbds
00351 
00352 #endif