Struct tantivy_sstable::Dictionary
source · pub struct Dictionary<TSSTable: SSTable = VoidSSTable> {
pub sstable_slice: FileSlice,
pub sstable_index: SSTableIndex,
/* private fields */
}
Expand description
An SSTable is a sorted map that associates sorted &[u8]
keys
to any kind of typed values.
The SSTable is organized in blocks. In each block, keys and values are encoded separately.
The keys are encoded using incremental encoding. The values on the other hand, are encoded according to a value-specific codec defined in the TSSTable generic argument.
Finally, an index is joined to the Dictionary to make it possible, given a key to identify which block contains this key.
The codec was designed in such a way that the sstable reader is not aware of block, and yet can read any sequence of blocks, as long as the slice of bytes it is given starts and stops at block boundary.
(See also README.md)
Fields§
§sstable_slice: FileSlice
§sstable_index: SSTableIndex
Implementations§
source§impl Dictionary<VoidSSTable>
impl Dictionary<VoidSSTable>
pub fn build_for_tests(terms: &[&str]) -> Dictionary
source§impl<TSSTable: SSTable> Dictionary<TSSTable>
impl<TSSTable: SSTable> Dictionary<TSSTable>
pub fn builder<W: Write>(wrt: W) -> Result<Writer<W, TSSTable::ValueWriter>>
sourcepub fn file_slice_for_range(
&self,
key_range: impl RangeBounds<[u8]>,
limit: Option<u64>
) -> FileSlice
pub fn file_slice_for_range( &self, key_range: impl RangeBounds<[u8]>, limit: Option<u64> ) -> FileSlice
This function returns a file slice covering a set of sstable blocks
that include the key range passed in arguments. Optionally returns
only block for up to limit
matching terms.
It works by identifying
first_block
: the block containing the start boundary keylast_block
: the block containing the end boundary key.
And then returning the range that spans over all blocks between.
and including first_block and last_block, aka:
[first_block.start_offset .. last_block.end_offset)
Technically this function does not provide the tightest fit, as
for simplification, it treats the start bound of the key_range
as if it was inclusive, even if it is exclusive.
On the rare edge case where a user asks for (start_key, end_key]
and start_key
happens to be the last key of a block, we return a
slice that is the first block was not necessary.
sourcepub fn from_bytes(owned_bytes: OwnedBytes) -> Result<Self>
pub fn from_bytes(owned_bytes: OwnedBytes) -> Result<Self>
Creates a term dictionary from the supplied bytes.
sourcepub fn num_terms(&self) -> usize
pub fn num_terms(&self) -> usize
Returns the number of terms in the dictionary.
Term ordinals range from 0 to num_terms() - 1
.
sourcepub fn term_ord<K: AsRef<[u8]>>(&self, key: K) -> Result<Option<TermOrdinal>>
pub fn term_ord<K: AsRef<[u8]>>(&self, key: K) -> Result<Option<TermOrdinal>>
Returns the ordinal associated with a given term.
sourcepub fn ord_to_term(&self, ord: TermOrdinal, bytes: &mut Vec<u8>) -> Result<bool>
pub fn ord_to_term(&self, ord: TermOrdinal, bytes: &mut Vec<u8>) -> Result<bool>
Returns the term associated with a given term ordinal.
Term ordinals are defined as the position of the term in the sorted list of terms.
Returns true if and only if the term has been found.
Regardless of whether the term is found or not, the buffer may be modified.
sourcepub fn term_info_from_ord(
&self,
term_ord: TermOrdinal
) -> Result<Option<TSSTable::Value>>
pub fn term_info_from_ord( &self, term_ord: TermOrdinal ) -> Result<Option<TSSTable::Value>>
Returns the number of terms in the dictionary.
sourcepub fn get<K: AsRef<[u8]>>(&self, key: K) -> Result<Option<TSSTable::Value>>
pub fn get<K: AsRef<[u8]>>(&self, key: K) -> Result<Option<TSSTable::Value>>
Lookups the value corresponding to the key.
sourcepub async fn get_async<K: AsRef<[u8]>>(
&self,
key: K
) -> Result<Option<TSSTable::Value>>
pub async fn get_async<K: AsRef<[u8]>>( &self, key: K ) -> Result<Option<TSSTable::Value>>
Lookups the value corresponding to the key.
sourcepub fn range(&self) -> StreamerBuilder<'_, TSSTable>
pub fn range(&self) -> StreamerBuilder<'_, TSSTable>
Returns a range builder, to stream all of the terms within an interval.