1 #ifndef __MAP_H__
2 #define __MAP_H__
3 
4 #include "pair.h"
5 #include "set.h"
6 
7 template<class T1, class T2> class TMap : public TSet< TPair<T1,T2> > {
8 	typedef TPair<T1,T2> TData;
9 	typedef T1 TFirst;
10 	typedef T2 TSecond;
11 public:
TMap()12 	TMap () { this->d = 0; this->capacity = 0; }
13 	T2 &operator [] (const T1 &key);
14 	typedef typename TVector<TPair<T1,T2> >::iterator iterator;
15 	virtual iterator find (const T1& key) const;
16 };
17 
18 #define MAP(x,y,z) typedef TMap<x,y> z;
19 
20 template<class T1,class T2>
21 T2 & TMap<T1,T2>::operator [] (const T1 &key) {
22 	iterator found = find (key);
23 	if (found != this->end())
24 		return found->second();
25 	else {
26 		TData x;
27 		x.first() = key;
28 		return this->insert (x)->second();
29 	}
30 }
31 
32 template<class T1,class T2>
find(const T1 & key)33 typename TMap<T1,T2>::iterator TMap<T1,T2>::find (const T1 &key) const {
34 	TData x;
35 	x.first() = key;
36 	return TSet<TData>::find (x);
37 }
38 
39 #endif
40