ma.vi.base.trie.StringTrie Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of com.vikmad.base Show documentation
Show all versions of com.vikmad.base Show documentation
Base algos, data structures and utilities
The newest version!
package ma.vi.base.trie;
import ma.vi.base.collections.CharIterable;
import ma.vi.base.tuple.T2;
import java.util.List;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;
/**
* Trie specialised for strings.
*
* @author Vikash Madhow ([email protected])
*/
public class StringTrie extends Trie {
public V put(String sequence, V value) {
return super.put(new CharIterable(sequence), value);
}
public V get(String sequence) {
return super.get(new CharIterable(sequence));
}
public List> getPrefixed(String sequence) {
return charListToString(super.getPrefixed(new CharIterable(sequence)));
}
public void delete(String sequence) {
super.delete(new CharIterable(sequence));
}
public boolean deletePrefixed(String sequence) {
return super.deletePrefixed(new CharIterable(sequence));
}
protected List> charListToString(List, V>> from) {
return from.stream()
.map(t -> T2.of(t.a.stream()
.map(Object::toString)
.collect(joining()),
t.b))
.collect(toList());
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy