public HybridRebalancer(CacheNode <TKey, TValue> root, int nodeCount, int activePath, int outPath, TimeSpan expectedTimeToEnd) { _nodes = new CacheNode <TKey, TValue> [nodeCount]; _activePath = activePath; _outPath = outPath; _oldRoot = root; if (_timeFor500NodesToRebalance == default(TimeSpan)) { MaxNodesForExactRebalancing = 500; } else { var r = expectedTimeToEnd.TotalMilliseconds / _timeFor500NodesToRebalance.TotalMilliseconds; MaxNodesForExactRebalancing = (int)Math.Pow(r * Math.Pow(500, 3), 1 / 3.0); } _nodesForHeavyRebalance = Math.Min(nodeCount, MaxNodesForExactRebalancing); FillNodesArray(root, _nodes, _activePath); Debug.Assert(_nodes.Select(k => k._key).Distinct().Count() == _nodes.Length && _nodes.Length == nodeCount); }
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(); } } }
public void AddNode(CacheNode <TKey, TValue> newNode, int path, ref int depth) { CacheNode <TKey, TValue> node; depth++; var moreOrLess = _comparer.Compare(_key, newNode._key); if (moreOrLess == 0) { Debug.Fail("Добавление уже существующего ключа"); } else if (moreOrLess > 0) { node = GetLeftNode(path); if (node != null) { node.AddNode(newNode, path, ref depth); } else { CreateNode(true, newNode, path); } } else if (moreOrLess < 0) { node = GetRightNode(path); if (node != null) { node.AddNode(newNode, path, ref depth); } else { CreateNode(false, newNode, path); } } }
private void SetParent(CacheNode <TKey, TValue> parent) { _parent = parent; }
public CacheNodeProxy(CacheNode <TKey, TValue> node) { _node = node; }
public abstract void BuildTree(CacheNode <TKey, TValue> root, int outPath);
protected void FillNodesArray(CacheNode <TKey, TValue> root, CacheNode <TKey, TValue>[] nodes, int activePath) { int actNodes = 0; RecursiveFill(root, ref actNodes, nodes, activePath); }
public void Clear() { _root = null; }
public override void BuildTree(CacheNode <TKey, TValue> root, int outPath) { int depth = 0; ConstructNewTreeAfterCalculation(0, _actNodes - 1, ref depth, outPath); }