public class FSA extends Object
Modifier and Type | Class and Description |
---|---|
static class |
FSA.Iterator
Class used to iterate over all accepted strings in the fsa.
|
static class |
FSA.State
Thread local state object used to traverse a Finite-State Automaton.
|
Modifier and Type | Field and Description |
---|---|
private Charset |
_charset |
private MappedByteBuffer |
_data |
private MappedByteBuffer |
_header |
private boolean |
_ok |
private MappedByteBuffer |
_phash |
private MappedByteBuffer |
_state_tab |
private MappedByteBuffer |
_symbol_tab |
Constructor and Description |
---|
FSA(FileInputStream filename)
Loads an FSA from a file input stream using utf-8 encoding
|
FSA(FileInputStream filename,
String charsetname)
Loads an FSA from a file input stream using the specified character encoding
|
FSA(String filename)
Loads an FSA from a file using utf-8 encoding
|
FSA(String filename,
String charsetname)
Loads an FSA from a file using the specified character encoding.
|
Modifier and Type | Method and Description |
---|---|
protected ByteBuffer |
data(int state)
Retrieves data for the given state using the underlying fsa data buffer.
|
protected String |
dataString(int state)
Retrieves data for the given state using the underlying fsa data buffer.
|
private String |
decode(ByteBuffer buf) |
protected int |
delta(int state,
byte symbol) |
private ByteBuffer |
encode(CharBuffer chrbuf) |
private ByteBuffer |
encode(String str) |
FSA.State |
getState() |
private int |
getSymbol(int index) |
private int |
h_checksum() |
private int |
h_data_size() |
private int |
h_data_type() |
private int |
h_fixed_data_size() |
private int |
h_has_phash() |
private int |
h_magic() |
private int |
h_serial() |
private int |
h_size() |
private int |
h_start() |
private int |
h_version() |
protected int |
hashDelta(int state,
byte symbol) |
boolean |
hasPerfectHash() |
private void |
init(FileInputStream file,
String charsetname) |
private void |
init(String filename,
String charsetname) |
protected boolean |
isFinal(int state) |
boolean |
isOk() |
FSA.Iterator |
iterator()
Returns a new iterator to the start state.
|
FSA.Iterator |
iterator(FSA.State state)
Returns a new iterator to the given state.
|
static FSA |
loadFromResource(String resourceFileName,
Class loadingClass)
Loads an FSA from a resource file name, which is resolved from the class path of the
class loader of the given class.
|
String |
lookup(String str)
Convenience method that returns the metadata string in the fsa
for the input lookup String, or null if the input string does
not exist in the fsa.
|
static void |
main(String[] args) |
int |
serial() |
protected int |
start() |
int |
version() |
private boolean _ok
private MappedByteBuffer _header
private MappedByteBuffer _symbol_tab
private MappedByteBuffer _state_tab
private MappedByteBuffer _data
private MappedByteBuffer _phash
private Charset _charset
public FSA(String filename)
IllegalArgumentException
- if the file is not foundpublic FSA(String filename, String charsetname)
IllegalArgumentException
- if the file is not foundpublic FSA(FileInputStream filename)
public FSA(FileInputStream filename, String charsetname)
public FSA.State getState()
public FSA.Iterator iterator()
public FSA.Iterator iterator(FSA.State state)
state
- the state to create the iterator from.public static FSA loadFromResource(String resourceFileName, Class loadingClass)
This is useful for loading fsa's deployed within OSGi bundles.
resourceFileName
- the name of the file, relative to any element on the classpath.
For example, if the classpath contains resources/ and the file is resources/myfsa.fsa
this argument should be myfsa.fsaloadingClass
- a class which provides the class loader to use for loading. Any class which is loaded
from the same class path as the resource will do (e.g with OSGi - any class in the same bundle jar)RuntimeException
- if the class could not be loadedprivate void init(FileInputStream file, String charsetname)
private int h_magic()
private int h_version()
private int h_checksum()
private int h_size()
private int h_start()
private int h_data_size()
private int h_data_type()
private int h_fixed_data_size()
private int h_has_phash()
private int h_serial()
private int getSymbol(int index)
private ByteBuffer encode(String str)
private ByteBuffer encode(CharBuffer chrbuf)
private String decode(ByteBuffer buf)
public boolean isOk()
public boolean hasPerfectHash()
public int version()
public int serial()
protected int start()
protected int delta(int state, byte symbol)
protected int hashDelta(int state, byte symbol)
protected boolean isFinal(int state)
protected ByteBuffer data(int state)
state
- The fsa state to retrieve data from.protected String dataString(int state)
state
- The fsa state to retrieve data from.public String lookup(String str)
str
- The string to look up.public static void main(String[] args)
Copyright © 2018. All rights reserved.