diff --git a/Cargo.toml b/Cargo.toml index 3cd1f20..0da96c3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "space-time" -version = "0.2.0" +version = "0.3.0" authors = ["Boyd Johnson "] description = "A nightly only library of space-time filling curves that supports no-std." license-file = "LICENSE.txt" @@ -11,9 +11,9 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -num-integer = { version = "^0.1", default-features = false } -num-traits = { version = "^0.2", default-features = false, features = ["libm"] } +num-integer = { version = "0.1", default-features = false } +num-traits = { version = "0.2", default-features = false, features = ["libm"] } [dev-dependencies] -quickcheck = "^0.9" -quickcheck_macros = "^0.9" +quickcheck = "1.0" +quickcheck_macros = "1.0" diff --git a/src/index_range.rs b/src/index_range.rs index 9f062fb..7f94514 100644 --- a/src/index_range.rs +++ b/src/index_range.rs @@ -32,8 +32,8 @@ pub trait IndexRange: core::fmt::Debug { /// Returns all three (lower, upper, contained) as a tuple. fn tuple(&self) -> (u64, u64, bool) { ( - ::lower(&self), - ::upper(&self), + ::lower(self), + ::upper(self), self.contained(), ) } @@ -67,7 +67,7 @@ impl PartialEq for dyn IndexRange { impl Eq for dyn IndexRange {} -/// +/// A covered range. #[derive(Debug, PartialEq, Eq)] pub struct CoveredRange { upper: u64, diff --git a/src/xzorder/xz2_sfc.rs b/src/xzorder/xz2_sfc.rs index 8859cf5..b0f0689 100644 --- a/src/xzorder/xz2_sfc.rs +++ b/src/xzorder/xz2_sfc.rs @@ -207,17 +207,17 @@ impl XZ2SFC { ymax = y_center; } (false, true) => { - cs += 1 + div_floor(4_u64.pow(self.g as u32 - i) - 1_u64, 3); + cs += 1 + div_floor(4_u64.pow(self.g - i) - 1_u64, 3); xmin = x_center; ymax = y_center; } (true, false) => { - cs += 1 + div_floor(2 * (4_u64.pow(self.g as u32 - i) - 1_u64), 3); + cs += 1 + div_floor(2 * (4_u64.pow(self.g - i) - 1_u64), 3); xmax = x_center; ymin = y_center; } (false, false) => { - cs += 1 + div_floor(3 * 4_u64.pow(self.g as u32 - i) - 1_u64, 3); + cs += 1 + div_floor(3 * 4_u64.pow(self.g - i) - 1_u64, 3); xmin = x_center; ymin = y_center; } diff --git a/src/zorder/z_2.rs b/src/zorder/z_2.rs index 1db6772..c1b8629 100644 --- a/src/zorder/z_2.rs +++ b/src/zorder/z_2.rs @@ -139,7 +139,11 @@ mod tests { #[quickcheck] fn test_split_and_combine(x: u32) -> bool { - Z2::combine(Z2::split(x)) == x + if x > Z2::MAX_MASK as u32 { + true + } else { + Z2::combine(Z2::split(x)) == x + } } #[test] @@ -177,8 +181,8 @@ mod tests { #[test] fn test_longest_common_prefix() { assert_eq!( - Z2::longest_common_prefix(&[u64::max_value(), u64::max_value() - 15]).prefix, - u64::max_value() - 15 + Z2::longest_common_prefix(&[u64::MAX, u64::MAX - 15]).prefix, + u64::MAX - 15 ); assert_eq!(Z2::longest_common_prefix(&[15, 13]).prefix, 12); // 1111, 1101 => 1100 => 12 assert_eq!(Z2::longest_common_prefix(&[12, 15]).prefix, 12); // 1100, 1111 => 1100 diff --git a/src/zorder/z_3.rs b/src/zorder/z_3.rs index 73222fc..4f484a2 100644 --- a/src/zorder/z_3.rs +++ b/src/zorder/z_3.rs @@ -250,14 +250,17 @@ impl ZCurve3D { let depth_max: u32 = self.time_to_depth(t_max); let max = Z3::new(col_max, row_max, depth_max); - let max_recurse = hints.iter().find_map(|h| { - let RangeComputeHints::MaxRecurse(max) = *h; - if max > MAX_RECURSION { - Some(MAX_RECURSION) - } else { - Some(max) - } - }); + let max_recurse = hints + .iter() + .map(|h| { + let RangeComputeHints::MaxRecurse(max) = *h; + if max > MAX_RECURSION { + MAX_RECURSION + } else { + max + } + }) + .next(); ::zranges::( &[ZRange { @@ -289,12 +292,12 @@ mod tests { assert_eq!(Z3::new(23, 13, 200).decode(), (23, 13, 200)); // only 21 bits are saved, so MAX Value gets chopped assert_eq!( - Z3::new(u16::max_value() as u32, 0, 0).decode(), - (u16::max_value() as u32, 0, 0) + Z3::new(u16::MAX as u32, 0, 0).decode(), + (u16::MAX as u32, 0, 0) ); assert_eq!( - Z3::new(u16::max_value() as u32, 0, u16::max_value() as u32).decode(), - (u16::max_value() as u32, 0, u16::max_value() as u32) + Z3::new(u16::MAX as u32, 0, u16::MAX as u32).decode(), + (u16::MAX as u32, 0, u16::MAX as u32) ); } diff --git a/src/zorder/z_curve_2d.rs b/src/zorder/z_curve_2d.rs index 0c718e2..b3e00a4 100644 --- a/src/zorder/z_curve_2d.rs +++ b/src/zorder/z_curve_2d.rs @@ -120,14 +120,17 @@ impl ZCurve2D { let row_max = self.map_to_row(y_min); let max = Z2::new(col_max, row_max); - let max_recurse = hints.iter().find_map(|h| { - let RangeComputeHints::MaxRecurse(max) = *h; - if max > Self::MAX_RECURSION { - Some(Self::MAX_RECURSION) - } else { - Some(max) - } - }); + let max_recurse = hints + .iter() + .map(|h| { + let RangeComputeHints::MaxRecurse(max) = *h; + if max > Self::MAX_RECURSION { + Self::MAX_RECURSION + } else { + max + } + }) + .next(); Z2::zranges::( &[ZRange { diff --git a/src/zorder/z_n.rs b/src/zorder/z_n.rs index 8945548..e91b8e4 100644 --- a/src/zorder/z_n.rs +++ b/src/zorder/z_n.rs @@ -67,10 +67,10 @@ pub trait ZN { fn overlaps(range: ZRange, value: ZRange) -> bool; /// Compute the Z-index ranges that cover zbounds (Default values: precision = 64, - /// `max_recurse` = 7, `max_ranges` = `usize::max_value()`). + /// `max_recurse` = 7, `max_ranges` = `usize::MAX`). #[must_use] fn zranges_default(zbounds: &[ZRange]) -> Vec> { - Self::zranges::(zbounds, 64, Some(usize::max_value()), Some(DEFAULT_RECURSE)) + Self::zranges::(zbounds, 64, Some(usize::MAX), Some(DEFAULT_RECURSE)) } /// Compute the Z-index ranges that cover zbounds. @@ -110,7 +110,7 @@ pub trait ZN { let mut level = 0; let max_recurse = max_recurse.unwrap_or(DEFAULT_RECURSE); - let max_ranges = max_ranges.unwrap_or(usize::max_value()); + let max_ranges = max_ranges.unwrap_or(usize::MAX); loop { let next = remaining.pop_front(); @@ -209,7 +209,7 @@ pub trait ZN { bit_shift += Self::DIMENSIONS; ZPrefix { - prefix: values[0] & (u64::max_value().wrapping_shl(bit_shift as u32)), + prefix: values[0] & (u64::MAX.wrapping_shl(bit_shift as u32)), precision: 64 - bit_shift, } }