pub struct EdgeCluster { /* private fields */ }Expand description
Serialized cluster holding all edges for a node in a given direction.
Implementations§
Source§impl EdgeCluster
impl EdgeCluster
Sourcepub fn create_from_edges(
edges: &[EdgeRecord],
node_id: i64,
direction: Direction,
string_table: &mut StringTable,
) -> NativeResult<Self>
pub fn create_from_edges( edges: &[EdgeRecord], node_id: i64, direction: Direction, string_table: &mut StringTable, ) -> NativeResult<Self>
Build a cluster from a slice of canonical EdgeRecords.
Sourcepub fn serialize(&self) -> Vec<u8> ⓘ
pub fn serialize(&self) -> Vec<u8> ⓘ
Serialize cluster header + payload. CRITICAL FIX: Ensure the final buffer size matches header expectations exactly.
Sourcepub fn verify_serialized_layout(bytes: &[u8]) -> NativeResult<()>
pub fn verify_serialized_layout(bytes: &[u8]) -> NativeResult<()>
Validate serialized bytes before writing to disk.
Sourcepub fn deserialize(bytes: &[u8]) -> NativeResult<Self>
pub fn deserialize(bytes: &[u8]) -> NativeResult<Self>
Rebuild a cluster from raw bytes. Rebuild a cluster from raw bytes.
Sourcepub fn edge_count(&self) -> u32
pub fn edge_count(&self) -> u32
Number of edges stored in this cluster.
Sourcepub fn size_bytes(&self) -> usize
pub fn size_bytes(&self) -> usize
Total bytes including cluster header.
Sourcepub fn iter_neighbors(&self) -> impl Iterator<Item = i64> + '_
pub fn iter_neighbors(&self) -> impl Iterator<Item = i64> + '_
Iterate over neighbor node IDs stored in this cluster.
Sourcepub fn iter_decompress(&self) -> impl Iterator<Item = CompactEdgeRecord> + '_
pub fn iter_decompress(&self) -> impl Iterator<Item = CompactEdgeRecord> + '_
Iterate over edges using lazy decompression from serialized bytes.
This method provides a zero-allocation iterator that decompresses edges on-the-fly, improving cache locality for large clusters.
§Returns
An iterator that yields CompactEdgeRecord items
Sourcepub fn decompress_from_bytes(
bytes: &[u8],
) -> NativeResult<DecompressEdgeIterator<'_>>
pub fn decompress_from_bytes( bytes: &[u8], ) -> NativeResult<DecompressEdgeIterator<'_>>
Create a decompression iterator from raw serialized bytes.
This is useful for edge clusters that haven’t been fully deserialized yet, allowing for lazy loading and improved memory efficiency.
§Arguments
bytes- Raw serialized cluster bytes
§Returns
A DecompressEdgeIterator that yields edges on-demand
Sourcepub fn is_efficient(&self) -> bool
pub fn is_efficient(&self) -> bool
Return whether the cluster meets compactness heuristics.
Sourcepub fn validate(&self) -> NativeResult<()>
pub fn validate(&self) -> NativeResult<()>
Validate record integrity.
Sourcepub fn set_offset(&mut self, offset: FileOffset)
pub fn set_offset(&mut self, offset: FileOffset)
Set file offset once the cluster has been written to disk.
Sourcepub fn offset(&self) -> FileOffset
pub fn offset(&self) -> FileOffset
Retrieve the cluster’s file offset.
Sourcepub fn payload_size(&self) -> usize
pub fn payload_size(&self) -> usize
Get the serialized payload size (excluding header).
Sourcepub fn edges(&self) -> &[CompactEdgeRecord]
pub fn edges(&self) -> &[CompactEdgeRecord]
Borrow the compact edges (used when flushing clusters).
Sourcepub fn create_from_compact_edges(
compact_edges: Vec<CompactEdgeRecord>,
_node_id: i64,
_direction: Direction,
) -> NativeResult<Self>
pub fn create_from_compact_edges( compact_edges: Vec<CompactEdgeRecord>, _node_id: i64, _direction: Direction, ) -> NativeResult<Self>
Create cluster directly from compact edges without EdgeRecord reconstruction. This is the new pipeline method that treats compact edges as authoritative. CRITICAL FIX: Ensure serialized_size exactly matches the actual payload bytes.
Sourcepub fn get_neighbors_with_cache(
&self,
cache: &ThreadSafeCache,
node_id: i64,
direction: Direction,
) -> Vec<i64>
pub fn get_neighbors_with_cache( &self, cache: &ThreadSafeCache, node_id: i64, direction: Direction, ) -> Vec<i64>
Get neighbors with cache support. This is a cache-aware wrapper around iter_neighbors that records access patterns.
For high-degree nodes (degree > 1000), we recommend caching only neighbor IDs rather than the full cluster to reduce memory pressure.
Sourcepub fn prefetch_neighbors<F>(
&self,
cache: &ThreadSafeCache,
neighbor_ids: &[i64],
get_cluster_fn: F,
direction: Direction,
)
pub fn prefetch_neighbors<F>( &self, cache: &ThreadSafeCache, neighbor_ids: &[i64], get_cluster_fn: F, direction: Direction, )
Prefetch neighboring clusters into cache for traversal optimization. This loads clusters for the next hop in a BFS/DFS traversal.
Arguments:
cache: The thread-safe cache to populateneighbor_ids: IDs of neighbors to prefetchget_cluster_fn: Function to load cluster if not in cachedirection: Direction of edges to prefetch
Sourcepub fn is_high_degree_node(&self) -> bool
pub fn is_high_degree_node(&self) -> bool
Check if this is a high-degree node that should get special cache treatment.
Trait Implementations§
Source§impl Clone for EdgeCluster
impl Clone for EdgeCluster
Source§fn clone(&self) -> EdgeCluster
fn clone(&self) -> EdgeCluster
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for EdgeCluster
impl RefUnwindSafe for EdgeCluster
impl Send for EdgeCluster
impl Sync for EdgeCluster
impl Unpin for EdgeCluster
impl UnwindSafe for EdgeCluster
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> 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