#endianness #hasher

endian-hasher

Endianness wrapper for Hashers

1 unstable release

Uses old Rust 2015

0.1.1 Nov 30, 2016
0.1.0 Nov 30, 2016

#59 in #hasher

MIT/Apache

4KB

This crate provides wrappers for Hasher that change the endianness used when hashing primitive numeric types.

Installation

This crate works with Cargo and is on crates.io. Add it to your Cargo.toml with:

[dependencies]
endianhasher = "0.1"

Use the crate like:

extern crate endian_hasher;

use std::hash::{Hasher, SipHasher24};

use endianhasher::{HasherToLE, HasherToBE};

let mut h1 = HasherToLE(SipHasher24::new_with_keys(k0,k1));
-3i64.hash(&mut h1);
h1.finish()

lib.rs:

These simple wrapper types for Hasher change the endianness used when hashing primitive numeric types.

Examples

use std::collections::hash_map::DefaultHasher;
use std::hash::Hasher;
use endian_hasher::*;

assert_eq!( {
let mut h1 = HasherToLE(DefaultHasher::new());
h1.write_i16(-3);
h1.finish()
}, {
let mut h0 = DefaultHasher::new();
h0.write_i16( i16::to_le(-3) );
h0.finish()
} );

assert_eq!( {
let mut h1 = HasherToBE(DefaultHasher::new());
h1.write_u32(79);
h1.finish()
}, {
let mut h0 = DefaultHasher::new();
h0.write_u32( 79u32.to_be() );
h0.finish()
} );

assert_eq!( {
let mut h1 = HasherSwapBytes(DefaultHasher::new());
h1.write_u64(0x12345678);
h1.finish()
}, {
let mut h0 = DefaultHasher::new();
h0.write_u64( u64::swap_bytes(0x12345678) );
h0.finish()
} );

No runtime deps