Skip to content

Commit 981e29a

Browse files
committed
fix:Couple of fixes for "rare" conditions.
1 parent f87edbd commit 981e29a

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

Java/TriesWithFrequencies/src/TrieFunctions.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,9 @@ public static Trie merge(Trie tr1, Trie tr2) {
151151

152152
} else if (!tr1.getKey().equals(tr2.getKey())) {
153153

154+
// This is wrong, but with this implementation is does not happen.
155+
// (Or at least has not been detected.)
156+
// With the tipycal trie creation with "" root, the merge in the next logical branch happens.
154157
res.getChildren().putAll(tr1.getChildren());
155158
res.getChildren().putAll(tr2.getChildren());
156159

@@ -300,7 +303,6 @@ public static List<List<String>> mapPosition(Trie tr, List<List<String>> words)
300303
//! @description Retrieval of a sub-trie corresponding to a "word".
301304
//! @param tr a trie object
302305
//! @param word a list of strings
303-
//! @param
304306
public static Trie retrieve(Trie tr, List<String> word) {
305307

306308
if (word == null || word.isEmpty()) {
@@ -987,12 +989,12 @@ public static Trie map( Trie tr, TrieNodeFunction preFunc, TrieNodeFunction pos
987989

988990
}
989991

992+
res.setChildren( resChildren );
993+
990994
if ( postFunc != null ) {
991995
res = postFunc.apply(res);
992996
}
993997

994-
res.setChildren( resChildren );
995-
996998
return res;
997999
}
9981000
}

0 commit comments

Comments
 (0)