stx/btree_multimap.h

Go to the documentation of this file.
00001 // $Id: btree_multimap.h 35 2007-04-27 11:26:33Z tb $
00006 /*
00007  * STX B+ Tree Template Classes v0.7
00008  * Copyright (C) 2007 Timo Bingmann
00009  *
00010  * This library is free software; you can redistribute it and/or modify it
00011  * under the terms of the GNU Lesser General Public License as published by the
00012  * Free Software Foundation; either version 2.1 of the License, or (at your
00013  * option) any later version.
00014  *
00015  * This library is distributed in the hope that it will be useful, but WITHOUT
00016  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00017  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
00018  * for more details.
00019  *
00020  * You should have received a copy of the GNU Lesser General Public License
00021  * along with this library; if not, write to the Free Software Foundation,
00022  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00023  */
00024 
00025 #ifndef _STX_BTREE_MULTIMAP_H_
00026 #define _STX_BTREE_MULTIMAP_H_
00027 
00028 #include <stx/btree.h>
00029 
00030 namespace stx {
00031 
00046 template <typename _Key, typename _Data,
00047           typename _Compare = std::less<_Key>,
00048           typename _Traits = btree_default_map_traits<_Key, _Data> >
00049 class btree_multimap
00050 {
00051 public:
00052     // *** Template Parameter Types
00053 
00056     typedef _Key                        key_type;
00057 
00060     typedef _Data                       data_type;
00061 
00063     typedef _Compare                    key_compare;
00064 
00067     typedef _Traits                     traits;
00068 
00069 public:
00070     // *** Constructed Types
00071 
00073     typedef btree_multimap<key_type, data_type, key_compare, traits>    self;
00074 
00077     typedef std::pair<key_type, data_type>      value_type;
00078 
00080     typedef stx::btree<key_type, data_type, value_type, key_compare, traits, true> btree_impl;
00081 
00083     typedef typename btree_impl::value_compare  value_compare;
00084 
00086     typedef typename btree_impl::size_type      size_type;
00087 
00089     typedef typename btree_impl::tree_stats     tree_stats;
00090 
00091 public:
00092     // *** Static Constant Options and Values of the B+ Tree
00093 
00095     static const unsigned short         leafslotmax =  btree_impl::leafslotmax;
00096 
00099     static const unsigned short         innerslotmax =  btree_impl::innerslotmax;
00100 
00104     static const unsigned short         minleafslots = btree_impl::minleafslots;
00105 
00109     static const unsigned short         mininnerslots = btree_impl::mininnerslots;
00110 
00113     static const bool                   selfverify = btree_impl::selfverify;
00114 
00118     static const bool                   debug = btree_impl::debug;
00119 
00121     static const bool                   allow_duplicates = btree_impl::allow_duplicates;
00122 
00123 public:
00124     // *** Iterators and Reverse Iterators
00125 
00128     typedef typename btree_impl::iterator               iterator;
00129 
00132     typedef typename btree_impl::const_iterator         const_iterator;
00133 
00135     typedef typename btree_impl::reverse_iterator       reverse_iterator;
00136 
00138     typedef typename btree_impl::const_reverse_iterator const_reverse_iterator;
00139 
00140 private:
00141     // *** Tree Implementation Object
00142 
00144     btree_impl  tree;
00145 
00146 public:
00147     // *** Constructors and Destructor
00148 
00151     inline btree_multimap()
00152         : tree()
00153     {
00154     }
00155 
00158     inline btree_multimap(const key_compare &kcf)
00159         : tree(kcf)
00160     {
00161     }
00162 
00164     template <class InputIterator>
00165     inline btree_multimap(InputIterator first, InputIterator last)
00166         : tree(first, last)
00167     {
00168     }
00169 
00172     template <class InputIterator>
00173     inline btree_multimap(InputIterator first, InputIterator last, const key_compare &kcf)
00174         : tree(first, last, kcf)
00175     {
00176     }
00177 
00179     inline ~btree_multimap()
00180     {
00181     }
00182 
00184     void swap(self& from)
00185     {
00186         std::swap(tree, from.tree);
00187     }
00188 
00189 public:
00190     // *** Key and Value Comparison Function Objects
00191 
00193     inline key_compare key_comp() const
00194     {
00195         return tree.key_comp();
00196     }
00197 
00200     inline value_compare value_comp() const
00201     {
00202         return tree.value_comp();
00203     }
00204 
00205 public:
00206     // *** Fast Destruction of the B+ Tree
00207 
00209     void clear()
00210     {
00211         tree.clear();
00212     }
00213 
00214 public:
00215     // *** STL Iterator Construction Functions
00216 
00219     inline iterator begin()
00220     {
00221         return tree.begin();
00222     }
00223 
00226     inline iterator end()
00227     {
00228         return tree.end();
00229     }
00230 
00233     inline const_iterator begin() const
00234     {
00235         return tree.begin();
00236     }
00237 
00240     inline const_iterator end() const
00241     {
00242         return tree.end();
00243     }
00244 
00247     inline reverse_iterator rbegin()
00248     {
00249         return tree.rbegin();
00250     }
00251 
00254     inline reverse_iterator rend()
00255     {
00256         return tree.rend();
00257     }
00258 
00261     inline const_reverse_iterator rbegin() const
00262     {
00263         return tree.rbegin();
00264     }
00265 
00268     inline const_reverse_iterator rend() const
00269     {
00270         return tree.rend();
00271     }
00272 
00273 public:
00274     // *** Access Functions to the Item Count
00275 
00277     inline size_type size() const
00278     {
00279         return tree.size();
00280     }
00281 
00283     inline bool empty() const
00284     {
00285         return tree.empty();
00286     }
00287     
00290     inline size_type max_size() const
00291     {
00292         return tree.max_size();
00293     }
00294 
00296     inline const tree_stats& get_stats() const
00297     {
00298         return tree.get_stats();
00299     }
00300 
00301 public:
00302     // *** Standard Access Functions Querying the Tree by Descending to a Leaf
00303 
00306     bool exists(const key_type &key) const
00307     {
00308         return tree.exists(key);
00309     }
00310 
00313     iterator find(const key_type &key)
00314     {
00315         return tree.find(key);
00316     }
00317 
00320     const_iterator find(const key_type &key) const
00321     {
00322         return tree.find(key);
00323     }
00324 
00327     size_type count(const key_type &key) const
00328     {
00329         return tree.count(key);
00330     }
00331 
00334     iterator lower_bound(const key_type& key)
00335     {
00336         return tree.lower_bound(key);
00337     }
00338 
00341     const_iterator lower_bound(const key_type& key) const
00342     {
00343         return tree.lower_bound(key);
00344     }
00345 
00348     iterator upper_bound(const key_type& key)
00349     {
00350         return tree.upper_bound(key);
00351     }
00352 
00355     const_iterator upper_bound(const key_type& key) const
00356     {
00357         return tree.upper_bound(key);
00358     }
00359 
00361     inline std::pair<iterator, iterator> equal_range(const key_type& key)
00362     {
00363         return tree.equal_range(key);
00364     }
00365 
00367     inline std::pair<const_iterator, const_iterator> equal_range(const key_type& key) const
00368     {
00369         return tree.equal_range(key);
00370     }
00371 
00372 public:
00373     // *** B+ Tree Object Comparison Functions
00374 
00378     inline bool operator==(const self &other) const
00379     {
00380         return (tree == other.tree);
00381     }
00382 
00384     inline bool operator!=(const self &other) const
00385     {
00386         return (tree != other.tree);
00387     }
00388 
00391     inline bool operator<(const self &other) const
00392     {
00393         return (tree < other.tree);
00394     }
00395 
00397     inline bool operator>(const self &other) const
00398     {
00399         return (tree > other.tree);
00400     }
00401 
00403     inline bool operator<=(const self &other) const
00404     {
00405         return (tree <= other.tree);
00406     }
00407 
00409     inline bool operator>=(const self &other) const
00410     {
00411         return (tree >= other.tree);
00412     }
00413 
00414 public:
00416 
00418     inline self& operator= (const self &other)
00419     {
00420         if (this != &other)
00421         {
00422             tree = other.tree;
00423         }
00424         return *this;
00425     }
00426 
00429     inline btree_multimap(const self &other)
00430         : tree(other.tree)
00431     {
00432     }
00433     
00434 public:
00435     // *** Public Insertion Functions
00436 
00439     inline iterator insert(const value_type& x)
00440     {
00441         return tree.insert2(x.first, x.second).first;
00442     }
00443     
00447     inline iterator insert(const key_type& key, const data_type& data)
00448     {
00449         return tree.insert2(key, data).first;
00450     }
00451 
00456     inline iterator insert2(const key_type& key, const data_type& data)
00457     {
00458         return tree.insert2(key, data).first;
00459     }
00460 
00463     inline iterator insert(iterator hint, const value_type &x)
00464     {
00465         return tree.insert2(hint, x.first, x.second);
00466     }
00467 
00470     inline iterator insert2(iterator hint, const key_type& key, const data_type& data)
00471     {
00472         return tree.insert2(hint, key, data);
00473     }
00474 
00477     template <typename InputIterator>
00478     inline void insert(InputIterator first, InputIterator last)
00479     {
00480         return tree.insert(first, last);
00481     }
00482 
00483 public:
00484     // *** Public Erase Functions
00485 
00488     bool erase_one(const key_type &key)
00489     {
00490         return tree.erase_one(key);
00491     }
00492 
00495     size_type erase(const key_type &key)
00496     {
00497         return tree.erase(key);
00498     }
00499 
00500 #ifdef BTREE_TODO
00502     void erase(iterator iter)
00503     {
00504 
00505     }
00506 #endif
00507 
00508 #ifdef BTREE_TODO
00511     void erase(iterator /* first */, iterator /* last */)
00512     {
00513         abort();
00514     }
00515 #endif
00516 
00517 public:
00518     // *** Debug Printing
00519 
00523     void print() const
00524     {
00525         tree.print();
00526     }
00527 
00529     void print_leaves() const
00530     {
00531         tree.print_leaves();
00532     }
00533 
00534 public:
00535     // *** Verification of B+ Tree Invariants
00536 
00539     void verify() const
00540     {
00541         tree.verify();
00542     }
00543 
00544 public:
00545 
00550     void dump(std::ostream &os) const
00551     {
00552         tree.dump(os);
00553     }
00554 
00559     bool restore(std::istream &is)
00560     {
00561         return tree.restore(is);
00562     }
00563 };
00564 
00565 } // namespace stx
00566 
00567 #endif // _STX_BTREE_MULTIMAP_H_

Generated on Fri Apr 27 14:49:56 2007 for STX B+ Tree Template Classes by  doxygen 1.5.2