Skip to content

Commit

Permalink
isize, usize
Browse files Browse the repository at this point in the history
  • Loading branch information
crepererum committed Aug 20, 2016
1 parent 9e7ec50 commit 97fad15
Show file tree
Hide file tree
Showing 3 changed files with 178 additions and 0 deletions.
69 changes: 69 additions & 0 deletions src/signed_integer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,72 @@ impl_rdxsort!(i8, u8, i8::min_value(), 0i8);
impl_rdxsort!(i16, u16, i16::min_value(), 0i16);
impl_rdxsort!(i32, u32, i32::min_value(), 0i32);
impl_rdxsort!(i64, u64, i64::min_value(), 0i64);

#[cfg(target_pointer_width = "16")]
impl RdxSortTemplate for isize {
#[inline]
fn cfg_nbuckets() -> usize {
<i16 as RdxSortTemplate>::cfg_nbuckets()
}

#[inline]
fn cfg_nrounds() -> usize {
<i16 as RdxSortTemplate>::cfg_nrounds()
}

#[inline]
fn get_bucket(&self, round: usize) -> usize {
(*self as i16).get_bucket(round)
}

#[inline]
fn reverse(round: usize, bucket: usize) -> bool {
<i16 as RdxSortTemplate>::reverse(round, bucket)
}
}

#[cfg(target_pointer_width = "32")]
impl RdxSortTemplate for isize {
#[inline]
fn cfg_nbuckets() -> usize {
<i32 as RdxSortTemplate>::cfg_nbuckets()
}

#[inline]
fn cfg_nrounds() -> usize {
<i32 as RdxSortTemplate>::cfg_nrounds()
}

#[inline]
fn get_bucket(&self, round: usize) -> usize {
(*self as i32).get_bucket(round)
}

#[inline]
fn reverse(round: usize, bucket: usize) -> bool {
<i32 as RdxSortTemplate>::reverse(round, bucket)
}
}

#[cfg(target_pointer_width = "64")]
impl RdxSortTemplate for isize {
#[inline]
fn cfg_nbuckets() -> usize {
<i64 as RdxSortTemplate>::cfg_nbuckets()
}

#[inline]
fn cfg_nrounds() -> usize {
<i64 as RdxSortTemplate>::cfg_nrounds()
}

#[inline]
fn get_bucket(&self, round: usize) -> usize {
(*self as i64).get_bucket(round)
}

#[inline]
fn reverse(round: usize, bucket: usize) -> bool {
<i64 as RdxSortTemplate>::reverse(round, bucket)
}
}
69 changes: 69 additions & 0 deletions src/unsigned_integer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,72 @@ impl RdxSortTemplate for u64 {
false
}
}

#[cfg(target_pointer_width = "16")]
impl RdxSortTemplate for usize {
#[inline]
fn cfg_nbuckets() -> usize {
<u16 as RdxSortTemplate>::cfg_nbuckets()
}

#[inline]
fn cfg_nrounds() -> usize {
<u16 as RdxSortTemplate>::cfg_nrounds()
}

#[inline]
fn get_bucket(&self, round: usize) -> usize {
(*self as u16).get_bucket(round)
}

#[inline]
fn reverse(round: usize, bucket: usize) -> bool {
<u16 as RdxSortTemplate>::reverse(round, bucket)
}
}

#[cfg(target_pointer_width = "32")]
impl RdxSortTemplate for usize {
#[inline]
fn cfg_nbuckets() -> usize {
<u32 as RdxSortTemplate>::cfg_nbuckets()
}

#[inline]
fn cfg_nrounds() -> usize {
<u32 as RdxSortTemplate>::cfg_nrounds()
}

#[inline]
fn get_bucket(&self, round: usize) -> usize {
(*self as u32).get_bucket(round)
}

#[inline]
fn reverse(round: usize, bucket: usize) -> bool {
<u32 as RdxSortTemplate>::reverse(round, bucket)
}
}

#[cfg(target_pointer_width = "64")]
impl RdxSortTemplate for usize {
#[inline]
fn cfg_nbuckets() -> usize {
<u64 as RdxSortTemplate>::cfg_nbuckets()
}

#[inline]
fn cfg_nrounds() -> usize {
<u64 as RdxSortTemplate>::cfg_nrounds()
}

#[inline]
fn get_bucket(&self, round: usize) -> usize {
(*self as u64).get_bucket(round)
}

#[inline]
fn reverse(round: usize, bucket: usize) -> bool {
<u64 as RdxSortTemplate>::reverse(round, bucket)
}
}
40 changes: 40 additions & 0 deletions tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,12 @@ trivial_myhash!(i8);
trivial_myhash!(i16);
trivial_myhash!(i32);
trivial_myhash!(i64);
trivial_myhash!(isize);
trivial_myhash!(u8);
trivial_myhash!(u16);
trivial_myhash!(u32);
trivial_myhash!(u64);
trivial_myhash!(usize);

impl MyHash for f32 {
fn hash_it<H>(&self, state: &mut H) where H: Hasher {
Expand Down Expand Up @@ -319,6 +321,25 @@ mod sub_i64 {
}
}

mod sub_isize {
use super::*;

#[test]
fn test_rnd_isize() {
test_rnd_generic::<isize>(vec![isize::min_value(), isize::min_value() + 1, -1, 0, 1, isize::max_value() - 1, isize::max_value()]);
}

#[test]
fn test_empty_isize() {
test_empty_generic::<isize>();
}

#[test]
fn test_single_isize() {
test_single_generic::<isize>(3);
}
}

mod sub_u8 {
use super::*;

Expand Down Expand Up @@ -405,6 +426,25 @@ mod sub_u64 {
}
}

mod sub_usize {
use super::*;

#[test]
fn test_rnd_usize() {
test_rnd_generic::<usize>(vec![0, 1, usize::max_value() - 1, usize::max_value()]);
}

#[test]
fn test_empty_usize() {
test_empty_generic::<usize>();
}

#[test]
fn test_single_usize() {
test_single_generic::<usize>(3);
}
}

mod sub_f32 {
use super::*;

Expand Down

0 comments on commit 97fad15

Please sign in to comment.