public std_pair <TKey, TValue> lower_bound(TKey key) { std_pair <TKey, TValue> sp = null; if (base.ContainsKey(key)) { sp = new std_pair <TKey, TValue>(key, base[key]); } return(sp); }
//public KeyValuePair<TKey, TValue>[] get_allocator() { // KeyValuePair<TKey, TValue>[] array = new KeyValuePair<TKey, TValue>[base.Count]; // base.CopyTo(array, 0); // return array; //} public static std_pair <TKey, TValue>[] get_allocator(std_unordered_map <TKey, TValue> _this) { TKey[] array = new TKey[_this.Count]; _this.Keys.CopyTo(array, 0); std_pair <TKey, TValue>[] sps = new std_pair <TKey, TValue> [_this.Count]; for (int i = 0; i < _this.Count; i++) { sps[i] = new std_pair <TKey, TValue>(array[i], _this[array[i]]); } return(sps); }
public static std_pair <TKey, TValue>[] get_allocator(std_map <TKey, TValue> _this) { KeyValuePair <TKey, TValue>[] array = new KeyValuePair <TKey, TValue> [_this.Count]; _this.CopyTo(array, 0); std_pair <TKey, TValue>[] sps = new std_pair <TKey, TValue> [_this.Count]; for (int i = 0; i < _this.Count; i++) { sps[i] = new std_pair <TKey, TValue>(array[i]); } return(sps); }
public std_pair <KeyValuePair <TKey, TValue>, bool> insert(TKey key, TValue @value) { std_pair <KeyValuePair <TKey, TValue>, bool> ret = new std_pair <KeyValuePair <TKey, TValue>, bool>(new KeyValuePair <TKey, TValue>(key, @value), false); if (!base.ContainsKey(key)) { base.Add(key, @value); ret.second = true; } else { ret = new std_pair <KeyValuePair <TKey, TValue>, bool>(new KeyValuePair <TKey, TValue>(key, base[key]), false); } return(ret); }
public std_pair <std_pair <TKey, TValue>, std_pair <TKey, TValue> > equal_range(TKey key) { //return lower bound and up bound if (!base.ContainsKey(key)) { return(new std_pair <std_pair <TKey, TValue>, std_pair <TKey, TValue> >(null, null));//return null; } std_pair <TKey, TValue> f1 = lower_bound(key); std_pair <TKey, TValue> s2 = upper_bound(key); if (f1 != null) { return(new std_pair <std_pair <TKey, TValue>, std_pair <TKey, TValue> >(f1, s2)); } return(new std_pair <std_pair <TKey, TValue>, std_pair <TKey, TValue> >(null, null)); }
public std_pair <std_pair <TKey, TValue>, std_pair <TKey, TValue> > equal_range(TKey key) { //return lower bound and up bound if (!base.ContainsKey(key)) { return(null); } //KeyValuePair<TKey, TValue> select =new KeyValuePair<TKey,TValue>(key, base[key]); KeyValuePair <TKey, TValue> first = new KeyValuePair <TKey, TValue>(); KeyValuePair <TKey, TValue> second = new KeyValuePair <TKey, TValue>(); bool find_first = false; bool find_second = false; //查找下一个 Enumerator et = base.GetEnumerator(); //if (et.Current.Key.Equals(key)) { // first = et.Current; // find_first = true; //} while (et.MoveNext()) { if (find_first) { second = et.Current; find_second = true; break; } else { if (et.Current.Key.Equals(key)) { first = et.Current; find_first = true; } } } std_pair <std_pair <TKey, TValue>, std_pair <TKey, TValue> > range = new std_pair <std_pair <TKey, TValue>, std_pair <TKey, TValue> >( find_first ? new std_pair <TKey, TValue>(first.Key, first.Value) : null, find_second ? new std_pair <TKey, TValue>(second.Key, second.Value) : null); return(range); }
public std_pair <TKey, TValue> upper_bound(TKey key) { std_pair <TKey, TValue> sp = null; if (base.ContainsKey(key)) { bool find_pre = false; foreach (var v in base.Keys) { if (find_pre) { sp = new std_pair <TKey, TValue>(v, base[v]); break; } if (v.Equals(key)) { find_pre = true; } } } return(sp); }
public bool Equals(std_pair <T> other) { return(this.data.Equals(other.data)); }