File tree Expand file tree Collapse file tree 1 file changed +22
-2
lines changed Expand file tree Collapse file tree 1 file changed +22
-2
lines changed Original file line number Diff line number Diff line change 8
8
9
9
import Foundation
10
10
11
+ /**
12
+ This class represents a node in the Ternary Search Tree.
13
+ A node has two main data members, the key and the data.
14
+ All nodes in a TST must have keys, but only some will have data.
15
+ This can be seen in the way the data variable is of Optional type.
16
+ */
11
17
class TSTNode < Element> {
12
18
//Member properties of a particular node.
19
+
20
+ /// The key that identifies this node.
13
21
var key : Character
22
+ /// The data stored in this node. May be `nil`
14
23
var data : Element ?
24
+ /// Boolean flag to depict whether this node holds data or not.
15
25
var hasData : Bool
16
26
17
- //Children
27
+ /// The children of this node
18
28
var left : TSTNode ? , right : TSTNode ? , middle : TSTNode ?
19
29
20
-
30
+ /**
31
+ Initializer for key and/or data
32
+
33
+ - parameter key: The key to set for this node.
34
+ - parameter data: The optional data to set in this node.
35
+ */
21
36
init ( key: Character , data: Element ? ) {
22
37
self . key = key
23
38
self . data = data
24
39
self . hasData = ( data != nil )
25
40
}
26
41
42
+ /**
43
+ Make a node that only has a key
44
+
45
+ - parameter key: The key to ascribe to this node.
46
+ */
27
47
init ( key: Character ) {
28
48
self . key = key
29
49
self . data = nil
You can’t perform that action at this time.
0 commit comments