Exemplo n.º 1
0
 /// <summary>コンストラクタ。</summary>
 /// <param name="bracketSize">領域サイズ。</param>
 public BLeaf(int bracketSize)
 {
     this.Count       = 0;
     this.PreviewLeaf = null;
     this.NextLeaf    = null;
     this.value       = new T[bracketSize];
 }
Exemplo n.º 2
0
 /// <summary>コンストラクタ(列挙を特定の位置より始める場合)</summary>
 /// <param name="parent">B+木コレクション。</param>
 /// <param name="leaf">葉要素。</param>
 /// <param name="index">開始位置。</param>
 public BPlusEnumerator(BPlusTree <T> parent, BLeaf leaf, int index)
 {
     this.parent  = parent;
     this.curleaf = leaf;
     this.ptridx  = -1;
     this.started = index;
 }
Exemplo n.º 3
0
 /// <summary>コンストラクタ。</summary>
 /// <param name="parent">B+木コレクション。</param>
 public BPlusEnumerator(BPlusTree <T> parent)
 {
     this.parent  = parent;
     this.curleaf = parent.start;
     this.ptridx  = -1;
     this.started = 0;
 }
 /// <summary>コンストラクタ。</summary>
 /// <param name="bracket">領域サイズ。</param>
 /// <param name="leftItem">左辺値。</param>
 /// <param name="rightItem">右辺値。</param>
 public BBranch(int bracket, IBParts leftItem, IBParts rightItem)
 {
     this.value      = new IBParts[bracket];
     this.Count      = 2;
     this.value[0]   = leftItem;
     this.value[1]   = rightItem;
     this.headerLeaf = this.TraverseLeaf;
 }
Exemplo n.º 5
0
            /// <summary>指定要素の項目を取り込む。</summary>
            /// <param name="other">取り込む要素。</param>
            public void MargeParts(IBParts other)
            {
                var leaf = other as BPlusTree <T> .BLeaf;

                Array.Copy(leaf.value, 0, this.value, this.Count, leaf.Count);
                this.Count   += leaf.Count;
                this.NextLeaf = leaf.NextLeaf;
                if (leaf.NextLeaf != null)
                {
                    leaf.NextLeaf.PreviewLeaf = this;
                }
            }
Exemplo n.º 6
0
            /// <summary>葉要素の分割を行う。</summary>
            /// <param name="item">追加する要素。</param>
            /// <param name="idx">追加位置。</param>
            /// <param name="parent">木構造。</param>
            /// <param name="manage">処理状態。</param>
            private void Split(T item, int idx, BPlusTree <T> parent, ref ManageResult manage)
            {
                var tmpNext = new BLeaf(parent.bracketSize);

                if (idx < parent.mSize + 1)
                {
                    // 後半部分はコピー
                    tmpNext.Count = parent.mSize + 1;
                    Array.Copy(this.value, parent.mSize, tmpNext.value, 0, parent.mSize + 1);

                    // 前半部は挿入
#if DEBUG
                    Array.Clear(this.value, parent.mSize, this.value.Length - parent.mSize);
#endif
                    this.Count = parent.mSize + 1;
                    if (parent.mSize + 1 > idx)
                    {
                        Array.Copy(this.value, idx, this.value, idx + 1, (parent.mSize + 1) - idx);
                    }
                    this.value[idx] = item;
                }
                else
                {
                    // 後半部分に挿入
                    int ptr = idx - (parent.mSize + 1);
                    tmpNext.Count = parent.mSize + 1;
                    if (ptr > 0)
                    {
                        Array.Copy(this.value, parent.mSize + 1, tmpNext.value, 0, ptr);
                    }
                    Array.Copy(this.value, idx, tmpNext.value, ptr + 1, parent.bracketSize - idx);
                    tmpNext.value[ptr] = item;

                    // 前半部分は変更なし
#if DEBUG
                    Array.Clear(this.value, parent.mSize + 1, this.value.Length - (parent.mSize + 1));
#endif
                    this.Count = parent.mSize + 1;
                }

                // 前後のリンクを設定
                tmpNext.NextLeaf = this.NextLeaf;
                if (this.NextLeaf != null)
                {
                    this.NextLeaf.PreviewLeaf = tmpNext;
                }
                this.NextLeaf       = tmpNext;
                tmpNext.PreviewLeaf = this;

                // 新しく生成した要素を返す
                manage.newParts = tmpNext;
            }
 /// <summary>ルート要素の再設定。</summary>
 private void RelinkRoot()
 {
     if (this.root.Count <= 1)
     {
         var parts = this.root.FirstParts;
         if (parts is BBranch)
         {
             this.root = (BBranch)parts;
         }
         else
         {
             this.root  = null;
             this.start = (BLeaf)parts;
         }
     }
 }
Exemplo n.º 8
0
 /// <summary>列挙子を次の要素へ進める。</summary>
 /// <returns>進める要素があれば真。</returns>
 public bool MoveNext()
 {
     if (this.ptridx < 0)
     {
         this.ptridx = this.started;
         return(this.ptridx >= 0 && this.ptridx < this.curleaf.Count);
     }
     else if (this.ptridx < this.curleaf.Count - 1)
     {
         this.ptridx++;
         return(true);
     }
     else if (this.curleaf.NextLeaf != null)
     {
         this.curleaf = this.curleaf.NextLeaf;
         this.ptridx  = 0;
         return(true);
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 9
0
 /// <summary>列挙子を前の要素へ進める。</summary>
 /// <returns>進める要素があれば真。</returns>
 public bool MovePreviw()
 {
     if (this.ptridx < 0)
     {
         this.ptridx = this.started;
         return(this.ptridx >= 0 && this.ptridx < this.curleaf.Count);
     }
     else if (this.ptridx > 0)
     {
         this.ptridx--;
         return(true);
     }
     else if (this.curleaf.PreviewLeaf != null)
     {
         this.curleaf = this.curleaf.PreviewLeaf;
         this.ptridx  = this.curleaf.Count - 1;
         return(true);
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 10
0
 /// <summary>列挙子をコレクションの最初の要素の前に設定する。</summary>
 public void Reset()
 {
     this.curleaf = this.parent.start;
     this.ptridx  = -1;
     this.started = 0;
 }
Exemplo n.º 11
0
 /// <summary>コンストラクタ。</summary>
 /// <param name="leaf">対象の葉要素。</param>
 /// <param name="idx">インデックス。</param>
 public SearchResult(BLeaf leaf, int idx)
 {
     this.leaf  = leaf;
     this.index = idx;
 }
Exemplo n.º 12
0
 /// <summary>リストから全ての項目を削除します。</summary>
 public void Clear()
 {
     this.root  = null;
     this.start = new BLeaf(this.bracketSize);
 }