map 和 set 的封装
这俩在封装的时候对红黑树里面的 K,T 的处理:
map的话 K 是存 Key,T 是搞的 pair<Key,Value>--这两个 Key 是一样的哈
set的话 K 是存 Key,T 也是存 Key--这两个 Key 是一样的哈 (第二个 T 存东西单纯为了陪跑)对于
set的话 KT 都不能被修改–因为都是 Key对于
map的话 K 不能被修改,T 里面的 value 可以被修改对于键和值的理解:
对于
map:键用来排序查找啥的,值用来存信息对于
set:键承担了所有
namespace mylib {
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 {
.();
}
{
.();
}
V& []( K& key) {
pair<iterator, > ret = ((key, ()));
ret.first->second;
}
{
.(kv);
}
:
RBTree<K, pair< K, V>, MapKeyOfT> ;
};
}

