00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef __PANALIX_AVLMAP_HPP
00012 #define __PANALIX_AVLMAP_HPP
00013
00014 #include "src/collection/avltree.hpp"
00015 #include "src/collection/tuple.hpp"
00016
00017 namespace Collection {
00018
00019 template<typename A, typename B, int (*cmp)(A,A) >
00020 int tuple2_comparator(Tuple2<A,B> a1, Tuple2<A,B> a2) {
00021 return cmp(a1._1, a2._1);
00022 }
00023
00024 template <typename KeyT, typename DataT, int (*cmp) (KeyT, KeyT)>
00025 class AvlMap {
00026 private:
00027 AvlTree<Tuple2<KeyT,DataT>, tuple2_comparator<KeyT,DataT,cmp> > *tr;
00028 public:
00029 AvlMap() {
00030 tr= new AvlTree<Tuple2<KeyT,DataT>, tuple2_comparator<KeyT,DataT,cmp> >;
00031
00032 }
00033 ~AvlMap() {
00034 notimpl();
00035 }
00036
00037 bool update(KeyT key, DataT data) {
00038 return tr->insert(Tuple2<KeyT,DataT>(key,data));
00039 }
00040
00041 bool remove(KeyT key) {
00042 return tr->remove(Tuple2<KeyT,DataT>(key,(DataT)(0)));
00043 }
00044 bool isEmpty() {
00045 return tr->isEmpty();
00046 }
00047
00048 Option<Tuple2<KeyT, DataT> > find(KeyT key) {
00049 return tr->find(Tuple2<KeyT,DataT>(key,(DataT)(0)));
00050 }
00051 };
00052 }
00053
00054
00055 #endif
00056