Issue #1353. fixed growable Trie
This commit is contained in:
parent
08f67ca434
commit
1361b31beb
|
@ -630,15 +630,16 @@ public class ArrayTernaryTrie<V> extends AbstractTrie<V>
|
|||
public boolean put(String s, V v)
|
||||
{
|
||||
boolean added = _trie.put(s,v);
|
||||
while (!added)
|
||||
while (!added && _growby>0)
|
||||
{
|
||||
ArrayTernaryTrie<V> bigger = new ArrayTernaryTrie<>(_trie._key.length+_growby);
|
||||
for (Map.Entry<String,V> entry : _trie.entrySet())
|
||||
bigger.put(entry.getKey(),entry.getValue());
|
||||
_trie = bigger;
|
||||
added = _trie.put(s,v);
|
||||
}
|
||||
|
||||
return true;
|
||||
return added;
|
||||
}
|
||||
|
||||
public V get(String s, int offset, int len)
|
||||
|
|
|
@ -180,8 +180,7 @@ public class ClasspathPattern extends AbstractSet<String>
|
|||
if (_entries.get(name)!=null)
|
||||
return false;
|
||||
|
||||
_entries.put(name,entry);
|
||||
return true;
|
||||
return _entries.put(name,entry);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -228,4 +228,21 @@ public class ClasspathPatternTest
|
|||
assertThat(pattern.match(JDK.class),is(true));
|
||||
assertThat(pattern.match(ClasspathPatternTest.class),is(false));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testLarge()
|
||||
{
|
||||
ClasspathPattern pattern = new ClasspathPattern();
|
||||
for (int i=0; i<500; i++)
|
||||
{
|
||||
assertTrue(pattern.add("n"+i+"."+Integer.toHexString(100+i)+".Name"));
|
||||
}
|
||||
|
||||
for (int i=0; i<500; i++)
|
||||
{
|
||||
assertTrue(pattern.match("n"+i+"."+Integer.toHexString(100+i)+".Name"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue