Example #1
0
 private BTreeValue <TKey, TKeyData, TData> ReturnFromLeft(TKey uid, BTreeValue <TKey, TKeyData, TData> current)
 {
     if (0 == current.BucketBeforeId)
     {
         return(null);
     }
     if (null == current.BucketBefore)
     {
         current.BucketBefore = Index.LoadBucket(current.BucketBeforeId);
     }
     return(current.BucketBefore.Find(uid));
 }
Example #2
0
 private BTreeValue <TKey, TKeyData, TData> ReturnFromRight(TKey uid, BTreeValue <TKey, TKeyData, TData> current)
 {
     if (0 == current.BucketAfterId)
     {
         return(null);
     }
     if (null == current.BucketAfter)
     {
         current.BucketAfter = Index.LoadBucket(current.BucketAfterId);
     }
     return(current.BucketAfter.Find(uid));
 }
Example #3
0
        /// <summary>
        /// Generates a user-defined type (UDT) or user-defined aggregate from its binary form.
        /// </summary>
        /// <param name="r">The <see cref="T:System.IO.BinaryReader"/> stream from which the object is deserialized.</param>
        public void Read(BinaryReader r)
        {
            Id = r.ReadInt32();
            var cnt = r.ReadInt32();
            BTreeValue <TKey, TKeyData, TData> last    = null;
            BTreeValue <TKey, TKeyData, TData> current = null;

            for (var i = 0; i < cnt; i++)
            {
                current = new BTreeValue <TKey, TKeyData, TData> {
                    ContainingBucket = this
                };
                current.Read(r);
                current.BucketBeforeId = r.ReadInt32();

                if (0 != current.BucketBeforeId)
                {
                    current.BucketBefore = new BTreeBucket <TKey, TKeyData, TData> {
                        Index = Index
                    };
                    current.BucketBefore.Read(r);
                    current.BucketBefore.Parent = this;
                    Index.PlainIndex[current.BucketBefore.Id] = current.BucketBefore;
                }

                if (null != last)
                {
                    last.BucketAfterId = current.BucketBeforeId;
                    if (0 != current.BucketBeforeId)
                    {
                        last.BucketAfter = current.BucketBefore;
                    }
                }
                last = current;
                if (cnt - 1 == i)
                {
                    current.BucketAfterId = r.ReadInt32();
                    if (0 != current.BucketAfterId)
                    {
                        current.BucketAfter       = new BTreeBucket <TKey, TKeyData, TData>();
                        current.BucketAfter.Index = Index;
                        current.BucketAfter.Read(r);
                        current.BucketAfter.Parent = this;
                        this.Index.PlainIndex[current.BucketAfter.Id] = current.BucketAfter;
                    }
                }
                this.Values.Add(current);
            }
        }
Example #4
0
        /// <summary>
        /// Метод встраивания значения в текущий букет - добавляет к набору если отсутствует и переупорядочивает
        /// </summary>
        /// <param name="uid"></param>
        /// <param name="keydata"></param>
        /// <param name="data"></param>
        private void StoreHere(TKey uid, TKeyData keydata, TData[] data)
        {
            BTreeValue <TKey, TKeyData, TData> value = null;

            if (Index.SelfDataOnly)
            {
                value = new BTreeValue <TKey, TKeyData, TData> {
                    Key = uid, Value = keydata
                };
            }
            else
            {
                value = new BTreeValue <TKey, TKeyData, TData> {
                    Key = uid, Value = Index.CreateDataStorage()
                };
            }
            value.ContainingBucket = this;
            int insertIndex = -1;

            for (var i = 0; i < Values.Count; i++)
            {
                if (Values[i].Key.CompareTo(uid) > 0)
                {
                    insertIndex = i;
                    break;
                }
            }
            if (-1 == insertIndex)
            {
                Values.Add(value);
            }
            else
            {
                Values.Insert(insertIndex, value);
            }
            MarkChanged();

            if (null != data && 0 != data.Length)
            {
                Index.AppendData(value.Value, data);
            }
        }
Example #5
0
        private void StoreLeft(TKey uid, TKeyData keydata, TData[] data, BTreeValue <TKey, TKeyData, TData> current, int ix)
        {
            if (0 == current.BucketBeforeId)
            {
                var newbucket = Index.CreateBucket();
                current.BucketBeforeId = newbucket.Id;
                current.BucketBefore   = newbucket;

                MarkChanged();
            }
            if (null == current.BucketBefore)
            {
                current.BucketBefore = Index.LoadBucket(current.BucketBeforeId);
            }
            if (0 != ix)
            {
                Values[ix - 1].BucketAfterId = current.BucketBeforeId;
                Values[ix - 1].BucketAfter   = current.BucketBefore;
            }
            current.BucketBefore.EnsureValue(uid, keydata, data);
        }
Example #6
0
        /// <summary>
        /// Встраивает объект в родительский
        /// </summary>
        /// <param name="mediana"></param>
        private void StoreValueAfterSplit(BTreeValue <TKey, TKeyData, TData> mediana)
        {
            bool wasfull     = IsFull;
            int  insertIndex = -1;

            for (var i = 0; i < Values.Count; i++)
            {
                if (Values[i].Key.CompareTo(mediana.Key) > 0)
                {
                    insertIndex = i;
                    break;
                }
            }
            if (-1 == insertIndex)
            {
                insertIndex = Values.Count;
                Values.Add(mediana);
            }
            else
            {
                Values.Insert(insertIndex, mediana);
            }
            if (0 != insertIndex && Values[insertIndex - 1].BucketAfterId != mediana.BucketBeforeId)
            {
                Values[insertIndex - 1].BucketAfterId = mediana.BucketBeforeId;
                Values[insertIndex - 1].BucketAfter   = mediana.BucketBefore;
            }
            if (Values.Count - 1 != insertIndex && Values[insertIndex + 1].BucketBeforeId != mediana.BucketAfterId)
            {
                Values[insertIndex + 1].BucketBeforeId = mediana.BucketAfterId;
                Values[insertIndex + 1].BucketBefore   = mediana.BucketAfter;
            }

            if (wasfull)
            {
                DoSplit();
            }
        }