stx/btree_multiset.h

Go to the documentation of this file.
00001 // $Id: btree_multiset.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_MULTISET_H_
00026 #define _STX_BTREE_MULTISET_H_
00027 
00028 #include <stx/btree.h>
00029 
00030 namespace stx {
00031 
00050 template <typename _Key,
00051           typename _Compare = std::less<_Key>,
00052           typename _Traits = btree_default_set_traits<_Key> >
00053 class btree_multiset
00054 {
00055 public:
00056     // *** Template Parameter Types
00057 
00060     typedef _Key                        key_type;
00061 
00063     typedef _Compare                    key_compare;
00064 
00067     typedef _Traits                     traits;
00068 
00069 private:
00070     // *** The Data_Type
00071 
00073     struct empty_struct
00074     {
00075     };
00076 
00077 public:
00078     // *** Constructed Types
00079 
00081     typedef struct empty_struct         data_type;
00082 
00084     typedef key_type                    value_type;
00085 
00087     typedef btree_multiset<key_type, key_compare, traits>       self;
00088 
00090     typedef stx::btree<key_type, data_type, value_type, key_compare, traits, true> btree_impl;
00091 
00093     typedef typename btree_impl::value_compare  value_compare;
00094 
00096     typedef typename btree_impl::size_type      size_type;
00097 
00099     typedef typename btree_impl::tree_stats     tree_stats;
00100 
00101 public:
00102     // *** Static Constant Options and Values of the B+ Tree
00103 
00105     static const unsigned short         leafslotmax =  btree_impl::leafslotmax;
00106 
00109     static const unsigned short         innerslotmax =  btree_impl::innerslotmax;
00110 
00114     static const unsigned short         minleafslots = btree_impl::minleafslots;
00115 
00119     static const unsigned short         mininnerslots = btree_impl::mininnerslots;
00120 
00123     static const bool                   selfverify = btree_impl::selfverify;
00124 
00128     static const bool                   debug = btree_impl::debug;
00129 
00131     static const bool                   allow_duplicates = btree_impl::allow_duplicates;
00132 
00133 public:
00134     // *** Iterators and Reverse Iterators
00135 
00138     typedef typename btree_impl::iterator               iterator;
00139 
00142     typedef typename btree_impl::const_iterator         const_iterator;
00143 
00145     typedef typename btree_impl::reverse_iterator       reverse_iterator;
00146 
00148     typedef typename btree_impl::const_reverse_iterator const_reverse_iterator;
00149 
00150 private:
00151     // *** Tree Implementation Object
00152 
00154     btree_impl  tree;
00155 
00156 public:
00157     // *** Constructors and Destructor
00158 
00161     inline btree_multiset()
00162         : tree()
00163     {
00164     }
00165 
00168     inline btree_multiset(const key_compare &kcf)
00169         : tree(kcf)
00170     {
00171     }
00172 
00174     template <class InputIterator>
00175     inline btree_multiset(InputIterator first, InputIterator last)
00176         : tree()
00177     {
00178         insert(first, last);
00179     }
00180 
00183     template <class InputIterator>
00184     inline btree_multiset(InputIterator first, InputIterator last, const key_compare &kcf)
00185         : tree(kcf)
00186     {
00187         insert(first, last);
00188     }
00189 
00191     inline ~btree_multiset()
00192     {
00193     }
00194 
00196     void swap(self& from)
00197     {
00198         std::swap(tree, from.tree);
00199     }
00200 
00201 public:
00202     // *** Key and Value Comparison Function Objects
00203 
00205     inline key_compare key_comp() const
00206     {
00207         return tree.key_comp();
00208     }
00209 
00212     inline value_compare value_comp() const
00213     {
00214         return tree.value_comp();
00215     }
00216 
00217 public:
00218     // *** Fast Destruction of the B+ Tree
00219 
00221     void clear()
00222     {
00223         tree.clear();
00224     }
00225 
00226 public:
00227     // *** STL Iterator Construction Functions
00228 
00231     inline iterator begin()
00232     {
00233         return tree.begin();
00234     }
00235 
00238     inline iterator end()
00239     {
00240         return tree.end();
00241     }
00242 
00245     inline const_iterator begin() const
00246     {
00247         return tree.begin();
00248     }
00249 
00252     inline const_iterator end() const
00253     {
00254         return tree.end();
00255     }
00256 
00259     inline reverse_iterator rbegin()
00260     {
00261         return tree.rbegin();
00262     }
00263 
00266     inline reverse_iterator rend()
00267     {
00268         return tree.rend();
00269     }
00270 
00273     inline const_reverse_iterator rbegin() const
00274     {
00275         return tree.rbegin();
00276     }
00277 
00280     inline const_reverse_iterator rend() const
00281     {
00282         return tree.rend();
00283     }
00284 
00285 public:
00286     // *** Access Functions to the Item Count
00287 
00289     inline size_type size() const
00290     {
00291         return tree.size();
00292     }
00293 
00295     inline bool empty() const
00296     {
00297         return tree.empty();
00298     }
00299     
00302     inline size_type max_size() const
00303     {
00304         return tree.max_size();
00305     }
00306 
00308     inline const tree_stats& get_stats() const
00309     {
00310         return tree.get_stats();
00311     }
00312 
00313 public:
00314     // *** Standard Access Functions Querying the Tree by Descending to a Leaf
00315 
00318     bool exists(const key_type &key) const
00319     {
00320         return tree.exists(key);
00321     }
00322 
00325     iterator find(const key_type &key)
00326     {
00327         return tree.find(key);
00328     }
00329 
00332     const_iterator find(const key_type &key) const
00333     {
00334         return tree.find(key);
00335     }
00336 
00339     size_type count(const key_type &key) const
00340     {
00341         return tree.count(key);
00342     }
00343 
00346     iterator lower_bound(const key_type& key)
00347     {
00348         return tree.lower_bound(key);
00349     }
00350 
00353     const_iterator lower_bound(const key_type& key) const
00354     {
00355         return tree.lower_bound(key);
00356     }
00357 
00360     iterator upper_bound(const key_type& key)
00361     {
00362         return tree.upper_bound(key);
00363     }
00364 
00367     const_iterator upper_bound(const key_type& key) const
00368     {
00369         return tree.upper_bound(key);
00370     }
00371 
00373     inline std::pair<iterator, iterator> equal_range(const key_type& key)
00374     {
00375         return tree.equal_range(key);
00376     }
00377 
00379     inline std::pair<const_iterator, const_iterator> equal_range(const key_type& key) const
00380     {
00381         return tree.equal_range(key);
00382     }
00383 
00384 public:
00385     // *** B+ Tree Object Comparison Functions
00386 
00389     inline bool operator==(const self &other) const
00390     {
00391         return (tree == other.tree);
00392     }
00393 
00395     inline bool operator!=(const self &other) const
00396     {
00397         return (tree != other.tree);
00398     }
00399 
00402     inline bool operator<(const self &other) const
00403     {
00404         return (tree < other.tree);
00405     }
00406 
00408     inline bool operator>(const self &other) const
00409     {
00410         return (tree > other.tree);
00411     }
00412 
00414     inline bool operator<=(const self &other) const
00415     {
00416         return (tree <= other.tree);
00417     }
00418 
00420     inline bool operator>=(const self &other) const
00421     {
00422         return (tree >= other.tree);
00423     }
00424 
00425 public:
00427 
00429     inline self& operator= (const self &other)
00430     {
00431         if (this != &other)
00432         {
00433             tree = other.tree;
00434         }
00435         return *this;
00436     }
00437 
00440     inline btree_multiset(const self &other)
00441         : tree(other.tree)
00442     {
00443     }
00444     
00445 public:
00446     // *** Public Insertion Functions
00447 
00450     inline iterator insert(const key_type& x)
00451     {
00452         return tree.insert2(x, data_type()).first;
00453     }
00454     
00457     inline iterator insert(iterator hint, const key_type &x)
00458     {
00459         return tree.insert2(hint, x, data_type());
00460     }
00461 
00464     template <typename InputIterator>
00465     inline void insert(InputIterator first, InputIterator last)
00466     {
00467         InputIterator iter = first;
00468         while(iter != last)
00469         {
00470             insert(*iter);
00471             ++iter;
00472         }
00473     }
00474 
00475 public:
00476     // *** Public Erase Functions
00477 
00479     bool erase_one(const key_type &key)
00480     {
00481         return tree.erase_one(key);
00482     }
00483 
00486     size_type erase(const key_type &key)
00487     {
00488         return tree.erase(key);
00489     }
00490 
00491 #ifdef BTREE_TODO
00493     void erase(iterator iter)
00494     {
00495 
00496     }
00497 #endif
00498 
00499 #ifdef BTREE_TODO
00502     void erase(iterator /* first */, iterator /* last */)
00503     {
00504         abort();
00505     }
00506 #endif
00507 
00508 public:
00509     // *** Debug Printing
00510 
00514     void print() const
00515     {
00516         tree.print();
00517     }
00518 
00520     void print_leaves() const
00521     {
00522         tree.print_leaves();
00523     }
00524 
00525 public:
00526     // *** Verification of B+ Tree Invariants
00527 
00530     void verify() const
00531     {
00532         tree.verify();
00533     }
00534 
00535 public:
00536 
00541     void dump(std::ostream &os) const
00542     {
00543         tree.dump(os);
00544     }
00545 
00550     bool restore(std::istream &is)
00551     {
00552         return tree.restore(is);
00553     }
00554 };
00555 
00556 } // namespace stx
00557 
00558 #endif // _STX_BTREE_MULTISET_H_

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