map 和 set 的封装
map 和 set 在封装时对红黑树内部 K、T 的处理有所不同:
map:K 存储 Key,T 存储pair<Key, Value>。Key 用于排序查找,Value 存储信息。set:K 存储 Key,T 也存储 Key。键承担了所有功能。
对于 set,K 和 T 均不可被修改;对于 map,K 不可修改,但 T 中的 Value 可以修改。
namespace renshen {
template<class K, class V>
class map {
struct MapKeyOfT {
const K& operator()(const pair<K, V>& kv) {
return kv.first;
}
};
public:
typedef typename RBTree<K, pair<const K, V>, MapKeyOfT>::iterator iterator;
typedef typename RBTree<K, pair<const K, V>, MapKeyOfT>::const_iterator const_iterator;
iterator begin() { return _t.begin(); }
iterator end() { return _t.end(); }
const_iterator begin() const { return _t.begin(); }
const_iterator { .(); }
V& []( K& key) {
pair<iterator, > ret = ((key, ()));
ret.first->second;
}
{
.(kv);
}
:
RBTree<K, pair< K, V>, MapKeyOfT> ;
};
}


