From 0aab35f3265a98ab9d84281d03c72d0f91e74bc1 Mon Sep 17 00:00:00 2001 From: fadi zaraket Date: Mon, 30 Jul 2018 19:56:53 +0300 Subject: [PATCH] fix: bug - add 'x' then add 'xc' Then you hit the "assert getBase(state) >= 0;" assertion because getBase(0+x) will be LEAF_BASE_VALUE which is -2 when you are trying to insert 'xc' and you are now reading 'c' from string. --- .../datrie/AbstractDoubleArrayTrie.java | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/main/org/digitalstain/datrie/AbstractDoubleArrayTrie.java b/src/main/org/digitalstain/datrie/AbstractDoubleArrayTrie.java index 7b748ef..9abf4e9 100644 --- a/src/main/org/digitalstain/datrie/AbstractDoubleArrayTrie.java +++ b/src/main/org/digitalstain/datrie/AbstractDoubleArrayTrie.java @@ -99,8 +99,25 @@ public boolean addToTrie(IntegerList string) { // For every input character while (i < string.size()) { assert state >= 0; - assert getBase(state) >= 0; - c = string.get(i); + //assert getBase(state) >= 0; + //c = string.get(i); + //FZ: the following asserttion will fire in case we inserted "a" and + // then "ab" since inserting "a" will result in base('a') to be set to + // LEAF_BASE_VALUE which is -1 + //assert getBase(state) >= 0; + //FZ: thus the following fix. + c = string.get(i); + int stateBase = getBase(state); + + if (i>0 && stateBase == LEAF_BASE_VALUE) { + setBase(transition, nextAvailableHop(c)); // Add a state + changed = true; + } else { + assert getBase(state) >= 0; + } + //FZ: end of fix. + + // Calculate next hop. It is the base contents of the current state // plus the input character. transition = getBase(state) + c;