Warning: session_start(): open(/var/lib/php/sessions/sess_fbpg43b154b7pektr2mat1t8tf, O_RDWR) failed: No space left on device (28) in /var/www/tb-usercake/models/config.php on line 51
Warning: session_start(): Failed to read session data: files (path: /var/lib/php/sessions) in /var/www/tb-usercake/models/config.php on line 51
// A = type of value in nodes.
// Can be case-sensitive or case-insensitive
// values can't be null
sclass StringTrie {
A value;
TreeMap> children;
*() {}
*(A *value) {}
void makeCaseInsensitive() {
children = asCIMap(children);
}
bool isCaseInsensitive() {
ret isCIMap(children);
}
void add(S string, A value) {
if (empty(string)) ret with this.value = value;
S existingPrefix = isCaseInsensitive()
? longestPrefixInCISet(string, navigableKeys(children))
: longestPrefixInNavigableSet(string, navigableKeys(children));
if (nempty(existingPrefix))
ret with children.get(existingPrefix).add(substring(string, l(existingPrefix)), value);
if (children == null) children = new TreeMap;
StringTrie child = new(value);
if (isCaseInsensitive()) child.makeCaseInsensitive();
children.put(string, child);
}
// returns TreeMap or ciMap
Map asMap() {
Map map = isCaseInsensitive() ? ciMap() : new TreeMap;
new StringBuilder buf;
collectMap(buf, map);
ret map;
}
private void collectMap(StringBuilder buf, Map map) {
if (value != null) map.put(str(buf), value);
int n = l(buf);
for (S string, StringTrie child : children) {
buf.append(string);
child.collectMap(buf, map);
buf.setLength(n);
}
}
toString {
new StringBuilder buf;
toString(buf, 0);
ret str(buf);
}
void toString(StringBuilder buf, int indent) {
buf.append(strOrEmpty(value)).append("\n");
for (S string, StringTrie child : children) {
buf.append(spaces(indent+2)).append(quote(string) + " => ");
child.toString(buf, indent+2);
}
}
}