[][src]Crate sorted_iter

This crate provides set and relational operations for all iterators in the standard library that are known at compile time to be sorted.

Set operations

use sorted_iter::SortedIterator;

let primes = btreeset! { 2, 3, 5, 7, 11, 13u64 }.into_iter();
let fibs = btreeset! { 1, 2, 3, 5, 8, 13u64 }.into_iter();
let fib_primes = primes.intersection(fibs);

For available set operations, see SortedIterator. For sorted iterators in the std lib, see instances the for SortedByItem marker trait.

Relational operations

use sorted_iter::SortedPairIterator;

let cities = btreemap! { 1 => "New York", 2 => "Tokyo", 3u8 => "Berlin" }.into_iter();
let countries = btreemap! { 1 => "USA", 2 => "Japan", 3u8 => "Germany" }.into_iter();
let cities_and_countries = cities.join(countries);

For available relational operations, see SortedPairIterator. For sorted iterators in the std lib, see instances the for SortedByKey marker trait.

Transformations that retain order are allowed

use sorted_iter::*;

let odd = (1..31).step_by(2);
let multiples_of_3 = (3..30).step_by(3);
let either = odd.union(multiples_of_3);

Transformations that can change the order lose the sorted property

This example deliberately fails to compile
use sorted_iter::*;

let a = (1..31).map(|x| -x);
let b = (3..30).step_by(3);
let either = a.union(b); // does not compile!

Modules

sorted_iterator
sorted_pair_iterator

Traits

SortedIterator

set operations for iterators where the items are sorted according to the natural order

SortedPairIterator

relational operations for iterators of pairs where the items are sorted according to the key