pub struct IndexedRepository<'index, 'objects, R: Repository + ?Sized> { /* private fields */ }Expand description
Index a stable repository without allocating or copying object bodies.
Construction reads the source count once, reads and hashes each object once,
and sorts an ID index in place. Subsequent object enumeration and ID access
are O(1); lookup by ID is O(log n). Object order, HEAD, and refs are preserved.
The source still owns the bodies and must satisfy Repository’s stability
contract. It must expose borrowed bodies through object; this wrapper does
not index streaming-only providers, validate object graphs, or deduplicate them.
Implementations§
Source§impl<'index, 'objects, R: Repository + ?Sized> IndexedRepository<'index, 'objects, R>
impl<'index, 'objects, R: Repository + ?Sized> IndexedRepository<'index, 'objects, R>
Sourcepub fn new(
repository: &'objects R,
object_storage: &'index mut [Option<ObjectMetadata<'objects>>],
index_storage: &'index mut [usize],
) -> Result<Self>
pub fn new( repository: &'objects R, object_storage: &'index mut [Option<ObjectMetadata<'objects>>], index_storage: &'index mut [usize], ) -> Result<Self>
Both arrays need at least repository.object_count() elements. Extra
slots are untouched. Initialize metadata with [None; N].
Insufficient capacity fails before reading any object. A missing source
object returns ObjectNotFound; discard partial arrays after an error.
use git_zero_core::{File, IndexedRepository, Repository, Snapshot};
let files = [File { name: "hello", contents: b"hello\n" }];
let mut tree = [0; 128];
let mut commit = [0; 256];
let snapshot = Snapshot::new(&files, &mut tree, &mut commit)?;
let mut objects = [None; 3]; // Commit, tree, and blob.
let mut by_id = [0; 3];
let indexed = IndexedRepository::new(&snapshot, &mut objects, &mut by_id)?;
assert_eq!(indexed.find(indexed.head()).unwrap().kind,
git_zero_core::ObjectKind::Commit);Sourcepub fn metadata(&self, index: usize) -> Option<&ObjectMetadata<'objects>>
pub fn metadata(&self, index: usize) -> Option<&ObjectMetadata<'objects>>
Metadata in the source repository’s enumeration order.
Trait Implementations§
Source§impl<R: Repository + ?Sized> Repository for IndexedRepository<'_, '_, R>
impl<R: Repository + ?Sized> Repository for IndexedRepository<'_, '_, R>
Source§fn object_format(&self) -> ObjectFormat
fn object_format(&self) -> ObjectFormat
object_id.Source§fn head(&self) -> ObjectId
fn head(&self) -> ObjectId
head_state().id() when absence needs to be distinguished.fn head_state(&self) -> Head<'_>
fn object_count(&self) -> usize
Source§fn object(&self, index: usize) -> Option<Object<'_>>
fn object(&self, index: usize) -> Option<Object<'_>>
None and implement object_info, read_object, and object_id instead.Source§fn object_id(&self, index: usize) -> Option<ObjectId>
fn object_id(&self, index: usize) -> Option<ObjectId>
ObjectHasher computes them incrementally with caller-owned scratch.fn head_ref(&self) -> &str
fn reference_count(&self) -> usize
fn reference_name(&self, index: usize) -> Option<&str>
Source§fn reference_id(&self, index: usize) -> Option<ObjectId>
fn reference_id(&self, index: usize) -> Option<ObjectId>
fn reference_symbolic_target(&self, index: usize) -> Option<&str>
fn reference_peeled(&self, index: usize) -> Option<ObjectId>
Source§fn find_index(&self, id: ObjectId) -> Option<usize>
fn find_index(&self, id: ObjectId) -> Option<usize>
fn object_info(&self, index: usize) -> Result<ObjectInfo>
Source§fn read_object(
&self,
index: usize,
offset: u64,
storage: &mut [u8],
) -> Result<usize>
fn read_object( &self, index: usize, offset: u64, storage: &mut [u8], ) -> Result<usize>
storage.len() body bytes starting at a byte offset.
Short reads are allowed. Return zero only at EOF or for empty storage.
Calls must be independent of earlier reads, enabling interleaved readers
and retries. Errors may modify storage but must not change the object.