Skip to content

Commit f8038f5

Browse files
authored
Merge pull request #10 from alecmocatta/nix-zeroable
Replace the Zeroable struct with Option
2 parents b6b06ac + fbcb908 commit f8038f5

File tree

5 files changed

+9
-66
lines changed

5 files changed

+9
-66
lines changed

Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "streaming_algorithms"
3-
version = "0.1.2"
3+
version = "0.2.0"
44
license = "MIT OR Apache-2.0"
55
authors = ["Alec Mocatta <alec@mocatta.net>"]
66
categories = ["data-structures","algorithms","science"]
@@ -10,7 +10,7 @@ SIMD-accelerated implementations of various streaming algorithms, including Coun
1010
"""
1111
repository = "https://github.com/alecmocatta/streaming_algorithms"
1212
homepage = "https://github.com/alecmocatta/streaming_algorithms"
13-
documentation = "https://docs.rs/streaming_algorithms/0.1.2"
13+
documentation = "https://docs.rs/streaming_algorithms/0.2.0"
1414
readme = "README.md"
1515
edition = "2018"
1616

@@ -20,7 +20,6 @@ maintenance = { status = "actively-developed" }
2020

2121
[dependencies]
2222
twox-hash = "1.1"
23-
serde_derive = "1.0"
2423
serde = { version = "1.0", features = ["derive"] }
2524
rand = { version = "0.7", features = ["small_rng"] }
2625
packed_simd = { version = "0.3", features = ["into_bits"] }

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
[![MIT / Apache 2.0 licensed](https://img.shields.io/crates/l/streaming_algorithms.svg?maxAge=2592000)](#License)
55
[![Build Status](https://dev.azure.com/alecmocatta/streaming_algorithms/_apis/build/status/tests?branchName=master)](https://dev.azure.com/alecmocatta/streaming_algorithms/_build?definitionId=16)
66

7-
[📖 Docs](https://docs.rs/streaming_algorithms/0.1.2) | [💬 Chat](https://constellation.zulipchat.com/#narrow/stream/213236-subprojects)
7+
[📖 Docs](https://docs.rs/streaming_algorithms/0.2.0/streaming_algorithms/) | [💬 Chat](https://constellation.zulipchat.com/#narrow/stream/213236-subprojects)
88

99
SIMD-accelerated implementations of various [streaming algorithms](https://en.wikipedia.org/wiki/Streaming_algorithm).
1010

azure-pipelines.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ jobs:
1313
parameters:
1414
endpoint: alecmocatta
1515
default:
16-
rust_toolchain: nightly
17-
rust_lint_toolchain: nightly-2020-06-09
16+
rust_toolchain: nightly-2020-06-10
17+
rust_lint_toolchain: nightly-2020-06-10
1818
rust_flags: ''
1919
rust_features: ''
2020
rust_target_check: ''

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
//!
2424
//! As these implementations are often in hot code paths, unsafe is used, albeit only when necessary to a) achieve the asymptotically optimal algorithm or b) mitigate an observed bottleneck.
2525
26-
#![doc(html_root_url = "https://docs.rs/streaming_algorithms/0.1.2")]
26+
#![doc(html_root_url = "https://docs.rs/streaming_algorithms/0.2.0")]
2727
#![feature(specialization)]
2828
#![warn(
2929
missing_copy_implementations,

src/top.rs

Lines changed: 3 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -152,76 +152,20 @@ impl<'a, A: Hash + Eq + Clone + Debug, C: Ord + Debug + 'a> Debug for TopIter<'a
152152
}
153153
}
154154

155-
/// For the result of a `std::iter::sum()` when an additive identity (i.e. zero) can't be constructed (in the case where we're summing an empty iterator).
156-
#[derive(Copy, Clone, Serialize, Deserialize, Debug)]
157-
pub enum Zeroable<T> {
158-
/// Zero
159-
Zero,
160-
/// Nonzero
161-
Nonzero(T),
162-
}
163-
#[allow(clippy::missing_errors_doc)]
164-
impl<T> Zeroable<T> {
165-
/// Transform to a `Result<T, E>`.
166-
pub fn ok_or<E>(self, err: E) -> Result<T, E> {
167-
match self {
168-
Zeroable::Nonzero(v) => Ok(v),
169-
Zeroable::Zero => Err(err),
170-
}
171-
}
172-
/// Converts to an `Option<T>`.
173-
pub fn nonzero(self) -> Option<T> {
174-
match self {
175-
Zeroable::Nonzero(v) => Some(v),
176-
Zeroable::Zero => None,
177-
}
178-
}
179-
}
180-
impl<T> From<Option<T>> for Zeroable<T> {
181-
fn from(a: Option<T>) -> Self {
182-
match a {
183-
Some(a) => Zeroable::Nonzero(a),
184-
None => Zeroable::Zero,
185-
}
186-
}
187-
}
188-
impl<T> iter::Sum for Zeroable<T>
189-
where
190-
Self: iter::Sum<T>,
191-
{
192-
fn sum<I>(iter: I) -> Self
193-
where
194-
I: Iterator<Item = Self>,
195-
{
196-
iter.filter_map(|item| {
197-
if let Zeroable::Nonzero(item) = item {
198-
Some(item)
199-
} else {
200-
None
201-
}
202-
})
203-
.sum()
204-
}
205-
}
206-
207155
impl<
208156
A: Hash + Eq + Clone,
209157
C: Ord + New + Clone + for<'a> ops::AddAssign<&'a C> + for<'a> UnionAssign<&'a C> + Intersect,
210-
> iter::Sum<Top<A, C>> for Zeroable<Top<A, C>>
158+
> iter::Sum<Top<A, C>> for Option<Top<A, C>>
211159
{
212160
fn sum<I>(mut iter: I) -> Self
213161
where
214162
I: Iterator<Item = Top<A, C>>,
215163
{
216-
let mut total = if let Some(total) = iter.next() {
217-
total
218-
} else {
219-
return Zeroable::Zero;
220-
};
164+
let mut total = iter.next()?;
221165
for sample in iter {
222166
total += sample;
223167
}
224-
Zeroable::Nonzero(total)
168+
Some(total)
225169
}
226170
}
227171
impl<

0 commit comments

Comments
 (0)