pub struct ShardMap {
pub version: u32,
pub hash_bytes: u8,
pub ranges: Vec<ShardRange>,
pub next_shard_id: u64,
}Expand description
Hash-range shard map (sorted, contiguous, full coverage).
Fields§
§version: u32Format version
hash_bytes: u8Hash width in bytes (8 = u64)
ranges: Vec<ShardRange>Sorted, contiguous ranges covering the full u64 space.
next_shard_id: u64Next shard ID to allocate when splitting ranges.
Implementations§
Source§impl ShardMap
impl ShardMap
pub const VERSION: u32 = 1
pub const HASH_BYTES: u8 = 8
Sourcepub fn new(range_count: u64) -> Self
pub fn new(range_count: u64) -> Self
Creates a new shard map with evenly-sized ranges.
The range count is rounded up to the next power of two to simplify future splits and keep ranges aligned.
Sourcepub fn range_index_for_hash(&self, key: u64) -> Option<usize>
pub fn range_index_for_hash(&self, key: u64) -> Option<usize>
Finds the range index for a given hash key.
Sourcepub fn range_for_hash(&self, key: u64) -> Option<&ShardRange>
pub fn range_for_hash(&self, key: u64) -> Option<&ShardRange>
Returns the shard range for a given hash key.
Sourcepub fn range_for_path(
&self,
repo_secret: &RepoSecret,
path: &str,
) -> Option<&ShardRange>
pub fn range_for_path( &self, repo_secret: &RepoSecret, path: &str, ) -> Option<&ShardRange>
Returns the shard range for a given path.
Sourcepub fn range_for_dir(
&self,
repo_secret: &RepoSecret,
dir_path: &str,
) -> Option<&ShardRange>
pub fn range_for_dir( &self, repo_secret: &RepoSecret, dir_path: &str, ) -> Option<&ShardRange>
Returns the shard range for a given directory path.
Sourcepub fn update_range(
&mut self,
shard_id: u64,
cid: ShardCid,
compressed_size: u64,
digest: Option<[u8; 32]>,
wrapped_key: Option<WrappedKey>,
) -> bool
pub fn update_range( &mut self, shard_id: u64, cid: ShardCid, compressed_size: u64, digest: Option<[u8; 32]>, wrapped_key: Option<WrappedKey>, ) -> bool
Updates shard CID and size by shard ID.
Sourcepub fn allocate_shard_id(&mut self) -> u64
pub fn allocate_shard_id(&mut self) -> u64
Allocate a new shard ID (for large file chunks that bypass hash assignment).
Sourcepub fn clear_assignments(&mut self)
pub fn clear_assignments(&mut self)
Clears all shard CIDs and compressed sizes (keeps ranges and IDs).
Sourcepub fn split_range(&mut self, shard_id: u64) -> bool
pub fn split_range(&mut self, shard_id: u64) -> bool
Splits a range into two halves, keeping the lower half’s shard_id.
Returns false if the range is not found or cannot be split.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for ShardMap
impl<'de> Deserialize<'de> for ShardMap
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for ShardMap
impl RefUnwindSafe for ShardMap
impl Send for ShardMap
impl Sync for ShardMap
impl Unpin for ShardMap
impl UnsafeUnpin for ShardMap
impl UnwindSafe for ShardMap
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more