protected void CleanUpTree(CacheNode <TKey, TValue> _oldRoot, IEnumerable <CacheNode <TKey, TValue> > _nodes, int _activePath, int _outPath) { if (Settings.CheckCycles) { if (!_oldRoot.CheckTree(_activePath)) { Debugger.Break(); } if (!_oldRoot.CheckTree(_outPath)) { Debugger.Break(); } } foreach (var cnode in _nodes.Where(k => k != null)) { var lnode = cnode.GetLeftNode(_outPath); if (lnode != null) { cnode.UnfixChild(lnode, _outPath); } var rnode = cnode.GetRightNode(_outPath); if (rnode != null) { cnode.UnfixChild(rnode, _outPath); } cnode._depth[_activePath] = 0; cnode.SetLeftNode(null, _outPath); cnode.SetRightNode(null, _outPath); } }
public void Add(TKey key, TValue value) { bool lockTaken = false; try { _writeLock.TryEnter(_writeTimeout, ref lockTaken); if (lockTaken) { if (Settings.CheckCycles && _root != null) { if (!_root.CheckTree(_currentPath, _cacheNodeCount + 1)) { Debugger.Break(); } } if (_root == null) { _root = new CacheNode <TKey, TValue>(key, value, _maxFixedBranchDepth, _comparer, Channel, DecCount, _frequencyCalc); } else { _root.AddNode(key, value, _maxFixedBranchDepth, _currentPath); } if (Settings.CheckCycles && _root != null) { if (!_root.CheckTree(_currentPath, _cacheNodeCount + 1)) { Debugger.Break(); } } Interlocked.Increment(ref _cacheNodeCount); } else { #if DEBUG if (NodeLostEvent != null) { NodeLostEvent(this, new EventArgs()); } #endif } } finally { if (lockTaken) { _writeLock.Exit(); } } }
protected void AfterBuildCheck(CacheNode <TKey, TValue> _oldRoot, IEnumerable <CacheNode <TKey, TValue> > _nodes, int _activePath, int _outPath) { if (Settings.CheckCycles) { foreach (var cnode in _nodes.Where(k => k != null)) { if (cnode.HasLeftNode(_outPath) || cnode.HasRightNode(_outPath)) { Debugger.Break(); } } if (!_oldRoot.CheckTree(_activePath)) { Debugger.Break(); } if (!_oldRoot.CheckTree(_outPath)) { Debugger.Break(); } } }