Skip to content

Commit

Permalink
32bit compatible
Browse files Browse the repository at this point in the history
  • Loading branch information
JieningYu committed Jan 2, 2024
1 parent 46f98f6 commit 1aeb3f3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ impl DimMapping {
/// # Panics
///
/// Panics if the given `range` is not divisible by `elements_per_chunk`.
pub fn new(range_bounds: impl RangeBounds<u64>, elements_per_chunk: usize) -> Self {
pub fn new(range_bounds: impl RangeBounds<u64>, elements_per_chunk: u64) -> Self {
let range: RangeInclusive<u64> = Wrapper(range_bounds).into();
let diff = (*range.end() - *range.start()) as u128 + 1;
let spacing = elements_per_chunk as u128;
Expand Down
22 changes: 13 additions & 9 deletions src/world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,17 +268,17 @@ pub struct World<T, const DIMS: usize, Io: IoHandle> {

/// Describes information of a single dimension.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Dim<R> {
pub struct Dim<R, C = usize> {
/// Range of values in this dimension.
pub range: R,

/// Count of items per chunk in this dimension.
pub items_per_chunk: usize,
pub items_per_chunk: C,
}

impl Dim<RangeInclusive<u64>> {
impl<C> Dim<RangeInclusive<u64>, C> {
#[inline]
pub fn new<R>(items_per_chunk: usize, range: R) -> Self
pub fn new<R>(items_per_chunk: C, range: R) -> Self
where
R: RangeBounds<u64>,
{
Expand Down Expand Up @@ -430,11 +430,15 @@ impl<T: Data, const DIMS: usize, Io: IoHandle> World<T, DIMS, Io> {
///
/// # Panics
///
/// Panics when count of given dimensions and the
/// - Panics when count of given dimensions and the
/// dimension count of data are different.
pub fn new<R>(dims: [Dim<R>; DIMS], io_handle: Io) -> Self
/// - Panics when the given `items per chunk` values could
/// not be converted into `u64` successfully.
pub fn new<R, C>(dims: [Dim<R, C>; DIMS], io_handle: Io) -> Self
where
R: std::ops::RangeBounds<u64>,
u64: TryFrom<C>,
<u64 as TryFrom<C>>::Error: std::error::Error,
{
assert_eq!(
T::DIMS,
Expand All @@ -446,9 +450,9 @@ impl<T: Data, const DIMS: usize, Io: IoHandle> World<T, DIMS, Io> {
Self {
chunks_buf: DashMap::new(),
chunks_limit: 24,
mappings: Arc::new(
dims.map(|value| DimMapping::new(value.range, value.items_per_chunk)),
),
mappings: Arc::new(dims.map(|value| {
DimMapping::new(value.range, u64::try_from(value.items_per_chunk).unwrap())
})),
io_handle,
}
}
Expand Down

0 comments on commit 1aeb3f3

Please sign in to comment.