@@ -25,28 +25,33 @@ public final class PatriciaTrie {
25
25
/**
26
26
* Represents a node in the Patricia Trie.
27
27
* All nodes are internal nodes that store the key data at the point of creation,
28
- * and their ` bitNumber` indicates the bit position to check when traversing.
28
+ * and their {@code bitNumber} indicates the bit position to check when traversing.
29
29
*/
30
30
private static class PatriciaTrieNode {
31
31
/**
32
- * The bit index (1-indexed from MSB) to check for branching at this node.
33
- * The index must be greater than that of the parent node.
32
+ * The bit index (1-indexed from MSB, 1 to 32 ) to check for branching at this node.
33
+ * The index must be greater than that of the parent node. A value of 0 is used for the root.
34
34
*/
35
35
int bitNumber ;
36
36
/**
37
- * The integer key stored at this node. This is the **data** that was inserted
38
- * to create this node and acts as a placeholder or final result during search .
37
+ * The integer key stored at this node. This key is used for the final comparison
38
+ * after traversing the trie structure to determine if the key exists .
39
39
*/
40
40
int key ;
41
41
/**
42
- * Pointer to the next node if the current bit is 0.
42
+ * Pointer to the next node if the current bit being examined is 0.
43
43
*/
44
44
PatriciaTrieNode leftChild ;
45
45
/**
46
- * Pointer to the next node if the current bit is 1.
46
+ * Pointer to the next node if the current bit being examined is 1.
47
47
*/
48
48
PatriciaTrieNode rightChild ;
49
49
50
+ /**
51
+ * Constructs a new PatriciaTrieNode.
52
+ * @param bitNumber The bit index for comparison at this node.
53
+ * @param key The integer key associated with this node.
54
+ */
50
55
PatriciaTrieNode (int bitNumber , int key ) {
51
56
this .bitNumber = bitNumber ;
52
57
this .key = key ;
@@ -170,6 +175,8 @@ private PatriciaTrieNode insert(PatriciaTrieNode t, int element) {
170
175
171
176
// 3. Check for Duplicates
172
177
if (element == lastNode .key ) {
178
+ // Note: Printing to stdout within a core algorithm method is generally discouraged
179
+ // but is kept here for informational context during the insertion process.
173
180
System .out .println ("Key " + element + " already present." );
174
181
return t ;
175
182
}
0 commit comments