pub struct IndexedDocument<'a> { /* private fields */ }Expand description
A JSON buffer plus structural / array / object indexes for path-accelerated reads.
Implementations§
Source§impl<'a> IndexedDocument<'a>
impl<'a> IndexedDocument<'a>
Sourcepub fn build(json: &'a [u8], array_paths: &[&str]) -> Result<Self, Error>
pub fn build(json: &'a [u8], array_paths: &[&str]) -> Result<Self, Error>
Build array side-tables for each path (lenient path parse).
use jshift::IndexedDocument;
let json = br#"{"products":[{"id":1},{"id":2},{"id":3}]}"#;
let doc = IndexedDocument::build(json, &["products"]).unwrap();
assert_eq!(doc.array_len(&jshift::parse_path("products")).unwrap(), 3);
assert_eq!(
doc.find(&jshift::parse_path("products[2].id")).unwrap(),
b"3"
);Sourcepub fn build_paths(
json: &'a [u8],
array_paths: &[&[PathSegment<'_>]],
) -> Result<Self, Error>
pub fn build_paths( json: &'a [u8], array_paths: &[&[PathSegment<'_>]], ) -> Result<Self, Error>
Build array side-tables from segment slices.
Sourcepub fn build_structural(json: &'a [u8]) -> Result<Self, Error>
pub fn build_structural(json: &'a [u8]) -> Result<Self, Error>
Build Stage-1 structural index only (no array/object tables yet).
Sourcepub fn build_full(
json: &'a [u8],
array_paths: &[&str],
object_paths: &[&str],
) -> Result<Self, Error>
pub fn build_full( json: &'a [u8], array_paths: &[&str], object_paths: &[&str], ) -> Result<Self, Error>
Full convenience: structural + arrays + objects.
pub fn as_bytes(&self) -> &'a [u8] ⓘ
Sourcepub fn index_structural(&mut self) -> Result<(), Error>
pub fn index_structural(&mut self) -> Result<(), Error>
Build or replace the document-wide Stage-1 structural list.
pub fn structural(&self) -> Option<&StructuralIndex>
Sourcepub fn index_array(&mut self, path: &[PathSegment<'_>]) -> Result<(), Error>
pub fn index_array(&mut self, path: &[PathSegment<'_>]) -> Result<(), Error>
Index the array at path.
pub fn index_array_str(&mut self, path: &str) -> Result<(), Error>
Sourcepub fn index_for_plan(&mut self, plan: &ProjectPlan) -> Result<(), Error>
pub fn index_for_plan(&mut self, plan: &ProjectPlan) -> Result<(), Error>
Index every array path a crate::ProjectPlan will walk (idempotent).
Builds Stage-1 structurals when missing (helps large-array table builds), then
array side-tables for each path from crate::ProjectPlan::array_paths_for_index.
Already-indexed paths are left unchanged.
use jshift::{IndexedDocument, ProjectPlan, project_indexed};
let json = br#"{"products":[{"id":1},{"id":2},{"id":3}]}"#;
let plan = ProjectPlan::from_paths(&["products[2].id"]).unwrap();
let mut doc = IndexedDocument::empty(json);
doc.index_for_plan(&plan).unwrap();
assert_eq!(project_indexed(&doc, &plan).unwrap(), br#"{"products":{"id":3}}"#);Sourcepub fn index_object(&mut self, path: &[PathSegment<'_>]) -> Result<(), Error>
pub fn index_object(&mut self, path: &[PathSegment<'_>]) -> Result<(), Error>
Index all keys of the object at path (value must be {...}).
pub fn index_object_str(&mut self, path: &str) -> Result<(), Error>
pub fn array_len(&self, path: &[PathSegment<'_>]) -> Option<usize>
pub fn array_index(&self, path: &[PathSegment<'_>]) -> Option<&ArrayIndex>
pub fn object_index(&self, path: &[PathSegment<'_>]) -> Option<&ObjectKeyIndex>
Sourcepub fn array_index_at_open(&self, open: usize) -> Option<&ArrayIndex>
pub fn array_index_at_open(&self, open: usize) -> Option<&ArrayIndex>
Look up an array side-table by the absolute offset of its opening [.
Used by the projector to jump elements in O(1) when the array was indexed (path-based) and emit visits the same on-wire span.
Sourcepub fn object_index_at_open(&self, open: usize) -> Option<&ObjectKeyIndex>
pub fn object_index_at_open(&self, open: usize) -> Option<&ObjectKeyIndex>
Look up an object key map by the absolute offset of its opening {.
Sourcepub fn find(&self, path: &[PathSegment<'_>]) -> Result<&'a [u8], Error>
pub fn find(&self, path: &[PathSegment<'_>]) -> Result<&'a [u8], Error>
Find using array / object indexes when applicable; else normal path scan.
pub fn find_offsets( &self, path: &[PathSegment<'_>], ) -> Result<(usize, usize), Error>
pub fn for_each_element<F>( &self, array_path: &[PathSegment<'_>], f: F, ) -> Result<(), Error>
pub fn for_each_element_str<F>( &self, array_path: &str, f: F, ) -> Result<(), Error>
pub fn indexed_array_count(&self) -> usize
pub fn indexed_object_count(&self) -> usize
Trait Implementations§
Source§impl<'a> Clone for IndexedDocument<'a>
impl<'a> Clone for IndexedDocument<'a>
Source§fn clone(&self) -> IndexedDocument<'a>
fn clone(&self) -> IndexedDocument<'a>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more