Claw  1.7.3
avl.hpp
Go to the documentation of this file.
1 /*
2  CLAW - a C++ Library Absolutely Wonderful
3 
4  CLAW is a free library without any particular aim but being useful to
5  anyone.
6 
7  Copyright (C) 2005-2011 Julien Jorge
8 
9  This library is free software; you can redistribute it and/or
10  modify it under the terms of the GNU Lesser General Public
11  License as published by the Free Software Foundation; either
12  version 2.1 of the License, or (at your option) any later version.
13 
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public
20  License along with this library; if not, write to the Free Software
21  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 
23  contact: julien.jorge@gamned.org
24 */
30 #ifndef __CLAW_AVL_HPP__
31 #define __CLAW_AVL_HPP__
32 
33 #include <claw/avl_base.hpp>
34 
35 namespace claw
36 {
37  //---------------------------------------------------------------------------
42  template < class K, class Comp = std::less<K> >
43  class avl
44  {
45  private:
48 
49  public:
51  typedef K value_type;
52 
54  typedef K key_type;
55 
57  typedef K referent_type;
58 
60  typedef Comp key_less;
61 
63  typedef const K& const_reference;
64 
66  typedef typename impl_type::avl_const_iterator const_iterator;
67 
68  public:
69  avl();
70  explicit avl( const avl<K, Comp>& that );
71  template<typename InputIterator>
72  avl( InputIterator first, InputIterator last );
73 
74  void insert( const K& key );
75  template<typename InputIterator>
76  void insert( InputIterator first, InputIterator last );
77 
78  void erase( const K& key );
79  void clear();
80 
81  unsigned int size() const;
82  bool empty() const;
83 
84  const_iterator begin() const;
85  const_iterator end() const;
86  const_iterator find( const K& key ) const;
87  const_iterator find_nearest_greater( const K& key ) const;
88  const_iterator find_nearest_lower( const K& key ) const;
91 
92  avl<K, Comp>& operator=( const avl<K, Comp>& that );
93  bool operator==( const avl<K, Comp>& that ) const;
94  bool operator!=( const avl<K, Comp>& that ) const;
95  bool operator<( const avl<K, Comp>& that ) const;
96  bool operator>( const avl<K, Comp>& that ) const;
97  bool operator<=( const avl<K, Comp>& that ) const;
98  bool operator>=( const avl<K, Comp>& that ) const;
99 
100  private:
102  impl_type m_tree;
103 
104  }; // class avl
105 } // namespace claw
106 
107 #include <claw/impl/avl.tpp>
108 
109 #endif // __CLAW_AVL_HPP__
void insert(const K &key)
Add a value in a tree.
Definition: avl.tpp:75
unsigned int size() const
Get the size of a tree.
Definition: avl.tpp:124
const_iterator upper_bound() const
Get an iterator on the gratest value of the tree.
Definition: avl.tpp:216
bool operator!=(const avl< K, Comp > &that) const
Disequality.
Definition: avl.tpp:250
Binary search tree AVL implementation.
Definition: avl.hpp:43
const_iterator end() const
Get an iterator after the end of the tree.
Definition: avl.tpp:156
void erase(const K &key)
Delete a value in a tree.
Definition: avl.tpp:102
Binary search tree base AVL implementation.
Definition: avl_base.hpp:57
bool operator>(const avl< K, Comp > &that) const
Greater than operator.
Definition: avl.tpp:272
Base implementation for the AVL Binary search tree.
impl_type::avl_const_iterator const_iterator
The type of the iterator on the values of the tree.
Definition: avl.hpp:66
void clear()
Clear a tree.
Definition: avl.tpp:113
K key_type
The type of the keys in the tree.
Definition: avl.hpp:54
bool empty() const
Tell if a tree is empty or not.
Definition: avl.tpp:135
Fuction object to get the first element of a std::pair.
Definition: functional.hpp:44
bool operator==(const avl< K, Comp > &that) const
Equality.
Definition: avl.tpp:239
K referent_type
The type passed to the template.
Definition: avl.hpp:57
const K & const_reference
The type of a const reference on the values.
Definition: avl.hpp:63
bool operator>=(const avl< K, Comp > &that) const
Greater or equal operator.
Definition: avl.tpp:294
const_iterator find_nearest_greater(const K &key) const
Get an iterator on the nodes of the tree on the key imediatly after from a specified key...
Definition: avl.tpp:181
The avl class implementation.
const_iterator find_nearest_lower(const K &key) const
Get an iterator on the nodes of the tree on the key imediatly before from a specified key...
Definition: avl.tpp:194
Comp key_less
The comparator to use to compare the keys.
Definition: avl.hpp:60
avl()
AVL constructor.
Definition: avl.tpp:38
const_iterator find(const K &key) const
Get an iterator on the nodes of the tree from a specified key.
Definition: avl.tpp:168
avl< K, Comp > & operator=(const avl< K, Comp > &that)
Assignment.
Definition: avl.tpp:227
const_iterator lower_bound() const
Get an iterator on the lowest value of the tree.
Definition: avl.tpp:205
K value_type
The type of the values in the tree.
Definition: avl.hpp:51
const_iterator begin() const
Get an iterator on the nodes of the tree.
Definition: avl.tpp:146