private void InitNewRoot(T key) { root = new ABTreeNode <T>(this.maxChildren); root.keys.Add(key); root.accumulations.Add(new List <T>()); this.Count++; this.CountWithAccum++; }
/// <summary> /// Move accumulations to the empty right node when splitting. /// </summary> public void MoveAccumulations(ABTreeNode <TT> right, int startIndex) { for (int i = startIndex; i < this.accumulations.Count; i++) { right.accumulations.Add(this.accumulations[i]); } this.accumulations.RemoveRange(startIndex, this.accumulations.Count - startIndex); }
/// <summary> /// Move keys to the empty right node when spliting. /// </summary> public void MoveKeys(ABTreeNode <TT> right, int startIndex) { for (int i = startIndex; i < this.keys.Count; i++) { right.keys.Add(this.keys[i]); } this.keys.RemoveRange(startIndex, this.keys.Count - startIndex); }
/// <summary> /// Inserts key into the tree. /// If it already contains the key, the key is not inserted. /// </summary> /// <param name="key"> A key to insert into the tree.</param> public void Insert(T key) { ABTreeNode <T> node = null; if (root == null) { InitNewRoot(key); } // The key was found => no insertion. else if ((node = FindLeafNode(key, out int pos)) == null) { return; }
/// <summary> /// Expects that this function is called only when adding new child to a parent after split occurs. /// Otherwise, it will throw null ptr exception. /// </summary> public void InsertBranch(int i, TT value, List <TT> accs, ABTreeNode <TT> child) { child.parent = this; this.keys.Insert(i, value); this.accumulations.Insert(i, accs); this.children.Insert(i + 1, child); // Reset the values of indeces inside. for (int j = i + 1; j < this.children.Count; j++) { this.children[j].index = j; } }
/// <summary> /// Move children to the empty right node when spliting. /// When moving children, it is important not to forget /// seting their new parent and theri new indeces as they occur in the parent's children array. /// </summary> public void MoveChildren(ABTreeNode <TT> right, int startIndex) { ABTreeNode <TT> child = null; int j = 0; for (int i = startIndex; i < this.children.Count; i++) { child = this.children[i]; child.parent = right; child.index = j; right.children.Add(child); j++; } this.children.RemoveRange(startIndex, this.children.Count - startIndex); }
private void InitNewRoot(T key) { root = new ABTreeNode <T>(this.maxChildren); root.keys.Add(key); this.Count++; }