Esempio n. 1
0
            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);
            }
Esempio n. 2
0
            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();
                    }
                }
            }
Esempio n. 3
0
        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);
                }
            }
        }
Esempio n. 4
0
 private void SetParent(CacheNode <TKey, TValue> parent)
 {
     _parent = parent;
 }
Esempio n. 5
0
 public CacheNodeProxy(CacheNode <TKey, TValue> node)
 {
     _node = node;
 }
Esempio n. 6
0
 public abstract void BuildTree(CacheNode <TKey, TValue> root, int outPath);
Esempio n. 7
0
            protected void FillNodesArray(CacheNode <TKey, TValue> root, CacheNode <TKey, TValue>[] nodes, int activePath)
            {
                int actNodes = 0;

                RecursiveFill(root, ref actNodes, nodes, activePath);
            }
Esempio n. 8
0
 public void Clear()
 {
     _root = null;
 }
Esempio n. 9
0
            public override void BuildTree(CacheNode <TKey, TValue> root, int outPath)
            {
                int depth = 0;

                ConstructNewTreeAfterCalculation(0, _actNodes - 1, ref depth, outPath);
            }