From 9f086ffc60a96dd2c31619b8fe21f9737b35cb7a Mon Sep 17 00:00:00 2001 From: Anton Antonov Date: Sat, 28 Jan 2017 22:07:31 -0500 Subject: [PATCH] Better shrinking. --- Java/TriesWithFrequencies/src/TrieFunctions.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Java/TriesWithFrequencies/src/TrieFunctions.java b/Java/TriesWithFrequencies/src/TrieFunctions.java index 365b1cf4..160ddf89 100644 --- a/Java/TriesWithFrequencies/src/TrieFunctions.java +++ b/Java/TriesWithFrequencies/src/TrieFunctions.java @@ -539,8 +539,10 @@ protected static Trie shrinkRec(Trie tr, String delimiter, double threshold, int List arr = new ArrayList(tr.getChildren().values()); boolean shrinkQ = false; - if (threshold < 0) { - shrinkQ = tr.getValue().equals( arr.get(0).getValue() ); + if (threshold < 0 && tr.getValue() >= 1.0 && arr.get(0).getValue() >= 1.0 ) { + shrinkQ = tr.getValue().equals(arr.get(0).getValue()); + } else if (threshold < 0 ) { + shrinkQ = arr.get(0).getValue() == 1.0 ; } else { shrinkQ = arr.get(0).getValue() >= threshold; }