-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[302] Fix build of version 0.20.0 (#303)
* fixup manifest * update changelog * delete unused dep. * add test results * post review fixes * Update CHANGELOG.md
- Loading branch information
Showing
10 changed files
with
838 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
use super::AHasher; | ||
use std::hash::Hasher; | ||
|
||
#[test] | ||
fn test_hash_algorithm_compat() { | ||
test_hash(&(0..10).collect::<Vec<u8>>(), 3604729491498336444); | ||
test_hash(&(245..255).collect::<Vec<u8>>(), 4698010058046694585); | ||
test_hash(&(63..73).collect::<Vec<u8>>(), 7892047681755360091); | ||
test_hash(&(101..111).collect::<Vec<u8>>(), 15822444892006722439); | ||
} | ||
|
||
fn test_hash(data: &[u8], eq_to: u64) { | ||
let mut hasher_7 = AHasher::new_with_keys(1, 2); | ||
hasher_7.write(data); | ||
let hash_7 = hasher_7.finish(); | ||
|
||
assert_eq!(hash_7, eq_to); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,184 @@ | ||
// Original work: Copyright (c) 2018 Tom Kaitchuck | ||
// Distributed under MIT license | ||
// Taken from aHash version 0.7.4 (commit ffa04fcb81f39755f636c75c9b7aa06533c0ae75) | ||
|
||
#![allow(clippy::complexity)] | ||
pub trait Convert<To> { | ||
fn convert(self) -> To; | ||
} | ||
|
||
macro_rules! convert { | ||
($a:ty, $b:ty) => { | ||
impl Convert<$b> for $a { | ||
#[inline(always)] | ||
fn convert(self) -> $b { | ||
unsafe { | ||
let mut result: $b = core::mem::zeroed(); | ||
core::ptr::copy_nonoverlapping( | ||
&self as *const $a as *const u8, | ||
&mut result as *mut $b as *mut u8, | ||
core::mem::size_of::<$b>(), | ||
); | ||
return result; | ||
} | ||
} | ||
} | ||
impl Convert<$a> for $b { | ||
#[inline(always)] | ||
fn convert(self) -> $a { | ||
unsafe { | ||
let mut result: $a = core::mem::zeroed(); | ||
core::ptr::copy_nonoverlapping( | ||
&self as *const $b as *const u8, | ||
&mut result as *mut $a as *mut u8, | ||
core::mem::size_of::<$a>(), | ||
); | ||
return result; | ||
} | ||
} | ||
} | ||
}; | ||
} | ||
|
||
convert!([u128; 4], [u64; 8]); | ||
convert!([u128; 4], [u32; 16]); | ||
convert!([u128; 4], [u16; 32]); | ||
convert!([u128; 4], [u8; 64]); | ||
convert!([u128; 2], [u64; 4]); | ||
convert!([u128; 2], [u32; 8]); | ||
convert!([u128; 2], [u16; 16]); | ||
convert!([u128; 2], [u8; 32]); | ||
convert!(u128, [u64; 2]); | ||
convert!(u128, [u32; 4]); | ||
convert!(u128, [u16; 8]); | ||
convert!(u128, [u8; 16]); | ||
convert!([u64; 8], [u32; 16]); | ||
convert!([u64; 8], [u16; 32]); | ||
convert!([u64; 8], [u8; 64]); | ||
convert!([u64; 4], [u32; 8]); | ||
convert!([u64; 4], [u16; 16]); | ||
convert!([u64; 4], [u8; 32]); | ||
convert!([u64; 2], [u32; 4]); | ||
convert!([u64; 2], [u16; 8]); | ||
convert!([u64; 2], [u8; 16]); | ||
convert!([u32; 4], [u16; 8]); | ||
convert!([u32; 4], [u8; 16]); | ||
convert!([u16; 8], [u8; 16]); | ||
convert!(u64, [u32; 2]); | ||
convert!(u64, [u16; 4]); | ||
convert!(u64, [u8; 8]); | ||
convert!([u32; 2], [u16; 4]); | ||
convert!([u32; 2], [u8; 8]); | ||
convert!(u32, [u16; 2]); | ||
convert!(u32, [u8; 4]); | ||
convert!([u16; 2], [u8; 4]); | ||
convert!(u16, [u8; 2]); | ||
convert!([[u64; 4]; 2], [u8; 64]); | ||
|
||
convert!([f64; 2], [u8; 16]); | ||
convert!([f32; 4], [u8; 16]); | ||
convert!(f64, [u8; 8]); | ||
convert!([f32; 2], [u8; 8]); | ||
convert!(f32, [u8; 4]); | ||
|
||
macro_rules! as_array { | ||
($input:expr, $len:expr) => {{ | ||
{ | ||
#[inline(always)] | ||
fn as_array<T>(slice: &[T]) -> &[T; $len] { | ||
assert_eq!(slice.len(), $len); | ||
unsafe { &*(slice.as_ptr() as *const [_; $len]) } | ||
} | ||
as_array($input) | ||
} | ||
}}; | ||
} | ||
|
||
pub(crate) trait ReadFromSlice { | ||
fn read_u16(&self) -> (u16, &[u8]); | ||
fn read_u32(&self) -> (u32, &[u8]); | ||
fn read_u64(&self) -> (u64, &[u8]); | ||
fn read_u128(&self) -> (u128, &[u8]); | ||
fn read_u128x2(&self) -> ([u128; 2], &[u8]); | ||
fn read_u128x4(&self) -> ([u128; 4], &[u8]); | ||
fn read_last_u16(&self) -> u16; | ||
fn read_last_u32(&self) -> u32; | ||
fn read_last_u64(&self) -> u64; | ||
fn read_last_u128(&self) -> u128; | ||
fn read_last_u128x2(&self) -> [u128; 2]; | ||
fn read_last_u128x4(&self) -> [u128; 4]; | ||
} | ||
|
||
impl ReadFromSlice for [u8] { | ||
#[inline(always)] | ||
fn read_u16(&self) -> (u16, &[u8]) { | ||
let (value, rest) = self.split_at(2); | ||
(as_array!(value, 2).convert(), rest) | ||
} | ||
|
||
#[inline(always)] | ||
fn read_u32(&self) -> (u32, &[u8]) { | ||
let (value, rest) = self.split_at(4); | ||
(as_array!(value, 4).convert(), rest) | ||
} | ||
|
||
#[inline(always)] | ||
fn read_u64(&self) -> (u64, &[u8]) { | ||
let (value, rest) = self.split_at(8); | ||
(as_array!(value, 8).convert(), rest) | ||
} | ||
|
||
#[inline(always)] | ||
fn read_u128(&self) -> (u128, &[u8]) { | ||
let (value, rest) = self.split_at(16); | ||
(as_array!(value, 16).convert(), rest) | ||
} | ||
|
||
#[inline(always)] | ||
fn read_u128x2(&self) -> ([u128; 2], &[u8]) { | ||
let (value, rest) = self.split_at(32); | ||
(as_array!(value, 32).convert(), rest) | ||
} | ||
|
||
#[inline(always)] | ||
fn read_u128x4(&self) -> ([u128; 4], &[u8]) { | ||
let (value, rest) = self.split_at(64); | ||
(as_array!(value, 64).convert(), rest) | ||
} | ||
|
||
#[inline(always)] | ||
fn read_last_u16(&self) -> u16 { | ||
let (_, value) = self.split_at(self.len() - 2); | ||
as_array!(value, 2).convert() | ||
} | ||
|
||
#[inline(always)] | ||
fn read_last_u32(&self) -> u32 { | ||
let (_, value) = self.split_at(self.len() - 4); | ||
as_array!(value, 4).convert() | ||
} | ||
|
||
#[inline(always)] | ||
fn read_last_u64(&self) -> u64 { | ||
let (_, value) = self.split_at(self.len() - 8); | ||
as_array!(value, 8).convert() | ||
} | ||
|
||
#[inline(always)] | ||
fn read_last_u128(&self) -> u128 { | ||
let (_, value) = self.split_at(self.len() - 16); | ||
as_array!(value, 16).convert() | ||
} | ||
|
||
#[inline(always)] | ||
fn read_last_u128x2(&self) -> [u128; 2] { | ||
let (_, value) = self.split_at(self.len() - 32); | ||
as_array!(value, 32).convert() | ||
} | ||
|
||
#[inline(always)] | ||
fn read_last_u128x4(&self) -> [u128; 4] { | ||
let (_, value) = self.split_at(self.len() - 64); | ||
as_array!(value, 64).convert() | ||
} | ||
} |
Oops, something went wrong.