net.amygdalum.util.text.doublearraytrie.DoubleArrayByteFallbackTrieCompiler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of compilerutils Show documentation
Show all versions of compilerutils Show documentation
Utility classes needed for search and compiler applications
The newest version!
package net.amygdalum.util.text.doublearraytrie;
import static net.amygdalum.util.text.doublearraytrie.Arrays.expand;
import java.util.IdentityHashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.Queue;
import net.amygdalum.util.text.ByteFallbackAdaptor;
import net.amygdalum.util.text.ByteNode;
import net.amygdalum.util.text.ByteTrie;
import net.amygdalum.util.text.ByteWordGraphCompiler;
import net.amygdalum.util.text.NodeResolver;
import net.amygdalum.util.text.linkeddawg.ByteGenericFallbackNode;
public class DoubleArrayByteFallbackTrieCompiler implements ByteWordGraphCompiler> {
@Override
public ByteNode create() {
return new ByteGenericFallbackNode<>();
}
@Override
public ByteTrie build(ByteNode node) {
DoubleArrayByteFallbackTrie.Builder builder = new DoubleArrayByteFallbackTrie.Builder();
boolean[] visited = new boolean[1024];
Map, Integer> assignments = new IdentityHashMap<>();
Queue> todo = new LinkedList<>();
todo.add(new Assignment<>(builder.root(), node));
while (!todo.isEmpty()) {
Assignment current = todo.remove();
int currentState = current.state;
ByteNode currentNode = current.node;
if (currentState >= visited.length) {
visited = expand(visited, currentState);
}
if (visited[currentState]) {
continue;
}
visited[currentState] = true;
assignments.put(currentNode, currentState);
int alternatives = currentNode.getAlternativesSize();
if (alternatives >= 1) {
branch(builder, currentState, currentNode, todo);
} else {
terminate(builder, currentState, currentNode);
}
}
for (Map.Entry, Integer> current : assignments.entrySet()) {
ByteNode currentNode = current.getKey();
int currentState = current.getValue();
ByteNode
© 2015 - 2025 Weber Informatics LLC | Privacy Policy