protected bool insideRemove(T obj, IList <uint> keys) { lock (this.locker) { if (keys.Count == 0) { this.Objs.Remove(obj); return(this.ObjsInDeep.Contains(obj)); } DeepMemory <T> mem; bool hasInDeep = false; foreach (uint key in keys) { if (this.Mems.TryGetValue(key, out mem)) { if (mem.insideRemove(obj, keys.Where(k => k != key).ToList <uint>())) { hasInDeep = true; } if (mem.ObjsInDeep.Count == 0) { this.Mems.Remove(key); } } } if (!hasInDeep) { ObjsInDeep.Remove(obj); } return(this.ObjsInDeep.Contains(obj)); } }
public void Add(T obj, IList <uint> keys) { lock (this.locker) { if (keys.Count == 0) { if (this.Objs == null) { this.Objs = new List <T>(); } this.Objs.Add(obj); return; } foreach (uint key in keys) { DeepMemory <T> record; if (!this.Mems.TryGetValue(key, out record)) { record = new DeepMemory <T>(key); this.Mems.Add(key, record); } record.Add(obj, keys.Where(k => k != key).ToList <uint>()); } if (!this.ObjsInDeep.Contains(obj)) { ObjsInDeep.Add(obj); } } }