Uses old Rust 2015

0.1.0 Feb 6, 2016

#6 in #pairwise

Download history 75/week @ 2024-08-25 105/week @ 2024-09-01 27/week @ 2024-09-08 5/week @ 2024-09-15 151/week @ 2024-09-22 15/week @ 2024-09-29 8/week @ 2024-10-06 1/week @ 2024-10-13 15/week @ 2024-10-20 81/week @ 2024-10-27 3/week @ 2024-11-03

155 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

~0–255KB