/// <summary>指定要素の項目を取り込む。</summary>
            /// <param name="other">取り込む要素。</param>
            public void MargeParts(IBParts other)
            {
                var branch = (BPlusTree <T> .BBranch)other;

                Array.Copy(branch.value, 0, this.value, this.Count, branch.Count);
                this.Count += branch.Count;
            }
            /// <summary>同階層の要素内の項目数のバランスを取る。</summary>
            /// <param name="other">同階層の要素。</param>
            public void BalanceParts(IBParts other)
            {
                var branch = (BPlusTree <T> .BBranch)other;

                // 全体の項目数を取得
                int allCnt = this.Count + branch.Count;
                int hfcnt  = allCnt / 2;
                int spncnt;

                if (this.Count < hfcnt)
                {
                    // 左辺の項目が少ない
                    spncnt = hfcnt - this.Count;
                    Array.Copy(branch.value, 0, this.value, this.Count, spncnt);
                    Array.Copy(branch.value, spncnt, branch.value, 0, branch.Count - spncnt);
                    this.Count   = hfcnt;
                    branch.Count = allCnt - hfcnt;

                    // 検索キー参照変更
                    branch.headerLeaf = branch.TraverseLeaf;
                }
                else if (this.Count > hfcnt)
                {
                    // 右辺の項目が少ない
                    spncnt = this.Count - hfcnt;
                    Array.Copy(branch.value, 0, branch.value, spncnt, branch.Count);
                    Array.Copy(this.value, hfcnt, branch.value, 0, spncnt);
                    this.Count   = hfcnt;
                    branch.Count = allCnt - hfcnt;

                    // 検索キー参照変更
                    branch.headerLeaf = branch.TraverseLeaf;
                }
            }
 /// <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;
 }
Ejemplo n.º 4
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;
                }
            }
            /// <summary>枝要素の分割を行う。</summary>
            /// <param name="element">追加する要素。</param>
            /// <param name="idx">追加位置。</param>
            /// <param name="parent">木構造。</param>
            /// <param name="manage">処理結果。</param>
            private void Split(IBParts element, int idx, BPlusTree <T> parent, ref ManageResult manage)
            {
                var tmpNext = new BBranch(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] = element;
                }
                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] = element;

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

                // 検索キー参照変更
                tmpNext.headerLeaf = tmpNext.TraverseLeaf;

                // 新しく生成した要素を返す
                manage.newParts = tmpNext;
            }
Ejemplo n.º 6
0
            /// <summary>同階層の要素内の項目数のバランスを取る。</summary>
            /// <param name="other">同階層の要素。</param>
            public void BalanceParts(IBParts other)
            {
                var leaf = other as BPlusTree <T> .BLeaf;

                // 全体の項目数を取得
                int allCnt = this.Count + leaf.Count;
                int hfcnt  = allCnt / 2;
                int spncnt;

                if (this.Count < hfcnt)
                {
                    // 左辺の項目が少ない
                    spncnt = hfcnt - this.Count;
                    Array.Copy(leaf.value, 0, this.value, this.Count, spncnt);
                    Array.Copy(leaf.value, spncnt, leaf.value, 0, leaf.Count - spncnt);
                    this.Count = hfcnt;
                    leaf.Count = allCnt - hfcnt;
#if DEBUG
                    for (int i = leaf.Count; i < leaf.value.Length; ++i)
                    {
                        leaf.value[i] = default(T);
                    }
#endif
                }
                else if (this.Count > hfcnt)
                {
                    // 右辺の項目が少ない
                    spncnt = this.Count - hfcnt;
                    Array.Copy(leaf.value, 0, leaf.value, spncnt, leaf.Count);
                    Array.Copy(this.value, hfcnt, leaf.value, 0, spncnt);
                    this.Count = hfcnt;
                    leaf.Count = allCnt - hfcnt;
#if DEBUG
                    for (int i = this.Count; i < this.value.Length; ++i)
                    {
                        this.value[i] = default(T);
                    }
#endif
                }
            }