MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / find_block_in_inode

Method find_block_in_inode

atomic-core/src/pristine/txn/read.rs:1590–1648  ·  view source on GitHub ↗
(
        &self,
        inode: Inode,
        pos: Position<NodeId>,
    )

Source from the content-addressed store, hash-verified

1588 }
1589
1590 fn find_block_in_inode(
1591 &self,
1592 inode: Inode,
1593 pos: Position<NodeId>,
1594 ) -> Result<Option<GraphNode<NodeId>>, Self::InodeError> {
1595 let table = &self.inode_graph_table;
1596 let inode_id = inode.get();
1597 let change_id = pos.change.get();
1598 let target_pos = pos.pos.get();
1599
1600 // Fast path: probe exact start position
1601 let exact_start = encode_inode_vertex(inode_id, change_id, target_pos, 0);
1602 let exact_end = encode_inode_vertex(inode_id, change_id, target_pos, u64::MAX);
1603 let mut empty_match = None;
1604
1605 for result in table.range::<&[u8; 32]>(&exact_start..=&exact_end)? {
1606 let (key, _) = result?;
1607 let (_, v_change, v_start, v_end) = decode_inode_vertex(key.value());
1608 if v_change != change_id || v_start != target_pos {
1609 continue;
1610 }
1611 if v_start != v_end {
1612 return Ok(Some(GraphNode {
1613 change: NodeId::new(v_change),
1614 start: ChangePosition::new(v_start),
1615 end: ChangePosition::new(v_end),
1616 }));
1617 }
1618 if empty_match.is_none() {
1619 empty_match = Some(GraphNode {
1620 change: NodeId::new(v_change),
1621 start: ChangePosition::new(v_start),
1622 end: ChangePosition::new(v_end),
1623 });
1624 }
1625 }
1626
1627 if let Some(m) = empty_match {
1628 return Ok(Some(m));
1629 }
1630
1631 // Slow path: scan all vertices for this change within the inode
1632 let start_key = encode_inode_vertex(inode_id, change_id, 0, 0);
1633 let end_key = encode_inode_vertex(inode_id, change_id, u64::MAX, u64::MAX);
1634
1635 for result in table.range::<&[u8; 32]>(&start_key..=&end_key)? {
1636 let (key, _) = result?;
1637 let (_, v_change, v_start, v_end) = decode_inode_vertex(key.value());
1638 if v_change == change_id && v_start <= target_pos && target_pos < v_end {
1639 return Ok(Some(GraphNode {
1640 change: NodeId::new(v_change),
1641 start: ChangePosition::new(v_start),
1642 end: ChangePosition::new(v_end),
1643 }));
1644 }
1645 }
1646
1647 Ok(None)

Callers 9

alive_reachesFunction · 0.45
alive_reaches_inodeFunction · 0.45
select_linear_successorFunction · 0.45
find_startMethod · 0.45

Calls 4

encode_inode_vertexFunction · 0.85
decode_inode_vertexFunction · 0.85
is_noneMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected