Skip to content

Commit 9ff30c6

Browse files
Add SIMD-vs-no-SIMD regression test.
1 parent b58e329 commit 9ff30c6

File tree

4 files changed

+70
-0
lines changed

4 files changed

+70
-0
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ jobs:
6565
run: cargo test --verbose --target ${{ matrix.arch }}-${{ fromJSON(env.target_map)[matrix.os] }} --features=no_simd
6666
- name: Build docs
6767
run: cargo doc --verbose
68+
- name: Run SIMD/no-SIMD tests
69+
run: |
70+
cd crosstest
71+
cargo run
6872
6973
benchmarks:
7074
strategy:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/target
2+
/crosstest/target
23
Cargo.lock

crosstest/Cargo.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[package]
2+
name = "crosstest"
3+
version = "0.1.0"
4+
edition = "2018"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]
9+
odht_with_simd = { package = "odht", version = "0.2.1" }
10+
odht_no_simd = { package = "odht", path = "..", features = ["no_simd"] }

crosstest/src/main.rs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
2+
3+
struct FxConfig;
4+
5+
macro_rules! impl_config {
6+
($odht_version:ident) => {
7+
impl $odht_version::Config for FxConfig {
8+
type Key = u64;
9+
type Value = u32;
10+
11+
type EncodedKey = [u8; 8];
12+
type EncodedValue = [u8; 4];
13+
14+
type H = $odht_version::FxHashFn;
15+
16+
#[inline]
17+
fn encode_key(k: &Self::Key) -> Self::EncodedKey {
18+
k.to_le_bytes()
19+
}
20+
21+
#[inline]
22+
fn encode_value(v: &Self::Value) -> Self::EncodedValue {
23+
v.to_le_bytes()
24+
}
25+
26+
#[inline]
27+
fn decode_key(k: &Self::EncodedKey) -> Self::Key {
28+
u64::from_le_bytes(*k)
29+
}
30+
31+
#[inline]
32+
fn decode_value(v: &Self::EncodedValue) -> Self::Value {
33+
u32::from_le_bytes(*v)
34+
}
35+
}
36+
}
37+
}
38+
39+
impl_config!(odht_no_simd);
40+
impl_config!(odht_with_simd);
41+
42+
fn main() -> Result<(), Box<dyn std::error::Error>> {
43+
44+
let entries: Vec<(u64, u32)> = (0 .. 1_000_000_u64).map(|x| (x * x, x as u32)).collect();
45+
46+
let with_simd_table = odht_with_simd::HashTableOwned::<FxConfig>::from_iterator(entries.clone(), 85);
47+
48+
let no_simd_table = odht_no_simd::HashTable::<FxConfig, _>::from_raw_bytes(with_simd_table.raw_bytes())?;
49+
50+
for (key, value) in entries {
51+
assert_eq!(no_simd_table.get(&key), Some(value));
52+
}
53+
54+
Ok(())
55+
}

0 commit comments

Comments
 (0)