@@ -20,9 +20,9 @@ A second order B-Tree with keys from 1 to 20 looks like this:
20
20
21
21
``` swift
22
22
class BTreeNode <Key : Comparable , Value > {
23
- unowned var ownerTree : BTree<Key , Value >
23
+ unowned var owner : BTree<Key , Value >
24
24
25
- private var keys = [Key ]()
25
+ fileprivate var keys = [Key ]()
26
26
var children: [BTreeNode]?
27
27
28
28
...
@@ -55,7 +55,7 @@ This is necessary because nodes have to know the order of the tree.
55
55
56
56
### The code
57
57
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,
59
59
it returns the value associated with it, else it returns ` nil ` .
60
60
61
61
## Insertion
@@ -72,7 +72,7 @@ Keys can only be inserted to leaf nodes.
72
72
After insertion we should check if the number of keys in the node is in the correct range.
73
73
If there are more keys in the node than ` order*2 ` , we need to split the node.
74
74
75
- ####Splitting a node
75
+ #### Splitting a node
76
76
77
77
1 . Move up the middle key of the node we want to split, to its parent (if it has one).
78
78
2 . 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:
90
90
91
91
### The code
92
92
93
- The method ` insertValue (_:forKey :)` does the insertion.
93
+ The method ` insert (_:for :)` does the insertion.
94
94
After 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.
96
96
97
97
The root node is checked by the tree itself.
98
98
If 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
112
112
If a node has fewer keys than the order of the tree, then we should move a key to it,
113
113
or merge it with one of its siblings.
114
114
115
- ####Moving a key to the child
115
+ #### Moving a key to the child
116
116
117
117
If the problematic node has a nearest sibling that has more keys than the order of the tree,
118
118
we 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
156
156
157
157
### The code
158
158
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,
160
160
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.
162
162
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.
166
166
167
167
## See also
168
168
0 commit comments