Skip to content

Commit b6b06ac

Browse files
authored
Merge pull request #9 from alecmocatta/serialize-zeroable
Make Zeroable (de)serializable
2 parents ab21366 + d23de5b commit b6b06ac

File tree

7 files changed

+33
-43
lines changed

7 files changed

+33
-43
lines changed

Cargo.toml

Lines changed: 3 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.1"
3+
version = "0.1.2"
44
license = "MIT OR Apache-2.0"
55
authors = ["Alec Mocatta <alec@mocatta.net>"]
66
categories = ["data-structures","algorithms","science"]
@@ -10,12 +10,12 @@ 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.1"
13+
documentation = "https://docs.rs/streaming_algorithms/0.1.2"
1414
readme = "README.md"
1515
edition = "2018"
1616

1717
[badges]
18-
azure-devops = { project = "alecmocatta/streaming_algorithms", pipeline = "tests" }
18+
azure-devops = { project = "alecmocatta/streaming_algorithms", pipeline = "tests", build = "16" }
1919
maintenance = { status = "actively-developed" }
2020

2121
[dependencies]

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
[![Crates.io](https://img.shields.io/crates/v/streaming_algorithms.svg?maxAge=86400)](https://crates.io/crates/streaming_algorithms)
44
[![MIT / Apache 2.0 licensed](https://img.shields.io/crates/l/streaming_algorithms.svg?maxAge=2592000)](#License)
5-
[![Build Status](https://dev.azure.com/alecmocatta/streaming_algorithms/_apis/build/status/tests?branchName=master)](https://dev.azure.com/alecmocatta/streaming_algorithms/_build/latest?branchName=master)
5+
[![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.1)
7+
[📖 Docs](https://docs.rs/streaming_algorithms/0.1.2) | [💬 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: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,19 @@ jobs:
1414
endpoint: alecmocatta
1515
default:
1616
rust_toolchain: nightly
17-
rust_lint_toolchain: nightly-2019-07-19
17+
rust_lint_toolchain: nightly-2020-06-09
1818
rust_flags: ''
1919
rust_features: ''
2020
rust_target_check: ''
2121
rust_target_build: ''
2222
rust_target_run: ''
2323
matrix:
2424
windows:
25-
imageName: 'vs2017-win2016'
26-
rust_target_run: 'x86_64-pc-windows-msvc i686-pc-windows-msvc' # currently broken building crate-type=lib: x86_64-pc-windows-gnu i686-pc-windows-gnu
25+
imageName: 'windows-latest'
26+
rust_target_run: 'x86_64-pc-windows-msvc i686-pc-windows-msvc x86_64-pc-windows-gnu'
2727
mac:
28-
imageName: 'macos-10.13'
29-
rust_target_run: 'x86_64-apple-darwin i686-apple-darwin'
28+
imageName: 'macos-latest'
29+
rust_target_run: 'x86_64-apple-darwin'
3030
linux:
31-
imageName: 'ubuntu-16.04'
31+
imageName: 'ubuntu-latest'
3232
rust_target_run: 'x86_64-unknown-linux-gnu i686-unknown-linux-gnu x86_64-unknown-linux-musl i686-unknown-linux-musl'

src/distinct.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ use std::{
5454
use twox_hash::XxHash;
5555

5656
mod consts;
57-
use self::consts::*;
57+
use self::consts::{BIAS_DATA, RAW_ESTIMATE_DATA, TRESHOLD_DATA};
5858

5959
/// Like [`HyperLogLog`] but implements `Ord` and `Eq` by using the estimate of the cardinality.
6060
#[derive(Serialize, Deserialize)]
@@ -429,7 +429,7 @@ impl<V: ?Sized> IntersectPlusUnionIsPlus for HyperLogLog<V> {
429429

430430
#[cfg(target_feature = "avx512bw")] // TODO
431431
mod simd_types {
432-
use super::*;
432+
use super::packed_simd;
433433
pub type u8s = packed_simd::u8x64;
434434
pub type u8s_sad_out = packed_simd::u64x8;
435435
pub type f32s = packed_simd::f32x16;
@@ -439,7 +439,7 @@ mod simd_types {
439439
#[cfg(target_feature = "avx2")]
440440
mod simd_types {
441441
#![allow(non_camel_case_types)]
442-
use super::*;
442+
use super::packed_simd;
443443
pub type u8s = packed_simd::u8x32;
444444
pub type u8s_sad_out = packed_simd::u64x4;
445445
pub type f32s = packed_simd::f32x8;
@@ -449,7 +449,7 @@ mod simd_types {
449449
#[cfg(all(not(target_feature = "avx2"), target_feature = "sse2"))]
450450
mod simd_types {
451451
#![allow(non_camel_case_types)]
452-
use super::*;
452+
use super::packed_simd;
453453
pub type u8s = packed_simd::u8x16;
454454
pub type u8s_sad_out = packed_simd::u64x2;
455455
pub type f32s = packed_simd::f32x4;
@@ -459,14 +459,14 @@ mod simd_types {
459459
#[cfg(all(not(target_feature = "avx2"), not(target_feature = "sse2")))]
460460
mod simd_types {
461461
#![allow(non_camel_case_types)]
462-
use super::*;
462+
use super::packed_simd;
463463
pub type u8s = packed_simd::u8x8;
464464
pub type u8s_sad_out = u64;
465465
pub type f32s = packed_simd::f32x2;
466466
pub type u32s = packed_simd::u32x2;
467467
pub type u8sq = packed_simd::u8x2;
468468
}
469-
use self::simd_types::*;
469+
use self::simd_types::{f32s, u32s, u8s, u8s_sad_out, u8sq};
470470

471471
struct Sad<X>(PhantomData<fn(X)>);
472472
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]

src/lib.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
//! SIMD-accelerated implementations of various [streaming algorithms](https://en.wikipedia.org/wiki/Streaming_algorithm).
22
//!
3-
//! **[Crates.io](https://crates.io/crates/streaming_algorithms) │ [Repo](https://github.com/alecmocatta/streaming_algorithms)**
3+
//! <p style="font-family: 'Fira Sans',sans-serif;padding:0.3em 0"><strong>
4+
//! <a href="https://crates.io/crates/streaming_algorithms">📦&nbsp;&nbsp;Crates.io</a>&nbsp;&nbsp;│&nbsp;&nbsp;<a href="https://github.com/alecmocatta/streaming_algorithms">📑&nbsp;&nbsp;GitHub</a>&nbsp;&nbsp;│&nbsp;&nbsp;<a href="https://constellation.zulipchat.com/#narrow/stream/213236-subprojects">💬&nbsp;&nbsp;Chat</a>
5+
//! </strong></p>
46
//!
57
//! This library is a work in progress. PRs are very welcome! Currently implemented algorithms include:
68
//!
@@ -21,8 +23,8 @@
2123
//!
2224
//! 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.
2325
24-
#![doc(html_root_url = "https://docs.rs/streaming_algorithms/0.1.1")]
25-
#![feature(specialization, try_trait)]
26+
#![doc(html_root_url = "https://docs.rs/streaming_algorithms/0.1.2")]
27+
#![feature(specialization)]
2628
#![warn(
2729
missing_copy_implementations,
2830
missing_debug_implementations,
@@ -44,7 +46,10 @@
4446
clippy::op_ref,
4547
clippy::needless_pass_by_value,
4648
clippy::suspicious_op_assign_impl,
47-
clippy::float_cmp
49+
clippy::float_cmp,
50+
clippy::unsafe_derive_deserialize,
51+
clippy::must_use_candidate,
52+
clippy::unused_self
4853
)]
4954

5055
mod count_min;

src/sample.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,6 @@ impl<T> ops::AddAssign for SampleUnstable<T> {
220220
#[cfg(test)]
221221
mod test {
222222
use super::*;
223-
use rand;
224223
use std::collections::HashMap;
225224

226225
#[test]

src/top.rs

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,14 @@ impl<'a, A: Hash + Eq + Clone + Debug, C: Ord + Debug + 'a> Debug for TopIter<'a
153153
}
154154

155155
/// 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, Debug)]
156+
#[derive(Copy, Clone, Serialize, Deserialize, Debug)]
157157
pub enum Zeroable<T> {
158158
/// Zero
159159
Zero,
160160
/// Nonzero
161161
Nonzero(T),
162162
}
163+
#[allow(clippy::missing_errors_doc)]
163164
impl<T> Zeroable<T> {
164165
/// Transform to a `Result<T, E>`.
165166
pub fn ok_or<E>(self, err: E) -> Result<T, E> {
@@ -184,25 +185,6 @@ impl<T> From<Option<T>> for Zeroable<T> {
184185
}
185186
}
186187
}
187-
impl<T> std::ops::Try for Zeroable<T> {
188-
type Ok = T;
189-
type Error = std::option::NoneError;
190-
191-
#[inline]
192-
fn into_result(self) -> Result<T, std::option::NoneError> {
193-
self.ok_or(std::option::NoneError)
194-
}
195-
196-
#[inline]
197-
fn from_ok(v: T) -> Self {
198-
Zeroable::Nonzero(v)
199-
}
200-
201-
#[inline]
202-
fn from_error(_: std::option::NoneError) -> Self {
203-
Zeroable::Zero
204-
}
205-
}
206188
impl<T> iter::Sum for Zeroable<T>
207189
where
208190
Self: iter::Sum<T>,
@@ -231,7 +213,11 @@ impl<
231213
where
232214
I: Iterator<Item = Top<A, C>>,
233215
{
234-
let mut total = iter.next()?;
216+
let mut total = if let Some(total) = iter.next() {
217+
total
218+
} else {
219+
return Zeroable::Zero;
220+
};
235221
for sample in iter {
236222
total += sample;
237223
}

0 commit comments

Comments
 (0)