286
правок
Изменения
Нет описания правки
'''bool''' insert(T: '''BPlusTree''', key: '''int''', value: '''Info'''):
leaf = find_key(T, key)
'''for''' i = 0 '''to''' leaf.key_num '''if''' key <tex>\in</tex> == leaf.key[i] '''return false''' pos = 0
'''while''' pos < leaf.key_num '''and''' leaf.key[pos] < key
++pos
++leaf.key_num
'''if''' leaf.key_num == 2 * t <span style="color:#008000"> // t {{---}} степень дерева</span>
split(T, leaf) <span style="color:#008000"> // Разбиваем узел</span>
'''void''' split(T: '''BPlusTree''', node: '''Node'''):
new_node = new_Node() <span style="color:#008000"> //Создаем новый узел </span> new_node.right = node.right Перенаправляем node.right и .left указатели, вставляя его между node и = new_node node.right= new_node new_node.left = node
mid_key = node.key[t]
new_node.key_num = t - 1
'''for''' i = 0 '''to''' new_node.key_num - 1 new_node.key[i] = node.key[i + t + 1] new_node.pointers[i] = node.pointers[i + t - + 1] new_node.child[i] = node.child[i + t + 1 ] new_node.child[new_node.key_num] = node.child[2 * t]
node.key_num = t
'''if''' node.leaf
++new_node.key_num
new_node.leaf = '''true'''
'''if''' node == T.root
T.root.key[0] = mid_key
T.root.child[0] = node
new_node.parent = node.parent
parent = node.parent
pos = 0
'''while''' pos < parent.key_num '''and''' parent.key[pos] < mid_key
++pos
++parent.key_num
'''if''' parent.key_num == 2 * t <span style="color:#008000"> // Если требуется, продолжаем разбиение узла</span>
split(T, parent)
leaf = find_key(T, key)
pos = 0
'''while''' pos < leaf.key_num '''and''' leaf.key[pos] < key ++pos '''if''' pos == leaf.key_num '''or''' leaf.key [pos] <tex>\notinneq</tex> leafkey '''return false'''
'''else'''
delete_in_node(leaf, key) <span style="color:#008000"> // Удалить ключ из вершины</span>
'''return true'''
'''while''' pos < tec.key_num '''and''' tec.key[pos] < key
++pos
'''if''' pos == tec.key_num '''or''' tec.key [pos] <tex>\notinneq</tex> teckey '''return''' Удаляем '''for''' i = pos '''to''' tec.key_num - 1 tec.key[i] = tec.key из [i + 1] tec.pointers[i] = tec.pointer[i + 1] '''for''' i = pos + 1 '''to''' tec.key_num tec.child[i] = tec.child[i + 1]
--tec.key_num
--left_sibling.key_num
++tec.key_num
'''else if''' right_sibling <tex>\neq</tex> null '''and''' right_sibling.key_num > t - 1
--right_sibling.key_num
++tec.key_num
'''else'''
'''if''' left_sibling <tex>\neq</tex> null
'''else'''
delete_in_node(tec.parent, min_key(right_sibling))
T.root = T.root.child[0]