Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Containers-Trie/CTOptimizedTrieNode.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
I am the node of a optimized Trie node, I have the children in an array as pairs.
I am used inside a CTOptimizedTrie
The first element is the key and the second the node.
This nodes have a string as a key, not a single character.
These nodes have a string as a key, not a single character.

My users should use:

- #findChildWithString: to get my subnode that aplies to the given string, nil if there is not node.
- #findChildWithString:storingAncestors:adding: to get my subnode that aplies to the given string, nil if there is not node. If the node does not exists, it will be added depending of the adding parameter. Also it will store the ancestors passed to reach the final node.
- #findChildWithString: to get my subnode that applies to the given string, nil if there is no node.
- #findChildWithString:storingAncestors:adding: to get my subnode that applies to the given string, nil if there is no node. If the node does not exist, it will be added depending on the adding parameter. Also it will store the ancestors passed to reach the final node.
- #removeNode: Removes a node from my self.
- #withAllChildrenDo: iterates over me and my children.

Expand Down
12 changes: 6 additions & 6 deletions src/Containers-Trie/CTTrie.class.st
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"
A tree for storing strings in which there is one node for every common prefix. The strings (words) are *usually* stored in extra leaf nodes. The root of a Trie can be recognized by the fact that its character instance variable is <nil>. Words can be determined by the fact that the node completing the word has a nodeValue. Note that a word does not have to be found at a leaf node (e.g. the word ""in"", see Wipidedia example at link given below).
A tree for storing strings in which there is one node for every common prefix. The strings (words) are *usually* stored in extra leaf nodes. The root of a Trie can be recognized by the fact that its character instance variable is <nil>. Words can be determined by the fact that the node completing the word has a nodeValue. Note that a word does not have to be found at a leaf node (e.g. the word ""in"", see Wikipedia example at link given below).

See <http://en.wikipedia.org/wiki/Trie> for more details.

Expand Down Expand Up @@ -30,7 +30,7 @@ CTTrie class >> readFromFile: anObject [
{ #category : #'instance creation - bulk' }
CTTrie class >> readFromFile: anObject withLineTransformer: aBlock [
"A utility method that allows to bulk load a file containing one word per line and add them all to a trie structure.
aBlock allows one to convert the line before inserting it in the trie (for example one can convert it as lowercase)."
aBlock allows one to convert the line before inserting it in the trie (for example one can convert it to lowercase)."

| aTrie fileReference |

Expand Down Expand Up @@ -85,11 +85,11 @@ CTTrie >> add: aString value: anObject [
]

{ #category : #accessing }
CTTrie >> at: aString update: updateBlock initial: initBlocktOrValue [
CTTrie >> at: aString update: updateBlock initial: initBlockOrValue [
"I am used to update the value at a given key. The updateBlock is passed
the existing value, and the result of the block is stored back.
If the key does not exist, store the value of the initBlocktOrValue.
initBlocktOrValue can be a block in case the initial value is expencive to compute."
If the key does not exist, store the value of the initBlockOrValue.
initBlockOrValue can be a block in case the initial value is expensive to compute."

| currentNode ancestors |
currentNode := root.
Expand All @@ -105,7 +105,7 @@ CTTrie >> at: aString update: updateBlock initial: initBlocktOrValue [
ifFalse: [ currentNode addChildWithLetter: each ] ].

[currentNode nodeValue: (currentNode nodeValue
ifNil: [ initBlocktOrValue value ]
ifNil: [ initBlockOrValue value ]
ifNotNil: [ :previousValue | updateBlock cull: previousValue])] ensure: [
self compressNode: currentNode ancestors: ancestors].

Expand Down