Documentation
<!--PROJECT-SCOPE-->

# ordered_zip

[![Build Status](http://img.shields.io/travis/deepthought/ordered_zip.svg?style=flat-square)](https://travis-ci.org/deepthought/ordered_zip)
[![Crates-Downloads](https://img.shields.io/crates/d/ordered_set.svg?style=flat-square)]()
[![Crates-Version](https://img.shields.io/crates/v/ordered_set.svg?style=flat-square)]()
[![Crates-License](https://img.shields.io/crates/l/ordered_set.svg?style=flat-square)]()

### 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`:

```toml
ordered_zip = "0.1.0"
```

… or whatever [other version](./releases) is more up-to-date.

Then add …

```rusr
extern crate ordered_zip;
```

… and …

```rust
use ordered_zip;
```

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

## Example Use

```rust
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](https://deepthought.github.io/ordered_zip)

## Contributing

Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on our [code of conduct](https://www.rust-lang.org/conduct.html), and the process for submitting pull requests to us.

## Versioning

We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/deepthought/ordered_zip/tags).

## Authors

* **Vincent Esche** - *Initial work* - [Regexident]https://github.com/Regexident

See also the list of [contributors](https://github.com/your/project/contributors) who participated in this project.

## License

This project is licensed under the **BSD License** - see the [LICENSE.md](LICENSE.md) file for details.