MCPcopy Create free account
hub / github.com/argumentcomputer/ix / group_consecutive

Function group_consecutive

crates/kernel/src/canonical_check.rs:598–622  ·  view source on GitHub ↗

Group consecutive equal elements in a sorted slice. Mirrors `group_by` (`src/ix/compile.rs:2644`) — the consecutive-equal grouping is sound because the input is already sorted by the same comparator.

(
  items: Vec<(KId<M>, &'a KConst<M>)>,
  ctx: &KMutCtx,
  resolve_ctor: &dyn Fn(&KId<M>) -> Option<KConst<M>>,
)

Source from the content-addressed store, hash-verified

596 let mut groups: Vec<Vec<(KId<M>, &'a KConst<M>)>> = Vec::new();
597 let mut current: Vec<(KId<M>, &'a KConst<M>)> = Vec::new();
598 for item in items {
599 if let Some(last) = current.last() {
600 let eq = compare_kconst(last.1, item.1, ctx, resolve_ctor)?.ordering
601 == Ordering::Equal;
602 if eq {
603 current.push(item);
604 } else {
605 groups.push(std::mem::replace(&mut current, vec![item]));
606 }
607 } else {
608 current.push(item);
609 }
610 }
611 if !current.is_empty() {
612 groups.push(current);
613 }
614 Ok(groups)
615}
616
617/// Sort kernel constants into canonical equivalence classes.
618///
619/// Iterative refinement (mirroring `sort_consts`,
620/// `src/ix/compile.rs:2727`):
621///
622/// 1. Seed with all members in a single class.
623/// 2. Build `KMutCtx` from the current partition.
624/// 3. Sort each multi-element class structurally; group adjacent equals.
625/// 4. Tiebreak each class by `id.addr` (kernel analogue of compile-side's

Callers

nothing calls this directly

Calls 3

compare_kconstFunction · 0.85
pushMethod · 0.80
is_emptyMethod · 0.45

Tested by

no test coverage detected