Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
cs2-19wi
project06
Commits
2b7bc29d
Commit
2b7bc29d
authored
6 years ago
by
Adam Blank
Browse files
Options
Download
Email Patches
Plain Diff
Update AutoCompleteTrie.java
parent
85deb9ee
master
No related merge requests found
Pipeline
#7789
canceled with stage
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/wordcorrector/AutoCompleteTrie.java
+28
-0
src/wordcorrector/AutoCompleteTrie.java
with
28 additions
and
0 deletions
+28
-0
src/wordcorrector/AutoCompleteTrie.java
View file @
2b7bc29d
package
wordcorrector
;
import
edu.caltech.cs2.datastructures.IterableString
;
import
edu.caltech.cs2.datastructures.LinkedDeque
;
import
edu.caltech.cs2.datastructures.TrieMap
;
import
edu.caltech.cs2.interfaces.IDeque
;
import
java.io.File
;
import
java.io.FileNotFoundException
;
import
java.util.Iterator
;
import
java.util.Scanner
;
import
java.util.function.Function
;
...
...
@@ -46,6 +49,31 @@ public class AutoCompleteTrie extends TrieMap<Character, IterableString, Integer
return
characters
;
}
protected
TrieNode
<
Character
,
Integer
>
followKey
(
IterableString
key
)
{
Iterator
<
Character
>
letters
=
key
.
iterator
();
TrieNode
<
Character
,
Integer
>
current
=
this
.
root
;
while
(
letters
.
hasNext
())
{
Character
letter
=
letters
.
next
();
if
(!
current
.
pointers
.
containsKey
(
letter
))
{
return
null
;
}
current
=
current
.
pointers
.
get
(
letter
);
}
return
current
;
}
protected
void
getKeys
(
TrieNode
<
Character
,
Integer
>
current
,
IDeque
<
Character
>
keySoFar
,
IDeque
<
IterableString
>
keys
)
{
if
(
current
.
value
!=
null
)
{
keys
.
add
(
super
.
collector
.
apply
(
keySoFar
));
}
for
(
Character
letter
:
current
.
pointers
.
keySet
())
{
keySoFar
.
addBack
(
letter
);
getKeys
(
current
.
pointers
.
get
(
letter
),
keySoFar
,
keys
);
keySoFar
.
removeBack
();
}
}
/**
* Retrieves keys that have the given key as a prefix
*/
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help