MCPcopy Create free account
hub / github.com/TheAlgorithms/Go / Insert

Method Insert

structure/tree/btree.go:178–194  ·  view source on GitHub ↗
(key T)

Source from the content-addressed store, hash-verified

176}
177
178func (tree *BTree[T]) Insert(key T) {
179 if tree.root == nil {
180 tree.root = NewBTreeNode[T](tree.maxKeys, true)
181 tree.root.keys[0] = key
182 tree.root.numKeys = 1
183 return
184 }
185
186 if tree.root.IsFull(tree.maxKeys) {
187 newRoot := NewBTreeNode[T](tree.maxKeys, false)
188 newRoot.numKeys = 0
189 newRoot.children[0] = tree.root
190 newRoot.Split(0, tree.maxKeys)
191 tree.root = newRoot
192 }
193 tree.root.InsertNonFull(tree, key)
194}
195
196func (node *BTreeNode[T]) DeleteIthKey(i int) {
197 if i >= node.numKeys {

Callers

nothing calls this directly

Calls 3

SplitMethod · 0.80
InsertNonFullMethod · 0.80
IsFullMethod · 0.45

Tested by

no test coverage detected