int-interval 0.3.0

A small, no_std half-open interval algebra library for primitive integer types.
Documentation

int-interval

A zero-allocation, half-open interval library for primitive integers.

  • Half-open intervals [start, end)
  • Branch-light, allocation-free, const fn friendly
  • Close to std::ops::Range performance

Supported types:

U8CO/I8CO, U16CO/I16CO, U32CO/I32CO, U64CO/I64CO, U128CO/I128CO, UsizeCO/IsizeCO

Interval Model

  • [start, end) with start < end
  • len = end - start
  • Empty intervals are not representable
U8CO::try_new(2,5) = {2,3,4}

Core API

Construction:

let x = U8CO::try_new(2,8).unwrap();
let y = U8CO::new_unchecked(2,8); // unchecked

Accessors:

x.start()
x.end_excl()
x.len()
x.contains(v)
x.iter()

Predicates:

x.intersects(y)
x.is_adjacent(y)
x.is_contiguous_with(y)

Interval Algebra

  • Intersection [A ∩ B]Option<T>
  • Convex HullT
  • BetweenOption<T>
  • UnionOneTwo<T>
  • DifferenceZeroOneTwo<T>
  • Symmetric DifferenceZeroOneTwo<T>
pub enum OneTwo<T> { One(T), Two(T,T) }
pub enum ZeroOneTwo<T> { Zero, One(T), Two(T,T) }
  • Fully stack-based, no heap allocation

Minkowski Arithmetic (New)

  • Interval-to-interval: add, sub, mul, div
  • Interval-to-scalar: add_n, sub_n, mul_n, div_n
  • Checked operations, overflow-safe
  • Supports negative numbers (i8/signed types)
  • Fully const fn compatible, preserves [start,end) semantics
let a = I8CO::try_new(-2,3).unwrap();
let b = I8CO::try_new(-1,2).unwrap();
let res = a.minkowski_mul(b).unwrap(); // [-2,3)

Features

  • Fast primitive interval algebra
  • Predictable, allocation-free behavior
  • Suitable for embedded or constrained environments
  • Ideal for:
    • Geometry / raster operations
    • Compiler span analysis
    • Scheduling ranges
    • DNA / sequence slicing
    • Numeric algorithms

Not designed for large interval sets or tree-based queries.


License

MIT