Skip to content

no-std Step 4: replace std::collections::HashSet in ordered_iter_mut debug check #417

Description

@Mec-iS

Sub-task of #413.

What

The #[cfg(debug_assertions)] block inside ordered_iter_mut in src/linalg/basic/matrix.rs uses std::collections::HashSet, which is not available under no_std + alloc:

// Current — std-only
let mut seen = std::collections::HashSet::new();
for &o in &desired {
    assert!(o < len, ...);
    assert!(seen.insert(o), ...);
}

Replace with a sorted-Vec dedup approach that works under no_std + alloc:

// no_std-compatible
let mut sorted_check = desired.clone();
sorted_check.sort_unstable();
let original_len = sorted_check.len();
sorted_check.dedup();
assert_eq!(sorted_check.len(), original_len, "iterator_mut: aliasing detected");
for &o in &desired {
    assert!(o < len, "iterator_mut: offset {o} out of bounds (len={len})");
}

This preserves the debug invariant (all offsets distinct and in-bounds) with O(n log n) instead of O(n) hash overhead — acceptable for a debug-only path.

Acceptance

  • No std::collections imports remain in matrix.rs outside of #[cfg(test)]
  • cargo test --all-features passes (existing test_iter_mut and test_row_major must pass)
  • cargo build --no-default-features does not pull in std::collections

Estimated effort: ~1 hr

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions