/** 将元素放入有尺寸限制的集合中 */ public static void putObjInDicWithMax <T>(long key, T obj, LongObjectMap <T> dic, int max, Comparison <T> compare) { if (max <= 0) { dic.put(key, obj); } else { if (dic.contains(key)) { dic.put(key, obj); } else { if (dic.size() >= max) { long leastKey = findLeastOfDic(dic, compare); dic.remove(leastKey); } dic.put(key, obj); } } }
/** longMap转SList */ public static SList <T> longObjectMapToSList <T>(LongObjectMap <T> map) { SList <T> sList = new SList <T>(map.length()); map.forEach((k, v) => { sList.add(v); }); return(sList); }
public EntryIterator(LongObjectMap <V> map) { _index = _tSafeIndex = map.getLastFreeIndex(); if (map._size == 0) { _index = _tSafeIndex + 1; } _tSet = map._set; _tValues = map._values; _entry = new Entry <V>(); _entry.key = _tFv = map._freeValue; }
public ForEachIterator(LongObjectMap <V> map) { _index = _tSafeIndex = map.getLastFreeIndex(); if (map._size == 0) { _index = _tSafeIndex + 1; } _tSet = map._set; _tValues = map._values; _v = default(V); _k = _tFv = map._freeValue; }
public LongObjectMap <V> clone() { if (_size == 0) { return(new LongObjectMap <V>()); } LongObjectMap <V> re = new LongObjectMap <V>(capacity()); //双拷贝 Array.Copy(_set, 0, re._set, 0, _set.Length); Array.Copy(_values, 0, re._values, 0, _values.Length); re.copyBase(this); re._freeValue = _freeValue; return(re); }
public void putAll(LongObjectMap <V> dic) { if (dic.isEmpty()) { return; } long[] keys = dic.getKeys(); V[] values = dic.getValues(); long fv = dic.getFreeValue(); long k; for (int i = keys.Length - 1; i >= 0; --i) { if ((k = keys[i]) != fv) { put(k, values[i]); } } }
/** 在字典中找寻最小的 */ public static long findLeastOfDic <T>(LongObjectMap <T> dic, Comparison <T> compare) { long[] keys = dic.getKeys(); T[] values = dic.getValues(); long fv = dic.getFreeValue(); long k; T v; T temp = default(T); bool has = false; long re = -1; for (int i = keys.Length - 1; i >= 0; --i) { if ((k = keys[i]) != fv) { v = values[i]; if (!has) { has = true; temp = v; re = k; } else { if (compare(temp, v) < 0) { temp = v; re = k; } } } } return(re); }
public EntrySet(LongObjectMap <V> map) { _map = map; }