ordered_zip

Crates.ioordered_zip
lib.rsordered_zip
version0.1.0
sourcesrc
created_at2016-02-06 22:01:25.272489
updated_at2016-02-06 22:01:25.272489
descriptionAn iterator that iterates two other iterators simultaneously, prioritized by pairwise ordering.
homepage
repositoryhttps://github.com/deepthought/ordered_zip
max_upload_size
id4109
size17,876
Vincent Esche (regexident)

documentation

https://deepthought.github.io/ordered_zip

README

ordered_zip

Build Status Downloads Version 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.

Commit count: 0

cargo fmt