Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
p2-public
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cse332-23au
p2-public
Commits
cfa66f82
Commit
cfa66f82
authored
3 years ago
by
@thx
Browse files
Options
Downloads
Patches
Plain Diff
Refactor to Java Map-based HashTrieNode
parent
3e8e0589
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/datastructures/dictionaries/HashTrieMap.java
+7
-14
7 additions, 14 deletions
src/main/java/datastructures/dictionaries/HashTrieMap.java
src/main/java/p2/wordcorrector/AutocompleteTrie.java
+6
-8
6 additions, 8 deletions
src/main/java/p2/wordcorrector/AutocompleteTrie.java
with
13 additions
and
22 deletions
src/main/java/datastructures/dictionaries/HashTrieMap.java
+
7
−
14
View file @
cfa66f82
package
datastructures.dictionaries
;
import
cse332.datastructures.containers.Item
;
import
cse332.exceptions.NotYetImplementedException
;
import
cse332.interfaces.misc.Dictionary
;
import
cse332.interfaces.misc.SimpleIterator
;
import
cse332.interfaces.trie.TrieMap
;
import
cse332.types.BString
;
import
java.util.
AbstractMap.SimpleEntry
;
import
java.util.
HashMap
;
import
java.util.Iterator
;
import
java.util.Map
;
import
java.util.Map.Entry
;
import
java.util.function.Supplier
;
/**
* See cse332/interfaces/trie/TrieMap.java
...
...
@@ -18,27 +15,23 @@ import java.util.function.Supplier;
* for method specifications.
*/
public
class
HashTrieMap
<
A
extends
Comparable
<
A
>,
K
extends
BString
<
A
>,
V
>
extends
TrieMap
<
A
,
K
,
V
>
{
public
class
HashTrieNode
extends
TrieNode
<
Dictionary
<
A
,
HashTrieNode
>,
HashTrieNode
>
{
public
class
HashTrieNode
extends
TrieNode
<
Map
<
A
,
HashTrieNode
>,
HashTrieNode
>
{
public
HashTrieNode
()
{
this
(
null
);
}
public
HashTrieNode
(
V
value
)
{
this
.
pointers
=
new
ChainingHashTable
<
A
,
HashTrieNode
>(
new
Supplier
<
Dictionary
<
A
,
HashTrieNode
>>()
{
@Override
public
Dictionary
<
A
,
HashTrieNode
>
get
()
{
return
new
MoveToFrontList
<>();
}
});
this
.
pointers
=
new
HashMap
<>();
this
.
value
=
value
;
}
@Override
public
Iterator
<
Entry
<
A
,
HashTrieNode
>>
iterator
()
{
throw
new
NotYetImplementedException
();
public
Iterator
<
Entry
<
A
,
HashTrieMap
<
A
,
K
,
V
>.
HashTrieNode
>>
iterator
()
{
return
pointers
.
entrySet
().
iterator
();
}
}
public
HashTrieMap
(
Class
<
K
>
KClass
)
{
super
(
KClass
);
throw
new
NotYetImplementedException
();
...
...
This diff is collapsed.
Click to expand it.
src/main/java/p2/wordcorrector/AutocompleteTrie.java
+
6
−
8
View file @
cfa66f82
package
p2.wordcorrector
;
import
cse332.types.AlphabeticString
;
import
datastructures.dictionaries.HashTrieMap
;
import
java.util.Map.Entry
;
public
class
AutocompleteTrie
extends
HashTrieMap
<
Character
,
AlphabeticString
,
Integer
>
{
public
AutocompleteTrie
()
{
...
...
@@ -16,10 +13,12 @@ public class AutocompleteTrie extends HashTrieMap<Character, AlphabeticString, I
@SuppressWarnings
(
"unchecked"
)
HashTrieNode
current
=
(
HashTrieNode
)
this
.
root
;
for
(
Character
item
:
key
.
toCharArray
())
{
current
=
current
.
pointers
.
find
(
item
);
if
(
current
==
null
)
{
if
(!
current
.
pointers
.
containsKey
(
item
))
{
return
null
;
}
else
{
current
=
current
.
pointers
.
get
(
item
);
}
}
String
result
=
key
;
...
...
@@ -28,9 +27,8 @@ public class AutocompleteTrie extends HashTrieMap<Character, AlphabeticString, I
if
(
current
.
value
!=
null
)
{
return
null
;
}
Entry
<
Character
,
HashTrieNode
>
next
=
current
.
iterator
().
next
();
result
+=
next
.
getKey
();
current
=
next
.
getValue
();
result
+=
current
.
pointers
.
keySet
().
iterator
().
next
();
current
=
current
.
pointers
.
values
().
iterator
().
next
();
}
// Switch this to return null to only complete if we're at the end of
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment