Skip to content

Commit ca68834

Browse files
Urgaumichaelwoerister
authored andcommitted
Switch to an array representation [u64; 2] instead of a tuple
1 parent 1c9f942 commit ca68834

File tree

4 files changed

+13
-12
lines changed

4 files changed

+13
-12
lines changed

src/sip128.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ impl SipHasher128 {
378378
}
379379

380380
#[inline]
381-
pub fn finish128(mut self) -> (u64, u64) {
381+
pub fn finish128(mut self) -> [u64; 2] {
382382
debug_assert!(self.nbuf < BUFFER_SIZE);
383383

384384
// Process full elements in buffer.
@@ -426,7 +426,7 @@ impl SipHasher128 {
426426
Sip13Rounds::d_rounds(&mut state);
427427
let _1 = state.v0 ^ state.v1 ^ state.v2 ^ state.v3;
428428

429-
(_0, _1)
429+
[_0, _1]
430430
}
431431
}
432432

src/sip128/tests.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@ impl<'a> Hash for Bytes<'a> {
1414
}
1515
}
1616

17-
fn hash_with<T: Hash>(mut st: SipHasher128, x: &T) -> (u64, u64) {
17+
fn hash_with<T: Hash>(mut st: SipHasher128, x: &T) -> [u64; 2] {
1818
x.hash(&mut st);
1919
st.finish128()
2020
}
2121

22-
fn hash<T: Hash>(x: &T) -> (u64, u64) {
22+
fn hash<T: Hash>(x: &T) -> [u64; 2] {
2323
hash_with(SipHasher128::new_with_keys(0, 0), x)
2424
}
25+
2526
#[rustfmt::skip]
2627
const TEST_VECTOR: [[u8; 16]; 64] = [
2728
[0xe7, 0x7e, 0xbc, 0xb2, 0x27, 0x88, 0xa5, 0xbe, 0xfd, 0x62, 0xdb, 0x6a, 0xdd, 0x30, 0x30, 0x01],
@@ -99,7 +100,7 @@ fn test_siphash_1_3_test_vector() {
99100

100101
for i in 0..64 {
101102
let out = hash_with(SipHasher128::new_with_keys(k0, k1), &Bytes(&input[..]));
102-
let expected = (
103+
let expected = [
103104
((TEST_VECTOR[i][0] as u64) << 0)
104105
| ((TEST_VECTOR[i][1] as u64) << 8)
105106
| ((TEST_VECTOR[i][2] as u64) << 16)
@@ -116,7 +117,7 @@ fn test_siphash_1_3_test_vector() {
116117
| ((TEST_VECTOR[i][13] as u64) << 40)
117118
| ((TEST_VECTOR[i][14] as u64) << 48)
118119
| ((TEST_VECTOR[i][15] as u64) << 56),
119-
);
120+
];
120121

121122
assert_eq!(out, expected);
122123
input.push(i as u8);

src/stable_hasher.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ mod tests;
1010

1111
/// Trait for retrieving the result of the stable hashing operation.
1212
pub trait StableHasherResult: Sized {
13-
fn finish(hash: (u64, u64)) -> Self;
13+
fn finish(hash: [u64; 2]) -> Self;
1414
}
1515

1616
/// When hashing something that ends up affecting properties like symbol names,

src/stable_hasher/tests.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ use super::*;
1010
// need to be updated whenever StableHasher changes its hashing algorithm.
1111

1212
#[derive(Debug, PartialEq)]
13-
struct TestHash((u64, u64));
13+
struct TestHash([u64; 2]);
1414

1515
impl StableHasherResult for TestHash {
16-
fn finish(hash: (u64, u64)) -> TestHash {
16+
fn finish(hash: [u64; 2]) -> TestHash {
1717
TestHash(hash)
1818
}
1919
}
@@ -50,7 +50,7 @@ fn test_hash_integers() {
5050
test_isize.hash(&mut h);
5151

5252
// This depends on the hashing algorithm. See note at top of file.
53-
let expected = TestHash((13997337031081104755, 6178945012502239489));
53+
let expected = TestHash([13997337031081104755, 6178945012502239489]);
5454

5555
assert_eq!(expected, h.finish());
5656
}
@@ -64,7 +64,7 @@ fn test_hash_usize() {
6464
test_usize.hash(&mut h);
6565

6666
// This depends on the hashing algorithm. See note at top of file.
67-
let expected = TestHash((12037165114281468837, 3094087741167521712));
67+
let expected = TestHash([12037165114281468837, 3094087741167521712]);
6868

6969
assert_eq!(expected, h.finish());
7070
}
@@ -78,7 +78,7 @@ fn test_hash_isize() {
7878
test_isize.hash(&mut h);
7979

8080
// This depends on the hashing algorithm. See note at top of file.
81-
let expected = TestHash((3979067582695659080, 2322428596355037273));
81+
let expected = TestHash([3979067582695659080, 2322428596355037273]);
8282

8383
assert_eq!(expected, h.finish());
8484
}

0 commit comments

Comments
 (0)