iter-merge
A high-performance iterator merging library for Rust that efficiently combines multiple iterators into a single iterator, yielding smallest item first.
Note: only compares the first items across provided iterators. The output would be sorted only if the iterators themselves are sorted.
Features
- Lazy iterator consumption: each
.next()advances only one iterator - Support for custom comparison functions
- Multiple storage backends:
VecandArray(for no-std and no-alloc compatibility) - Additional
Peekablemethods
Usage
use merge;
let iter1 = vec!;
let iter2 = vec!;
let result = merge.into_vec;
assert_eq!;
Custom Comparison
use ;
let mut merged = from_iter
.into_builder
.max_by
.build;
let result = merged.into_vec;
assert_eq!;
Performance
It's 1.45-1.65x faster than itertools::kmerge in my benchmarks and scales as O(item_count + log₂(iterator_count)) (just as well as itertools::kmerge)
Features
The crate supports following feature flags:
alloc: Enables heap-allocated storage withVecStorageand methods likeMergeIter::into_vec
Testing
Fuzzing:
Use cargo-fuzz
Miri:
Benchmarks:
RUSTFLAGS='-C target-cpu=native --cfg benchmarking'
(Benchmarking dependencies are behind benchmarking cfg option)
MSRV
The minimum supported Rust version for this crate is 1.68.0. This may change in a major release, but it is unlikely.
Contributing
Contributions are welcome. For major changes, please open an issue first to discuss what you would like to change.
Related Projects
itertools- General iterator utilities (includeskmerge)