@@ -20,9 +20,9 @@ A second order B-Tree with keys from 1 to 20 looks like this:
2020
2121``` swift
2222class BTreeNode <Key : Comparable , Value > {
23- unowned var ownerTree : BTree<Key , Value >
23+ unowned var owner : BTree<Key , Value >
2424
25- private var keys = [Key ]()
25+ fileprivate var keys = [Key ]()
2626 var children: [BTreeNode]?
2727
2828 ...
@@ -55,7 +55,7 @@ This is necessary because nodes have to know the order of the tree.
5555
5656### The code
5757
58- ` valueForKey(_ :)` method searches for the given key and if it's in the tree,
58+ ` value(for :)` method searches for the given key and if it's in the tree,
5959it returns the value associated with it, else it returns ` nil ` .
6060
6161## Insertion
@@ -72,7 +72,7 @@ Keys can only be inserted to leaf nodes.
7272After insertion we should check if the number of keys in the node is in the correct range.
7373If there are more keys in the node than ` order*2 ` , we need to split the node.
7474
75- ####Splitting a node
75+ #### Splitting a node
7676
77771 . Move up the middle key of the node we want to split, to its parent (if it has one).
78782 . If it hasn't got a parent(it is the root), then create a new root and insert to it.
@@ -90,9 +90,9 @@ An insertion to a first order tree looks like this:
9090
9191### The code
9292
93- The method ` insertValue (_:forKey :)` does the insertion.
93+ The method ` insert (_:for :)` does the insertion.
9494After it has inserted a key, as the recursion goes up every node checks the number of keys in its child.
95- if a node has too many keys, its parent calls the ` splitChild(_ :atIndex:)` method on it.
95+ if a node has too many keys, its parent calls the ` split(child :atIndex:)` method on it.
9696
9797The root node is checked by the tree itself.
9898If the root has too many nodes after the insertion the tree calls the ` splitRoot() ` method.
@@ -112,7 +112,7 @@ After a key have been removed from a node we should check that the node has enou
112112If a node has fewer keys than the order of the tree, then we should move a key to it,
113113or merge it with one of its siblings.
114114
115- ####Moving a key to the child
115+ #### Moving a key to the child
116116
117117If the problematic node has a nearest sibling that has more keys than the order of the tree,
118118we should perform this operation on the tree, else we should merge the node with one of its siblings.
@@ -156,13 +156,13 @@ so in the worst case merging also can go up to the root, in which case the heigh
156156
157157### The code
158158
159- - ` removeKey (_:)` method removes the given key from the tree. After a key has been deleted,
159+ - ` remove (_:)` method removes the given key from the tree. After a key has been deleted,
160160 every node checks the number of keys in its child. If a child has less nodes than the order of the tree,
161- it calls the ` fixChildWithLessNodesThanOrder(_ :atIndex:)` method.
161+ it calls the ` fix(childWithTooFewKeys :atIndex:)` method.
162162
163- - ` fixChildWithLessNodesThanOrder(_ :atIndex:)` method decides which way to fix the child (by moving a key to it,
164- or by merging it), then calls ` moveKeyAtIndex(keyIndex:toNode:fromNode:atPosition :)` or
165- ` mergeChild(_:withIndex:toNodeAtPosition :)` method according to its choice.
163+ - ` fix(childWithTooFewKeys :atIndex:)` method decides which way to fix the child (by moving a key to it,
164+ or by merging it), then calls ` move(keyAtIndex:to:from:at :)` or
165+ ` merge(child:atIndex:to :)` method according to its choice.
166166
167167## See also
168168
0 commit comments