(&self, pos: Position<NodeId>)
| 336 | } |
| 337 | |
| 338 | fn find_block_end(&self, pos: Position<NodeId>) -> PristineResult<GraphNode<NodeId>> { |
| 339 | // Handle ROOT position specially |
| 340 | if pos.change.is_root() { |
| 341 | return Ok(GraphNode::ROOT); |
| 342 | } |
| 343 | |
| 344 | let table = self.txn.open_multimap_table(GRAPH)?; |
| 345 | |
| 346 | let change_id = pos.change.get(); |
| 347 | let target_pos = pos.pos.get(); |
| 348 | |
| 349 | // FIRST: Check for empty span at exact position using direct lookup. |
| 350 | // This is important because empty vertices like inode markers (e.g., V[9:9]) |
| 351 | // must be found when predecessors references position 9, even if there's |
| 352 | // another span like V[0:9] that also ends at position 9. |
| 353 | // Without this direct lookup, iteration would return V[0:9] first since |
| 354 | // it has a lower start position. |
| 355 | let empty_key = encode_vertex(change_id, target_pos, target_pos); |
| 356 | if try_is_present(table.get(&empty_key)?)? { |
| 357 | return Ok(GraphNode { |
| 358 | change: NodeId::new(change_id), |
| 359 | start: ChangePosition::new(target_pos), |
| 360 | end: ChangePosition::new(target_pos), |
| 361 | }); |
| 362 | } |
| 363 | |
| 364 | // SECOND: binary-search the vertices that end at or contain this |
| 365 | // position (the historical full-range scan made each call |
| 366 | // O(change vertices) — review ::15, 2026-09-16). Under within-change |
| 367 | // hunk disjointness: an ends-at-pos span (unique when it exists) is |
| 368 | // the last vertex key ≤ (pos-1, MAX); a contains-pos span (unique |
| 369 | // when it exists) is the last vertex key ≤ (pos, MAX); an |
| 370 | // ends-at-pos span starts strictly before any contains-pos span, so |
| 371 | // this order preserves the historical first-match semantics. |
| 372 | if target_pos > 0 { |
| 373 | let before_upper = encode_vertex(change_id, target_pos - 1, u64::MAX); |
| 374 | if let Some((v_change, v_start, v_end)) = table |
| 375 | .range::<&[u8; 24]>(&encode_vertex(change_id, 0, 0)..=&before_upper)? |
| 376 | .next_back() |
| 377 | .transpose()? |
| 378 | .map(|(key, _values)| decode_vertex(key.value())) |
| 379 | { |
| 380 | if v_change == change_id && v_end == target_pos && v_start < v_end { |
| 381 | return Ok(GraphNode { |
| 382 | change: NodeId::new(change_id), |
| 383 | start: ChangePosition::new(v_start), |
| 384 | end: ChangePosition::new(v_end), |
| 385 | }); |
| 386 | } |
| 387 | } |
| 388 | } |
| 389 | |
| 390 | let contains_upper = encode_vertex(change_id, target_pos, u64::MAX); |
| 391 | if let Some((v_change, v_start, v_end)) = table |
| 392 | .range::<&[u8; 24]>(&encode_vertex(change_id, 0, 0)..=&contains_upper)? |
| 393 | .next_back() |
| 394 | .transpose()? |
| 395 | .map(|(key, _values)| decode_vertex(key.value())) |
nothing calls this directly
no test coverage detected