Example #1
0
 public BPlusTreeBlock <T> SplitInTwo()
 {
     _Next = new BPlusTreeBlock <T>()
     {
         _Next = _Next
     };
     base.SplitInTwo <BPlusTreeBlock <T> >(_Next);
     return(_Next);
 }
Example #2
0
        public bool AddOrGetExistsValue(T t, out T exists)
        {
            var index = _SortedBlockList.BinarySearch(t);

            if (index < 0)   //not-exists => Add
            {
                var count = _SortedBlockList.Count;
                if (count == 0)   // empty => Add
                {
                    var blockForAdd = new BPlusTreeBlock <T>(_Comparer, _BlockCapacity, t);
                    _SortedBlockList.Add(blockForAdd);
                    exists = default(T);
                    return(true);
                }

                index = ~index;
                if (index == count)
                {
                    index--;
                }
            }

            var block = _SortedBlockList[index];

            if (block.IsFull)
            {
                var newBlock = block.SplitInTwo();
                _SortedBlockList.Add(newBlock);

                index = block.IndexOfKeyCore(t);
                if (index < 0)   //not-exists => Add
                {
                    index = ~index;
                    if (index != block.Count)
                    {
                        var result = block.TryAddOrGetExistsValue(t, out exists);   //---block.Add( t );
                        Debug.Assert(result, "!result");
                        return(result);
                    }
                    else
                    {
                        var result = newBlock.TryAddOrGetExistsValue(t, out exists);   //---newBlock.TryAdd( t );
                        return(result);
                    }
                }
                else //exists => Get
                {
                    exists = block[index];
                }
                return(false);
            }
            else
            {
                var result = block.TryAddOrGetExistsValue(t, out exists);   //---block.Add( t );
                return(result);
            }
        }
Example #3
0
        public bool Add(T t)
        {
            var index = _SortedBlockList.BinarySearch(t);

            if (index < 0)   //not-exists
            {
                var count = _SortedBlockList.Count;
                if (count == 0)
                {
                    var blockForAdd = new BPlusTreeBlock <T>(_Comparer, _BlockCapacity, t);
                    _SortedBlockList.Add(blockForAdd);
                    return(true);
                }

                index = ~index;
                if (index == count)
                {
                    index--;
                }
            }

            var block = _SortedBlockList[index];

            if (block.IsFull)
            {
                //Debugger.Break();

                var newBlock = block.SplitInTwo();
                _SortedBlockList.Add(newBlock);

                index = block.IndexOfKeyCore(t);
                if (index < 0)   //not-exists
                {
                    index = ~index;
                    if (index != block.Count)
                    {
                        var result = block.TryAdd(t);
                        Debug.Assert(result);
                        return(result);
                    }
                    else
                    {
                        var result = newBlock.TryAdd(t);
                        return(result);
                    }
                }
                return(false);
            }
            else
            {
                var result = block.TryAdd(t);
                return(result);
            }
        }
Example #4
0
        public bool Add(T t)
        {
            var block = _SortedBlockSet.FindNearestBlock(t);

            if (block == null)   //not-exists
            {
                block = new BPlusTreeBlock <T>(_Comparer, _BlockCapacity, t);
                _SortedBlockSet.Add(block);
                return(true);
            }

            if (block.IsFull)
            {
                //Debugger.Break();

                //---var result = block.TryAdd( t );
                var newBlock = block.SplitInTwo();
                _SortedBlockSet.Add(newBlock);

                var index = block.IndexOfKeyCore(t);
                if (index < 0)   //not-exists
                {
                    index = ~index;
                    if (index != block.Count)
                    {
                        var result = block.TryAdd(t);
                        Debug.Assert(result, "!result");
                        return(result);
                    }
                    else
                    {
                        var result = newBlock.TryAdd(t);
                        return(result);
                    }
                }
                return(false);
            }
            else
            {
                var result = block.TryAdd(t);
                return(result);
            }
        }
Example #5
0
 public int Compare(BPlusTreeBlock <T> x, BPlusTreeBlock <T> y)
 {
     return(x.CompareOtherWith4_BPlusTreeBlock(y));
 }