API reference¶
The typed public surface of the lexindex Python package.
StringIndex¶
lexindex.StringIndex ¶
Ordered string↔id index (FST) with prefix / range / fuzzy / subsequence queries.
__doc__
class-attribute
¶
str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to 'strict'.
__module__
class-attribute
¶
str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to 'strict'.
__new__
builtin
¶
Create and return a new object. See help(type) for accurate signature.
from_bytes
staticmethod
¶
Reconstruct from a [PyStringIndex::to_bytes] blob.
fuzzy
method descriptor
¶
(key, id) pairs within Levenshtein edit distance max_distance of query.
ids_of
method descriptor
¶
Batched id: one call for many keys, looping in Rust to amortise the Python↔Rust
boundary. Returns a list aligned with keys, None where a key is absent. (Named ids_of, not
ids/keys, so the class is not mistaken for a mapping by dict(index).)
keys_of
method descriptor
¶
Batched key: one call for many ids. Returns a list aligned with ids, None
where an id is out of range.
load_mmap
staticmethod
¶
Zero-copy load: memory-map the file and borrow the index from it — no read into RAM, so a multi-gigabyte index is ready instantly and its pages are shared across processes. The mapped file must not be modified while the index is alive.
predecessor
method descriptor
¶
The largest (key, id) with key <= query, or None if every key is larger.
prefix
method descriptor
¶
(key, id) pairs whose key starts with prefix, lexicographically ordered.
range
method descriptor
¶
(key, id) pairs with lo <= key < hi, lexicographically ordered.
subsequence
method descriptor
¶
(key, id) pairs whose key contains query as a subsequence.
successor
method descriptor
¶
The smallest (key, id) with key >= query, or None if every key is smaller.
CompactHashIndex¶
lexindex.CompactHashIndex ¶
Fingerprint minimal-perfect-hash dictionary: the smallest string -> dense id map. Membership is
probabilistic (false-positive rate 256 ** -fingerprint_bytes) and there is no reverse id -> key.
__doc__
class-attribute
¶
__doc__ = "Fingerprint minimal-perfect-hash dictionary: the smallest `string -> dense id` map. Membership is\nprobabilistic (false-positive rate `256 ** -fingerprint_bytes`) and there is no reverse `id -> key`."
str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to 'strict'.
__module__
class-attribute
¶
str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to 'strict'.
__new__
builtin
¶
Create and return a new object. See help(type) for accurate signature.
contains
method descriptor
¶
Whether key is present (subject to the false-positive rate).
from_bytes
staticmethod
¶
Reconstruct from a [PyCompactHashIndex::to_bytes] blob.
id
method descriptor
¶
Dense id of key (membership checked against the fingerprint), or None.
id_unchecked
method descriptor
¶
Dense id of key without the fingerprint check — key must be a member, or the result is
an arbitrary valid slot. Fastest lookup for a fixed vocabulary.
ids_of
method descriptor
¶
Batched id: one call for many keys, aligned with keys (None where absent).
load
staticmethod
¶
Load a dictionary previously written with save.
load_mmap
staticmethod
¶
Zero-copy load: memory-map the file and borrow the fingerprint table.
PerfectHashIndex¶
lexindex.PerfectHashIndex ¶
Minimal-perfect-hash dictionary: fastest exact string → dense id, with persistence.
__doc__
class-attribute
¶
str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to 'strict'.
__module__
class-attribute
¶
str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to 'strict'.
__new__
builtin
¶
Create and return a new object. See help(type) for accurate signature.
from_bytes
staticmethod
¶
Reconstruct from a [PyPerfectHashIndex::to_bytes] blob.
id
method descriptor
¶
Dense id of key (membership verified), or None if absent.
id_unchecked
method descriptor
¶
Dense id of key without membership verification — key must be in the dictionary, or the
result is an arbitrary valid slot. Fastest lookup for a fixed vocabulary.
ids_of
method descriptor
¶
Batched id: one call for many keys, aligned with keys (None where absent).
keys_of
method descriptor
¶
Batched key: one call for many ids, aligned with ids (None where out of range).
load
staticmethod
¶
Load a dictionary previously written with save.
load_mmap
staticmethod
¶
Memory-map the file and borrow the key arena zero-copy (only the small MPH is read into RAM). The mapped file must not be modified while the dictionary is alive.