pub struct Index { /* private fields */ }Implementations§
Source§impl Index
impl Index
pub fn new( paths: List<u64>, children: VariableList<u16>, leaves: VariableList<u16>, values: VariableList<u16>, words: VariableList<u8>, map_keys: VariableList<u16>, map_vals: VariableList<u16>, args_keys: VariableList<u16>, args_vals: VariableList<u16>, ) -> Self
Sourcepub fn traverse(&self, path: &str) -> Box<[LeafRef]>
pub fn traverse(&self, path: &str) -> Box<[LeafRef]>
Traverse to the path node matching path (dot-separated keywords),
then collect all leaf descendants into a flat list.
use context_engine::{Tree, Index, dsl::Dsl};
let tree = Tree::Mapping(alloc::vec![(b"id".to_vec(), Tree::Null)]);
let (paths, children, leaves, values, words, map_keys, map_vals, args_keys, args_vals) = Dsl::compile(&tree, &[]).unwrap();
let index = Index::new(paths, children, leaves, values, words, map_keys, map_vals, args_keys, args_vals);
assert_eq!(index.traverse("id").len(), 1);
assert!(index.traverse("missing").is_empty());Sourcepub fn keyword_of(&self, path_id: u16) -> &[u8] ⓘ
pub fn keyword_of(&self, path_id: u16) -> &[u8] ⓘ
Return the keyword bytes for a path node.
use context_engine::{Tree, Index, dsl::Dsl};
let tree = Tree::Mapping(alloc::vec![(b"name".to_vec(), Tree::Null)]);
let (paths, children, leaves, values, words, map_keys, map_vals, args_keys, args_vals) = Dsl::compile(&tree, &[]).unwrap();
let index = Index::new(paths, children, leaves, values, words, map_keys, map_vals, args_keys, args_vals);
assert_eq!(index.keyword_of(1), b"name");Sourcepub fn get_meta(
&self,
leaf: &LeafRef,
) -> (u8, &[u16], &[u16], &[u16], &[u16], &[u16])
pub fn get_meta( &self, leaf: &LeafRef, ) -> (u8, &[u16], &[u16], &[u16], &[u16], &[u16])
Extract _get meta for the given leaf.
Returns (store_id, key_frags, map_keys, map_vals, args_keys, args_vals).
store_id=0 means no _get configured; all slices are empty in that case.
key_frags: VALUE_IS_PLACEHOLDER_MASK-flagged u16 fragments (same encoding as leaf values).
map_keys: dst path_id列, map_vals: src word_id列.
args_keys: arg name word_id列, args_vals: arg value values_id列 (each indexes into values).
Sourcepub fn set_meta(
&self,
leaf: &LeafRef,
) -> (u8, &[u16], &[u16], &[u16], &[u16], &[u16])
pub fn set_meta( &self, leaf: &LeafRef, ) -> (u8, &[u16], &[u16], &[u16], &[u16], &[u16])
Extract _set meta for the given leaf.
Same layout as get_meta.
Sourcepub fn leaf_fragments(&self, leaf: &LeafRef) -> Vec<(bool, &[u8])>
pub fn leaf_fragments(&self, leaf: &LeafRef) -> Vec<(bool, &[u8])>
Return the value fragments encoded in the leaf.
Each element is (is_placeholder, bytes):
false— static string literaltrue—${path}reference whose bytes are the path string
An empty slice means the leaf has no value (Null).
use context_engine::{Tree, Index, dsl::Dsl};
let tree = Tree::Mapping(alloc::vec![
(b"driver".to_vec(), Tree::Scalar(b"postgres".to_vec())),
]);
let (paths, children, leaves, values, words, map_keys, map_vals, args_keys, args_vals) = Dsl::compile(&tree, &[]).unwrap();
let index = Index::new(paths, children, leaves, values, words, map_keys, map_vals, args_keys, args_vals);
let leaves = index.traverse("driver");
let frags = index.leaf_fragments(&leaves[0]);
assert_eq!(frags.len(), 1);
assert_eq!(frags[0].0, false);
assert_eq!(frags[0].1, b"postgres");