27 #include <l4/cxx/std_alloc> 28 #include <l4/cxx/std_ops> 29 #include <l4/cxx/type_traits> 42 template<
typename Node,
typename Key,
typename Node_op >
43 class Avl_set_iter :
public __Bst_iter_b<Node, Node_op>
47 typedef __Bst_iter_b<Node, Node_op> Base;
62 Avl_set_iter(Node
const *t) : Base(t) {}
64 Avl_set_iter(Base
const &o) : Base(o) {}
66 Avl_set_iter(Avl_set_iter<Node,
typename Type_traits<Key>::Non_const_type, Node_op>
const &o)
73 Key &operator * ()
const {
return const_cast<Node*
>(_n)->item; }
78 Key *operator -> ()
const {
return &
const_cast<Node*
>(_n)->item; }
82 Avl_set_iter &operator ++ () { inc();
return *
this; }
86 Avl_set_iter &operator ++ (
int)
87 { Avl_set_iter tmp = *
this; inc();
return tmp; }
92 template<
typename KEY_TYPE>
95 typedef KEY_TYPE Key_type;
96 template<
typename NODE>
97 static Key_type
const &key_of(NODE
const *n)
114 template<
typename ITEM_TYPE,
class COMPARE,
115 template<
typename A>
class ALLOC,
154 _Node(Item_type
const &item) :
Avl_tree_node(), item(item) {}
165 friend class Base_avl_set<ITEM_TYPE, COMPARE, ALLOC, GET_KEY>;
167 explicit Node(_Node
const *n) : _n(n) {}
174 Node &operator = (
Node const &o) { _n = o._n;
return *
this; }
181 Item_type
const &operator * () {
return _n->item; }
187 Item_type
const *operator -> () {
return &_n->item; }
196 operator Item_type
const * () {
if (_n)
return &_n->item;
else return 0; }
206 Node_allocator _alloc;
214 typedef typename Type_traits<Item_type>::Param_type Item_param_type;
217 typedef Avl_set_iter<_Node, Item_type, Fwd>
Iterator;
218 typedef Iterator iterator;
221 typedef Const_iterator const_iterator;
224 typedef Rev_iterator reverse_iterator;
227 typedef Const_rev_iterator const_reverse_iterator;
236 : _tree(), _alloc(alloc)
285 int remove(Key_type
const &item)
287 _Node *n = _tree.
remove(item);
288 if ((
long)n == -E_inval)
306 {
return remove(item); }
330 Node lower_bound_node(Key_type &&key)
const 342 Const_iterator
end()
const {
return _tree.
end(); }
364 Const_rev_iterator
rend()
const {
return _tree.
rend(); }
377 Const_iterator find(Key_type
const &item)
const 378 {
return _tree.
find(item); }
386 template<
typename Item,
class Compare,
template<
typename A>
class Alloc,
typename KEY_TYPE>
388 : _tree(), _alloc(o._alloc)
390 for (Const_iterator i = o.
begin(); i != o.
end(); ++i)
395 template<
typename Item,
class Compare,
template<
typename A >
class Alloc,
typename KEY_TYPE>
399 _Node *n = _alloc.alloc();
401 return cxx::pair(end(), -E_nomem);
403 new (n,
Nothrow()) _Node(item);
427 template<
typename ITEM_TYPE,
class COMPARE = Lt_functor<ITEM_TYPE>,
431 Bits::Avl_set_get_key<ITEM_TYPE> >
440 Avl_set(Node_allocator
const &alloc)
Rev_iterator rbegin()
Get the mutable backward iterator for the last element of the set.
ITEM_TYPE Item_type
Type for the items store in the set.
Const_rev_iterator rbegin() const
Get the constant backward iterator for the last element in the set.
Node find_node(Key_type const &item) const
Lookup a node equal to item.
Node * remove(Key_param_type key)
Remove the node with key from the tree.
Node()
Default construction for NIL pointer.
Pair< Node *, bool > insert(Node *new_node)
Insert a new node into this AVL tree.
Helper type to distinguish the oeprator new version that does not throw exceptions.
bool valid() const
Validity check.
Rev Rev_iter_ops
Helper for building reverse iterators for different wrapper classes.
Const_iterator end() const
Get the end marker for the constant forward iterator.
AVL set for simple compareable items.
Const_rev_iterator rend() const
Get the end marker for the constant backward iterator.
Second second
Second value.
Avl_set_iter< _Node, Item_type, Fwd > Iterator
Forward iterator for the set.
Node * lower_bound_node(Key_param_type key) const
find the first node with a key not less than the given key.
Const_iterator find(Key_param_type key) const
find the node with the given key.
Node * find_node(Key_param_type key) const
find the node with the given key.
ALLOC< _Node > Node_allocator
Type for the node allocator.
Iterator end()
Get the end marker for the mutable forward iterator.
COMPARE Item_compare
Type for the comparison functor.
A smart pointer to a tree item.
void remove_all(FUNC &&callback)
Clear the tree.
Const_rev_iterator rbegin() const
Get the constant backward iterator for the last element in the set.
Avl_set_iter< _Node, Item_type, Rev > Rev_iterator
Backward iterator for the set.
Const_iterator begin() const
Get the constant forward iterator for the first element in the set.
Rev_iterator rend()
Get the end marker for the mutable backward iterator.
Internal: AVL set with internally managed nodes.
Const_iterator begin() const
Get the constant forward iterator for the first element in the set.
Avl_set_iter< _Node, Const_item_type, Rev > Const_rev_iterator
Constant backward iterator for the set.
int erase(Key_type const &item)
Erase the item with the given key.
Iterator begin()
Get the mutable forward iterator for the first element of the set.
GET_KEY::Key_type Key_type
Type of the sort key used for the items.
Const_iterator end() const
Get the end marker for the constant forward iterator.
GET_KEY Get_key
Key-getter type to derive the sort key of an internal node.
Bst::Iterator Iterator
Forward iterator for the tree.
Avl_set_iter< _Node, Const_item_type, Fwd > Const_iterator
Constant forward iterator for the set.
Node lower_bound_node(Key_type const &key) const
Find the first node greater or equal to key.
Const_rev_iterator rend() const
Get the end marker for the constant backward iterator.
Type_traits< Item_type >::Const_type Const_item_type
Type used for const items within the set.
Fwd Fwd_iter_ops
Helper for building forward iterators for different wrapper classes.
Base_avl_set(Node_allocator const &alloc=Node_allocator())
Create a AVL-tree based set.
Internal, key-getter for Avl_set nodes.
Standard allocator based on operator new () .