28 #ifndef _util_container_avlmap_h
29 #define _util_container_avlmap_h
31 #include <util/container/eavlmmap.h>
35 template <
class K,
class T>
41 AVLMapNode(
const K& k,
const T& d): data(d), node(k) {};
44 template <
class K,
class T>
59 void operator++() { map_->next(node); }
60 void operator++(
int) { operator++(); }
62 {
return map_ == i.map_ && node == i.node; }
64 {
return !operator == (i); }
66 { map_ = i.map_; node = i.node; }
67 const K &key()
const {
return node->node.key; }
68 T &data() {
return node->data; }
72 void clear() { map_.clear(); }
73 void insert(
const K& key,
const T& data);
74 void remove(
const K& key);
75 int contains(
const K& k)
const {
return map_.find(k) != 0; }
76 iterator find(
const K&)
const;
77 T &operator[](
const K &k);
79 int height() {
return map_.height(); }
80 void check() { map_.check(); }
82 int length()
const {
return map_.length(); }
84 iterator begin()
const {
return iterator(&map_,map_.start()); }
85 iterator end()
const {
return iterator(&map_,0); }
87 void print() { map_.print(); }
90 template <
class K,
class T>
92 AVLMap<K,T>::insert(
const K& key,
const T& data)
94 AVLMapNode<K,T> *node = map_.find(key);
95 if (node) node->data = data;
96 else map_.insert(
new AVLMapNode<K, T>(key,data));
99 template <
class K,
class T>
101 AVLMap<K,T>::remove(
const K& key)
103 AVLMapNode<K, T> *node = map_.find(key);
110 template <
class K,
class T>
111 inline typename AVLMap<K,T>::iterator
112 AVLMap<K,T>::find(
const K& k)
const
114 return iterator(&map_,map_.find(k));
117 template <
class K,
class T>
119 AVLMap<K,T>::operator [](
const K& k)
121 AVLMapNode<K, T> *node = map_.find(k);
122 if (node)
return node->data;