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)
|
public boolean put(String s, V v)
|
||||||
{
|
{
|
||||||
boolean added = _trie.put(s,v);
|
boolean added = _trie.put(s,v);
|
||||||
while (!added)
|
while (!added && _growby>0)
|
||||||
{
|
{
|
||||||
ArrayTernaryTrie<V> bigger = new ArrayTernaryTrie<>(_trie._key.length+_growby);
|
ArrayTernaryTrie<V> bigger = new ArrayTernaryTrie<>(_trie._key.length+_growby);
|
||||||
for (Map.Entry<String,V> entry : _trie.entrySet())
|
for (Map.Entry<String,V> entry : _trie.entrySet())
|
||||||
bigger.put(entry.getKey(),entry.getValue());
|
bigger.put(entry.getKey(),entry.getValue());
|
||||||
|
_trie = bigger;
|
||||||
added = _trie.put(s,v);
|
added = _trie.put(s,v);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return added;
|
||||||
}
|
}
|
||||||
|
|
||||||
public V get(String s, int offset, int len)
|
public V get(String s, int offset, int len)
|
||||||
|
|
|
@ -180,8 +180,7 @@ public class ClasspathPattern extends AbstractSet<String>
|
||||||
if (_entries.get(name)!=null)
|
if (_entries.get(name)!=null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
_entries.put(name,entry);
|
return _entries.put(name,entry);
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -228,4 +228,21 @@ public class ClasspathPatternTest
|
||||||
assertThat(pattern.match(JDK.class),is(true));
|
assertThat(pattern.match(JDK.class),is(true));
|
||||||
assertThat(pattern.match(ClasspathPatternTest.class),is(false));
|
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