relate_executor/graph/accounting/adjacency.rs
1//! The adjacency half of the admission estimate and wall (ADR-0529,
2//! ADR-0551, ADR-0599): the adjacency-tier and sealed-tier byte terms of a
3//! batch, the per-type adjacency limits, and the dense-span placement
4//! shared with the group admission walk. Split from the parent so the
5//! live-size accounting and the adjacency pricing grow independently.
6
7use std::collections::HashMap;
8use std::mem::size_of;
9
10use relate_core::{Error, NodeId};
11
12use crate::adjacency::{AdjHop, SealedRegion, Supersede, MAX_SPAN_TYPES};
13use crate::graph::adjacency::{AdjSide, ChunkHops};
14use crate::graph::*;
15
16impl Graph {
17 /// The adjacency share of a batch's live-size delta, split into the
18 /// refusable growth — a create's hop and slot growth (dense span or the
19 /// side-map entry a wide id takes, as the store's own estimator charges
20 /// it), plus a founding delete's dense side-table span — and the spill
21 /// the checkpoint fold reclaims: a delete's region, chunk, and tombstone
22 /// terms, and the side-map entry a founding delete at a wide id takes
23 /// (ADR-0529).
24 ///
25 /// Seeded from `spans` by the same protocol as the chain spans: the
26 /// adjacency tier's dense spans and the sealed span table's take their
27 /// start from the seed — not the committed graph — and come back
28 /// advanced ([`AdjSpanAdvance`], the spans this walk owns and nothing
29 /// else), so a group-mate inside a rung the group already reserved
30 /// prices no adjacency growth; the caller merges the advance with the
31 /// chain-span one at the admission entry point.
32 pub(in crate::graph) fn estimate_adj_delta(
33 &self,
34 ops: &[RedoOp],
35 spans: &crate::memory::DenseSpans,
36 ) -> (AdjDelta, AdjSpanAdvance) {
37 let mut out = SideAdmission::new(self.out_side(), spans.adj_out);
38 let mut inn = SideAdmission::new(self.in_side(), spans.adj_in);
39 let mut fresh_ids = FreshIds::new();
40 let mut delta = AdjDelta::default();
41 // One traversal carries both halves: the create terms, and the
42 // batch's own rel identities and pending delete tombstones the
43 // delete half prices. A rel created earlier in this batch is
44 // invisible to the committed store, so its delete resolves from
45 // `created` — only creates already walked are in it, so a delete
46 // that precedes its create tombstones nothing, as in the apply path;
47 // a rel the store holds comes from its live version.
48 let mut created: HashMap<RelId, (NodeId, NodeId, u32)> = HashMap::new();
49 let mut pending_out: PendingTombstones = HashMap::new();
50 let mut pending_in: PendingTombstones = HashMap::new();
51 for op in ops {
52 match op {
53 RedoOp::CreateRel {
54 id,
55 start,
56 end,
57 rel_type,
58 ..
59 } => {
60 let type_id = fresh_ids.resolve(self, rel_type);
61 created.insert(*id, (*start, *end, type_id));
62 delta.refusable += out.create(*start, type_id) + inn.create(*end, type_id);
63 }
64 RedoOp::DeleteRel { id } => {
65 let Some((start, end, type_id)) = created
66 .get(id)
67 .copied()
68 // The store's rels answer through the one live-identity
69 // spelling (a dead version's delete tombstones nothing,
70 // as in the apply path).
71 .or_else(|| self.rel_live_identity(*id))
72 else {
73 continue;
74 };
75 for (pending, node) in [(&mut pending_out, start), (&mut pending_in, end)] {
76 pending
77 .entry(node)
78 .or_default()
79 .entry(type_id)
80 .or_default()
81 .insert(*id);
82 }
83 }
84 _ => {}
85 }
86 }
87 // Each delete records one tombstone per endpoint that does not hold
88 // one yet (ADR-0551); the region, chunk, and tombstone terms are
89 // reclaimed at the checkpoint fold, so they are spill and never
90 // refuse a batch (ADR-0529: a delete at the cap commits). The
91 // founding side-table slot is the exception — the dense span only
92 // grows (ADR-0086) — so it stays refusable.
93 let (spilled, sealed) = self.estimate_delete_spill(&pending_out, &pending_in, spans);
94 (
95 delta + spilled,
96 AdjSpanAdvance {
97 adj_out: out.span,
98 adj_in: inn.span,
99 sealed_out: sealed.out,
100 sealed_in: sealed.inn,
101 },
102 )
103 }
104
105 /// The adjacency tier's structural limits (ADR-0599), the ones its
106 /// field widths state: a node holds at most [`MAX_SPAN_TYPES`] distinct
107 /// rel types in one direction (the span length's `u16`), and one
108 /// direction's arena at most `u32::MAX` stream bytes (the entry
109 /// offset's `u32`). Enforced here, at admission, before the redo is
110 /// logged — the tier's own mutation paths are infallible by design, so
111 /// the wall they must never hit is refused upstream. A delete never
112 /// breaches either: it founds a sealed entry only for a type the node
113 /// already holds, and its tombstone terms reclaim at the fold.
114 ///
115 /// `earlier` are the ops of slots this group commit already accepted:
116 /// the type wall is per group, not per slot — two slots that each add
117 /// types under the bound must be refused when their combined types
118 /// cross it, so this slot's creates are counted on top of the group's.
119 /// Each earlier slot passed the same walk at its own admission, so the
120 /// combined walk never fails on the earlier batches alone.
121 pub fn enforce_adjacency_limits(&self, ops: &[RedoOp], earlier: &[&[RedoOp]]) -> Result<()> {
122 let mut fresh_ids = FreshIds::new();
123 let mut out = TypeWall::new(self.out_side());
124 let mut inn = TypeWall::new(self.in_side());
125 // A second accumulator beside `SideAdmission`, stated: the byte
126 // estimate is per slot and only runs under a configured size limit,
127 // while the wall is per group and unconditional — the two walks
128 // cannot share a gate.
129 let mut growth = 0u64;
130 for batch in earlier.iter().copied().chain(std::iter::once(ops)) {
131 for op in batch {
132 if let RedoOp::CreateRel {
133 start,
134 end,
135 rel_type,
136 ..
137 } = op
138 {
139 let type_id = fresh_ids.resolve(self, rel_type);
140 out.record(*start, type_id)?;
141 inn.record(*end, type_id)?;
142 // One stored hop per endpoint reaches an arena at the
143 // fold. A delete adds none: its tombstones live in the
144 // entry column, never in the arena's byte buffer, so a
145 // delete is never refused for a bound it shrinks toward
146 // (ADR-0529's rule for the byte cap, on the field bound).
147 growth = growth.saturating_add(2 * size_of::<AdjHop>() as u64);
148 }
149 }
150 }
151 // The arena wall, per direction — each arena's own streams plus this
152 // batch's sealed-tier growth against its own offset field. The
153 // store's whole live charge is deliberately not compared: it prices
154 // structures no arena holds, and refusing on it would freeze a store
155 // whose live bytes sit above the bound — deletes included. A fold
156 // the arena itself refuses degrades instead (see `put_chunk`), so
157 // this wall is the early, loud spelling of the same bound.
158 for arena_bytes in self
159 .sides(relate_ir::Direction::Both)
160 .map(|(side, _)| side.sealed().arena_bytes())
161 {
162 if sealed_arena_breaches(arena_bytes, growth) {
163 return Err(Error::capacity_sealed_arena(
164 arena_bytes.saturating_add(growth),
165 u32::MAX as u64,
166 ));
167 }
168 }
169 Ok(())
170 }
171
172 /// The batch's delete terms: every delete
173 /// records one tombstone per endpoint that does not hold one yet
174 /// (ADR-0551) — a sealed chunk grows its tombstone vec, a never-sealed
175 /// type adds its on-demand chunk to the endpoint's region, all reclaimed
176 /// at the next checkpoint fold and so spill that never refuses a batch
177 /// (ADR-0529) — while a founding delete's dense side-table span is
178 /// permanent (ADR-0086) and stays refusable; its side-map entry,
179 /// reclaimed with the region, is spill like the rest.
180 /// The delete half always supersedes as a delete: no batch-reposition
181 /// path exists (a reposition prices per event through
182 /// [`Graph::price_sealed_event`]), so `Supersede::Deleted` is stated
183 /// here once, and the shared leaves keep the parameter for the
184 /// per-event spelling.
185 fn estimate_delete_spill(
186 &self,
187 pending_out: &PendingTombstones,
188 pending_in: &PendingTombstones,
189 spans: &crate::memory::DenseSpans,
190 ) -> (AdjDelta, SealedSpanAdvance) {
191 let sealed_slot = sealed_slot();
192 let sealed_overflow = crate::memory::overflow_entry_bytes(sealed_slot);
193 let (out, sealed_out) = price_side(
194 self.out_side().sealed(),
195 pending_out,
196 sealed_slot,
197 sealed_overflow,
198 spans.sealed_out,
199 );
200 let (inn, sealed_in) = price_side(
201 self.in_side().sealed(),
202 pending_in,
203 sealed_slot,
204 sealed_overflow,
205 spans.sealed_in,
206 );
207 (
208 out + inn,
209 SealedSpanAdvance {
210 out: sealed_out,
211 inn: sealed_in,
212 },
213 )
214 }
215
216 /// One write event's sealed-tier price on both endpoints' sides — the
217 /// per-event spelling of [`price_side`], the one formula the admission
218 /// estimate prices whole batches with. A delete records its tombstone on
219 /// demand, founding the entry when the region holds none (ADR-0551); a
220 /// reposition supersedes only a position a sealed chunk holds, so its
221 /// missing-chunk arm prices nothing. Priced before the event lands, so
222 /// the counts the terms read are the pre-mutation ones.
223 pub(in crate::graph) fn price_sealed_event(
224 &self,
225 start: NodeId,
226 end: NodeId,
227 type_id: u32,
228 id: RelId,
229 supersede: Supersede,
230 ) -> (i64, i64) {
231 // The one-event spelling of [`price_side`]: the per-key and per-node
232 // bodies called once per endpoint, no nested batch maps.
233 let ids = HashSet::from([id]);
234 let sealed_slot = sealed_slot();
235 let sealed_overflow = crate::memory::overflow_entry_bytes(sealed_slot);
236 let mut refusable = 0i64;
237 let mut spill = 0i64;
238 for (sealed, node) in [
239 (self.out_side().sealed(), start),
240 (self.in_side().sealed(), end),
241 ] {
242 let region = sealed.region(node);
243 let (mut entries, mut tombstones) = sealed.entry_counts();
244 spill += price_sealed_key(
245 region,
246 type_id,
247 &ids,
248 &mut entries,
249 &mut tombstones,
250 supersede,
251 );
252 let mut span = sealed.span();
253 let (node_refusable, node_spill) = price_sealed_node(
254 &mut span,
255 region,
256 node,
257 sealed_slot,
258 sealed_overflow,
259 supersede,
260 );
261 refusable += node_refusable;
262 spill += node_spill;
263 }
264 (refusable, spill)
265 }
266}
267
268/// The admission estimates' fresh-name resolver (LABS-425, stellar round
269/// 1): a name the interner does not know — a label or rel type the
270/// not-yet-applied batch mints — resolves to a descending id below the
271/// committed range, one id per distinct name. Both estimate terms
272/// ([`Graph::estimate_adj_delta`] here,
273/// [`Graph::estimate_stats_entry_growth`] in
274/// graph/degree_stats_estimate.rs) resolved this ladder by hand before;
275/// the descending-id collision invariant (fresh ids never collide with
276/// committed ids or each other) now lives in exactly one place.
277#[derive(Clone, Debug, PartialEq)]
278pub(in crate::graph) struct FreshIds {
279 fresh: HashMap<String, u32>,
280 next: u32,
281}
282
283impl FreshIds {
284 pub(in crate::graph) fn new() -> Self {
285 Self {
286 fresh: HashMap::new(),
287 next: u32::MAX,
288 }
289 }
290
291 /// The interned id, else this batch's earlier mint, else a new
292 /// descending id minted and memoized.
293 pub(in crate::graph) fn resolve(&mut self, g: &Graph, name: &str) -> u32 {
294 g.interner
295 .get_id(name)
296 .or_else(|| self.fresh.get(name).copied())
297 .unwrap_or_else(|| {
298 let id = self.next;
299 self.next = self.next.saturating_sub(1);
300 self.fresh.insert(name.to_string(), id);
301 id
302 })
303 }
304}
305
306/// A batch's pending delete tombstones on one side: per node, per rel
307/// type, the rel ids that will record one.
308type PendingTombstones = HashMap<NodeId, HashMap<u32, HashSet<RelId>>>;
309
310/// An adjacency estimate's two shares (ADR-0529): `refusable` growth is
311/// committed structure an over-cap batch is refused for; `spill` is what the
312/// checkpoint fold reclaims, so it never refuses a batch.
313#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
314pub(in crate::graph) struct AdjDelta {
315 pub(in crate::graph) refusable: i64,
316 pub(in crate::graph) spill: i64,
317}
318
319/// The adjacency half of a group seed's advance — the four spans
320/// [`Graph::estimate_adj_delta`] owns. A walk returns only the spans it
321/// prices, never a full copy with foreign fields echoed back; the one
322/// merge into the group seed happens at the admission entry point
323/// ([`Graph::estimate_redo_delta_with_constraint_growth`]). Mirrors the
324/// chain half's (`memory::ChainSpanAdvance`) derives: one protocol, one
325/// struct shape.
326#[derive(Clone, Copy, Debug, PartialEq, Eq)]
327pub(in crate::graph) struct AdjSpanAdvance {
328 pub(in crate::graph) adj_out: usize,
329 pub(in crate::graph) adj_in: usize,
330 pub(in crate::graph) sealed_out: usize,
331 pub(in crate::graph) sealed_in: usize,
332}
333
334/// The two sealed span-table spans one delete-half estimate advanced —
335/// named, so the same-typed pair cannot be transposed at
336/// [`estimate_delete_spill`](Graph::estimate_delete_spill)'s seam (the
337/// wrong-direction's-seed class this protocol exists to remove).
338#[derive(Clone, Copy, Debug, PartialEq, Eq)]
339struct SealedSpanAdvance {
340 out: usize,
341 inn: usize,
342}
343
344impl std::ops::Add for AdjDelta {
345 type Output = Self;
346
347 fn add(self, other: Self) -> Self {
348 Self {
349 refusable: self.refusable + other.refusable,
350 spill: self.spill + other.spill,
351 }
352 }
353}
354
355/// What one [`place_in_span`](crate::memory::place_in_span) answer charges
356/// — the one mapping from the placement policy's result to bytes, shared by
357/// the create loop and the delete phase: `dense` growth is permanent
358/// structure, `side_entry` the reclaimable entry a wide id takes. An id the
359/// array cannot index is refused by the commit's own validation before
360/// anything applies, so it prices nothing.
361struct PlacementCharge {
362 dense: i64,
363 side_entry: bool,
364}
365
366fn place(span: &mut usize, node: NodeId, slot: u64) -> PlacementCharge {
367 match crate::memory::place_in_span(span, node, slot) {
368 None | Some(crate::memory::SpanPlacement::Inside) => PlacementCharge {
369 dense: 0,
370 side_entry: false,
371 },
372 Some(crate::memory::SpanPlacement::Grew { bytes, .. }) => PlacementCharge {
373 dense: bytes as i64,
374 side_entry: false,
375 },
376 Some(crate::memory::SpanPlacement::SideEntry) => PlacementCharge {
377 dense: 0,
378 side_entry: true,
379 },
380 }
381}
382
383/// One side's create-admission state: the committed pair, the dense span the
384/// batch has grown so far (seeded from the admission walk's
385/// [`DenseSpans`](crate::memory::DenseSpans), not the committed graph — a
386/// group-mate inside a rung the group reserved prices no growth), the wide
387/// ids already priced, and the simulated chunk lists the batch's creates
388/// have built. One op touches both sides by
389/// the same rule, so the loop calls [`SideAdmission::create`] once per
390/// endpoint.
391struct SideAdmission<'a> {
392 side: AdjSide<'a>,
393 span: usize,
394 wide: HashSet<NodeId>,
395 pending: HashMap<NodeId, Vec<ChunkHops>>,
396 slot: u64,
397 overflow: u64,
398}
399
400impl<'a> SideAdmission<'a> {
401 fn new(side: AdjSide<'a>, seed_span: usize) -> Self {
402 Self {
403 span: seed_span,
404 side,
405 wide: HashSet::new(),
406 pending: HashMap::new(),
407 slot: adj_slot(),
408 overflow: crate::memory::overflow_entry_bytes(adj_value()),
409 }
410 }
411
412 /// The refusable bytes one created rel adds at `node` on this side: the
413 /// node's slot when it has no adjacency entry yet, and the hop growth.
414 fn create(&mut self, node: NodeId, type_id: u32) -> i64 {
415 let mut bytes = 0;
416 if !self.side.delta().contains_key(&node) {
417 // A dense growth is committed structure (refusable); a
418 // side-map entry is priced once per node per batch — the loop
419 // can revisit a node across its ops, so the dedupe is here.
420 let placed = place(&mut self.span, node, self.slot);
421 bytes += placed.dense;
422 if placed.side_entry && self.wide.insert(node) {
423 bytes += self.overflow as i64;
424 }
425 }
426 bytes
427 + bump_adj(&mut self.pending, node, type_id, || {
428 self.side.hop_counts(node)
429 })
430 }
431}
432
433/// One direction's share of the span-length limit
434/// ([`Graph::enforce_adjacency_limits`]): per touched node, the distinct
435/// types it already holds and the new types this batch would add. Held is
436/// the sealed span's own entries unioned with the delta chunks — the same
437/// vocabulary the span length counts, never the hop-bearing chunk list
438/// alone (a type whose delta chunk a fold's fully-reclaimed arm removed
439/// keeps its sealed entry, so `hop_counts` would undercount it). A type
440/// the node holds is free; a fresh one counts against
441/// [`MAX_SPAN_TYPES`].
442struct TypeWall<'a> {
443 side: AdjSide<'a>,
444 nodes: HashMap<NodeId, (HashSet<u32>, HashSet<u32>)>,
445}
446
447impl<'a> TypeWall<'a> {
448 fn new(side: AdjSide<'a>) -> Self {
449 Self {
450 side,
451 nodes: HashMap::new(),
452 }
453 }
454
455 /// One created rel's `(node, type)` pair. The held set is read once
456 /// per touched node; the fresh set dedupes a batch that repeats a new
457 /// type on the same node.
458 fn record(&mut self, node: NodeId, type_id: u32) -> Result<()> {
459 let (held, fresh) = self.nodes.entry(node).or_insert_with(|| {
460 let mut held: HashSet<u32> = self
461 .side
462 .sealed()
463 .region(node)
464 .map(|r| r.type_ids().into_iter().collect())
465 .unwrap_or_default();
466 if let Some(adj) = self.side.delta().get(&node) {
467 held.extend(adj.chunks.iter().map(|c| c.type_id));
468 }
469 (held, HashSet::new())
470 });
471 if !held.contains(&type_id) && fresh.insert(type_id) {
472 let count = held.len() + fresh.len();
473 if count > MAX_SPAN_TYPES {
474 return Err(Error::capacity_adjacency_types(
475 count as u64,
476 MAX_SPAN_TYPES as u64,
477 ));
478 }
479 }
480 Ok(())
481 }
482}
483
484/// The entry-offset bound ([`Graph::enforce_adjacency_limits`]): one
485/// arena's own stream bytes plus the batch's growth stay under the `u32`
486/// the entry offsets address. Saturating so an over-bound store refuses,
487/// never wraps.
488pub(in crate::graph) fn sealed_arena_breaches(arena_bytes: u64, growth: u64) -> bool {
489 !crate::adjacency::arena_admits(arena_bytes, growth)
490}
491
492impl Graph {
493 /// The sealed tier's whole reserved heap, both directions — the recount
494 /// oracle's term ([`Graph::structure_bytes`]); the write path charges
495 /// its events per region through [`Graph::price_sealed_event`] instead
496 /// (ADR-0599).
497 pub(in crate::graph) fn sealed_floor(&self) -> u64 {
498 let mut n = 0u64;
499 for sealed in self
500 .sides(relate_ir::Direction::Both)
501 .map(|(side, _)| side.sealed())
502 {
503 let tier = sealed.tier_bytes();
504 n = n.saturating_add(tier.arena);
505 n = n.saturating_add(tier.index);
506 }
507 n
508 }
509}
510
511/// One side's share of the sealed-tier terms
512/// ([`Graph::estimate_delete_spill`](Graph::estimate_delete_spill)'s phase
513/// 2, and the write path's per-event spelling
514/// [`Graph::price_sealed_event`]): per
515/// node, the dense span-table growth (permanent, refusable), the entry-array
516/// growth across every joining type — one before-and-after term per region,
517/// never one per type, or the reserved model's pow2 steps misprice a batch
518/// that joins several — then each key's own terms (all fold-reclaimed,
519/// spill): a sealed chunk's tombstone-vec growth, or a joining chunk's
520/// tombstones. `supersede` selects the missing-chunk arm: a delete records
521/// its tombstone on demand and so founds the entry (ADR-0551); a
522/// reposition only supersedes a position a sealed chunk holds
523/// ([`AdjSide::reposition`]'s delta-only arm writes no tombstone), so a
524/// missing chunk prices nothing. `seed_span` is the span-table span the
525/// admission walk carries (a group-mate inside a rung the group reserved
526/// prices no founding growth) — not `sealed.span()`, the committed one —
527/// and the advanced span comes back beside the delta. This is the delete
528/// half's spelling: it supersedes as a delete (`Supersede::Deleted`), the
529/// only mode a batch ever prices here.
530fn price_side(
531 sealed: &SealedArena,
532 pending: &PendingTombstones,
533 sealed_slot: u64,
534 sealed_overflow: u64,
535 seed_span: usize,
536) -> (AdjDelta, usize) {
537 let mut span = seed_span;
538 let (mut entries, mut tombstones) = sealed.entry_counts();
539 let mut priced = AdjDelta::default();
540 for (node, keys) in pending {
541 // One key loop prices every key's own term: a chunk the region
542 // already holds grows its tombstone vec (a delete after a
543 // reposition updates the existing slot in place), a type the
544 // region does not hold joins it, inserting its zero-hop entry and
545 // bringing its tombstones — priced once, here, never again in a
546 // region-level arm.
547 let region = sealed.region(*node);
548 for (type_id, ids) in keys {
549 priced.spill += price_sealed_key(
550 region,
551 *type_id,
552 ids,
553 &mut entries,
554 &mut tombstones,
555 Supersede::Deleted,
556 );
557 }
558 // The region-level term, once per node: a founding delete grows the
559 // node's dense span permanently (refusable). Each node reaches this
560 // arm once (`pending` is keyed by node), so the entry prices
561 // unconditionally — the per-batch dedupe is the create loop's, where
562 // a node can recur.
563 let (node_refusable, node_spill) = price_sealed_node(
564 &mut span,
565 region,
566 *node,
567 sealed_slot,
568 sealed_overflow,
569 Supersede::Deleted,
570 );
571 priced.refusable += node_refusable;
572 priced.spill += node_spill;
573 }
574 (priced, span)
575}
576
577/// One `(node, key)` entry's sealed-tier spill terms — the per-key body
578/// [`price_side`] loops and [`Graph::price_sealed_event`] calls once per
579/// endpoint. `entries`/`tombstones` are the running entry-column counts a
580/// joining chunk grows.
581fn price_sealed_key(
582 region: Option<SealedRegion<'_>>,
583 type_id: u32,
584 ids: &HashSet<RelId>,
585 entries: &mut usize,
586 tombstones: &mut usize,
587 supersede: Supersede,
588) -> i64 {
589 match region.filter(|r| r.has_chunk(type_id)) {
590 Some(region) => {
591 let fresh = region.fresh_tombstone_count(type_id, ids);
592 region.tombstone_growth_bytes(type_id, fresh) as i64
593 }
594 None if supersede == Supersede::Deleted => {
595 let mut spill = crate::adjacency::fresh_sealed_chunk_floor_bytes(ids.len()) as i64;
596 spill += crate::adjacency::entry_column_growth(*entries, *tombstones, 1) as i64;
597 *entries += 1;
598 *tombstones += 1;
599 spill
600 }
601 None => 0,
602 }
603}
604
605/// One node's founding-delete span term — the per-node body [`price_side`]
606/// and [`Graph::price_sealed_event`] share: the dense span a founding delete
607/// grows (refusable) or the side-map entry it takes (spill, reclaimed with
608/// the region it founds).
609fn price_sealed_node(
610 span: &mut usize,
611 region: Option<SealedRegion<'_>>,
612 node: NodeId,
613 sealed_slot: u64,
614 sealed_overflow: u64,
615 supersede: Supersede,
616) -> (i64, i64) {
617 if region.is_none() && supersede == Supersede::Deleted {
618 // The one placement mapping, shared with the create loop: dense
619 // growth is permanent structure, the side entry reclaimable.
620 let charge = place(span, node, sealed_slot);
621 return (
622 charge.dense,
623 i64::from(charge.side_entry) * sealed_overflow as i64,
624 );
625 }
626 (0, 0)
627}
628
629fn bump_adj(
630 sim: &mut HashMap<NodeId, Vec<ChunkHops>>,
631 node: NodeId,
632 type_id: u32,
633 init: impl FnOnce() -> Vec<ChunkHops>,
634) -> i64 {
635 let chunks = sim.entry(node).or_insert_with(init);
636 let before = crate::adjacency::adjacency_bytes(chunks.iter().map(|c| c.hops));
637 if let Some(slot) = chunks.iter_mut().find(|c| c.type_id == type_id) {
638 slot.hops += 1;
639 } else {
640 chunks.push(ChunkHops { type_id, hops: 1 });
641 }
642 crate::adjacency::adjacency_bytes(chunks.iter().map(|c| c.hops)) as i64 - before as i64
643}