Skip to content

Commit

Permalink
Full signature implementation of JavaTrieFunctions`insert.
Browse files Browse the repository at this point in the history
  • Loading branch information
antononcube committed Nov 8, 2017
1 parent 0a83b3f commit 577d6c7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
10 changes: 6 additions & 4 deletions Java/TriesWithFrequencies/src/TrieFunctions.java
Original file line number Diff line number Diff line change
Expand Up @@ -192,16 +192,18 @@ public static Trie merge(Trie tr1, Trie tr2) {

//! @description Inserts a "word" (a list of strings) into a trie.
public static Trie insert(Trie tr, List<String> word) {
return insert(tr, word, null);
return insert(tr, word, null, null );
}

//! @description Inserts a "word" (a list of strings) into a trie with a given associated value.
public static Trie insert(Trie tr, List<String> word, Double value) {
public static Trie insert(Trie tr, List<String> word, Double value, Double bottomVal ) {

if (value == null) {
if (value == null && bottomVal == null ) {
return merge(tr, make(word, 1.0, null));
} else if( bottomVal == null ) {
return merge(tr, make(word, value, null));
} else {
return merge(tr, make(word, 0.0, value));
return merge(tr, make(word, value, bottomVal));
}
}

Expand Down
6 changes: 6 additions & 0 deletions JavaTriesWithFrequencies.m
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,12 @@ Mathematica is (C) Copyright 1988-2017 Wolfram Research, Inc.
JavaTrieInsert[jTr_?JavaObjectQ, word : {_String ..}] :=
TrieFunctions`insert[jTr, Arrays`asList[MakeJavaObject[word]]];

JavaTrieInsert[jTr_?JavaObjectQ, word : {_String ..}, val_?NumericQ] :=
TrieFunctions`insert[jTr, Arrays`asList[JLink`MakeJavaObject[word]], JLink`MakeJavaObject[N[val]], JLink`MakeJavaObject[Null]];

JavaTrieInsert[jTr_?JavaObjectQ, word : {_String ..}, val_?NumericQ, bottomVal_?NumberQ] :=
TrieFunctions`insert[jTr, Arrays`asList[JLink`MakeJavaObject[word]], JLink`MakeJavaObject[N[val]], JLink`MakeJavaObject[N[bottomVal]]];

JavaTrieInsert[jTr_?JavaObjectQ, words : {{_String ..} ..}] :=
Block[{jTr2},
jTr2 = JavaTrieCreate[words];
Expand Down

0 comments on commit 577d6c7

Please sign in to comment.