L4Re Operating System Framework
Interface and Usage Documentation
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
avl_map
Go to the documentation of this file.
1// vi:set ft=cpp: -*- Mode: C++ -*-
6/*
7 * (c) 2008-2009 Alexander Warg <warg@os.inf.tu-dresden.de>
8 * economic rights: Technische Universität Dresden (Germany)
9 *
10 * License: see LICENSE.spdx (in this directory or the directories above)
11 */
12
13#pragma once
14
15#include <l4/cxx/std_alloc>
16#include <l4/cxx/std_ops>
17#include <l4/cxx/pair>
18#include <l4/cxx/avl_set>
19
20namespace cxx {
21namespace Bits {
22
24template<typename KEY_TYPE>
26{
27 typedef KEY_TYPE Key_type;
28 template<typename NODE>
29 static Key_type const &key_of(NODE const *n)
30 { return n->item.first; }
31};
32}
33
42template< typename KEY_TYPE, typename DATA_TYPE,
43 template<typename A> class COMPARE = Lt_functor,
44 template<typename B> class ALLOC = New_allocator >
45class Avl_map :
46 public Bits::Base_avl_set<Pair<KEY_TYPE, DATA_TYPE>,
47 COMPARE<KEY_TYPE>, ALLOC,
48 Bits::Avl_map_get_key<KEY_TYPE> >
49{
50private:
51 typedef Pair<KEY_TYPE, DATA_TYPE> Local_item_type;
54
55public:
57 typedef COMPARE<KEY_TYPE> Key_compare;
59 typedef KEY_TYPE Key_type;
61 typedef DATA_TYPE Data_type;
63 typedef typename Base_type::Node Node;
66
67 typedef typename Base_type::Iterator Iterator;
68 typedef typename Base_type::Iterator iterator;
69 typedef typename Base_type::Const_iterator Const_iterator;
70 typedef typename Base_type::Const_iterator const_iterator;
71 typedef typename Base_type::Rev_iterator Rev_iterator;
72 typedef typename Base_type::Rev_iterator reverse_iterator;
73 typedef typename Base_type::Const_rev_iterator Const_rev_iterator;
74 typedef typename Base_type::Const_rev_iterator const_reverse_iterator;
75
81 : Base_type(alloc)
82 {}
83
101
102 template<typename... Args>
103 cxx::Pair<Iterator, int> emplace(Args &&...args)
104 { return Base_type::emplace(cxx::forward<Args>(args)...); }
105
111 Data_type const &operator [] (Key_type const &key) const
112 { return this->find_node(key)->second; }
113
124 {
125 Node n = this->find_node(key);
126 if (n)
127 return const_cast<Data_type&>(n->second);
128 else
129 return insert(key, Data_type()).first->second;
130 }
131};
132
133}
134
AVL set.
AVL tree based associative container.
Definition avl_map:49
KEY_TYPE Key_type
Type of the key values.
Definition avl_map:59
Avl_map(Node_allocator const &alloc=Node_allocator())
Create an empty AVL-tree based map.
Definition avl_map:80
COMPARE< KEY_TYPE > Key_compare
Type of the comparison functor.
Definition avl_map:57
Base_type::Node Node
Return type for find.
Definition avl_map:63
Base_type::Node_allocator Node_allocator
Type of the allocator.
Definition avl_map:65
cxx::Pair< Iterator, int > insert(Key_type const &key, Data_type const &data)
Insert a <key, data> pair into the map.
Definition avl_map:99
DATA_TYPE Data_type
Type of the data values.
Definition avl_map:61
Data_type const & operator[](Key_type const &key) const
Get the data for the given key.
Definition avl_map:111
A smart pointer to a tree item.
Definition avl_set:173
Internal: AVL set with internally managed nodes.
Definition avl_set:123
Avl_set_iter< _Node, Item_type, Fwd > Iterator
Forward iterator for the set.
Definition avl_set:225
Node find_node(Key_type const &item) const
Lookup a node equal to item.
Definition avl_set:324
Avl_set_iter< _Node, Item_type, Rev > Rev_iterator
Backward iterator for the set.
Definition avl_set:231
ALLOC< _Node > Node_allocator
Type for the node allocator.
Definition avl_set:208
Avl_set_iter< _Node, Const_item_type, Rev > Const_rev_iterator
Constant backward iterator for the set.
Definition avl_set:234
cxx::Pair< Iterator, int > insert(Item_type const &item)
Insert an item into the set.
Definition avl_set:412
Avl_set_iter< _Node, Const_item_type, Fwd > Const_iterator
Constant forward iterator for the set.
Definition avl_set:228
Standard allocator based on operator new () .
Definition std_alloc:57
Our C++ library.
Definition arith:11
Pair implementation.
Key-getter for Avl_map.
Definition avl_map:26
Generic comparator class that defaults to the less-than operator.
Definition std_ops:19
Pair of two values.
Definition pair:28