Uses old Rust 2015

0.1.0 Feb 6, 2016

#21 in #ordering

Download history 87/week @ 2024-04-19 127/week @ 2024-04-26 110/week @ 2024-05-03 339/week @ 2024-05-10 120/week @ 2024-05-17 142/week @ 2024-05-24 353/week @ 2024-05-31 87/week @ 2024-06-07 322/week @ 2024-06-14 287/week @ 2024-06-21 208/week @ 2024-06-28 183/week @ 2024-07-05 165/week @ 2024-07-12

378 downloads per month

15KB
168 lines

ordered_zip

Build Status Crates-Downloads Crates-Version Crates-License

Synopsis

An iterator that iterates two other iterators simultaneously, prioritized by pairwise ordering.

Motivation

Sometimes there is the need to iterate over two sequences prioritized by the pairwise orderings of their items (such as for implementing operations on a sparse vector). The ordered_zip crate aims to provide a versatile API for this.

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisities

The ordered_zip crate does not have any dependencies.

Installing

Add the following to your dependencies in your project's Cargo.toml:

ordered_zip = "0.1.0"

… or whatever other version is more up-to-date.

Then add …

extern crate ordered_zip;

… and …

use ordered_zip;

… to your crate's root file (e.g. lib.rs, main.rs).

Example Use

use std::cmp::Ordering;
use ordered_zip::Compare;
use ordered_zip::NonGreedy;

struct IndexCompare;

impl<T, U> Compare<(usize, T), (usize, U)> for IndexCompare {
    fn cmp(lhs: &(usize, T), rhs: &(usize, U)) -> Ordering {
        (lhs.0).cmp(&(rhs.0))
    }
}

type NonGreedyStrategy = NonGreedy<IndexCompare>;

let v1 = vec![(0, 0.1), (1, 0.2), (3, 0.1), (4, 0.25), (7, 0.75)];
let v2 = vec![(2, 0.01), (4, 0.3), (5, 0.9), (9, 0.15), (10, 0.35)];
let nongreedy_zip = v1.into_iter().ordered_zip::<NonGreedyStrategy>(v2);
let dot_product = nongreedy_zip.fold(0.0, |sum, pair| {
    sum + match pair {
        (Some((_, l)), Some((_, r))) => l * r,
        _ => 0.0,
    }
}); // => 0.075

API Reference

Documentation

Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

See also the list of contributors who participated in this project.

License

This project is licensed under the BSD License - see the LICENSE.md file for details.

Dependencies

~230KB