Skip to content

Commit

Permalink
Merge pull request #54 from scalableminds/fix-lint-warnings
Browse files Browse the repository at this point in the history
Fix lint warnings
  • Loading branch information
rschwanhold authored Oct 8, 2020
2 parents caf7224 + 11d0524 commit c29a789
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 57 deletions.
2 changes: 1 addition & 1 deletion rust/build.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
fn main() {
println!("cargo:rustc-link-search={}", "../lz4/lib");
println!("cargo:rustc-link-search=../lz4/lib");
}
4 changes: 2 additions & 2 deletions rust/src/dataset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub struct Dataset {
header: Header,
}

static HEADER_FILE_NAME: &'static str = "header.wkw";
static HEADER_FILE_NAME: &str = "header.wkw";

impl Dataset {
pub fn new(root: &Path) -> Result<Dataset> {
Expand All @@ -21,7 +21,7 @@ impl Dataset {

Ok(Dataset {
root: root.to_owned(),
header: header,
header,
})
}

Expand Down
11 changes: 5 additions & 6 deletions rust/src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ impl File {
};

File {
file: file,
header: header,
file,
header,
block_idx: None,
disk_block_buf: block_buf,
}
Expand Down Expand Up @@ -244,8 +244,7 @@ impl File {
BlockType::LZ4 | BlockType::LZ4HC => {
let last_block_idx = self.header.file_vol() - 1;
let jump_table = self.header.jump_table.as_ref().unwrap();
let size = jump_table[last_block_idx as usize];
size
jump_table[last_block_idx as usize]
}
};

Expand Down Expand Up @@ -331,7 +330,7 @@ impl File {
// write data
self.file
.write_all(&buf_lz4[..len_lz4])
.or(Err(String::from("Could not write LZ4 block")))?;
.or(Err("Could not write LZ4 block"))?;

// update jump table
let jump_entry = self
Expand All @@ -357,7 +356,7 @@ impl File {
// read compressed block
self.file
.read_exact(buf_lz4)
.or(Err(String::from("Error while reading LZ4 block")))?;
.or(Err("Error while reading LZ4 block"))?;

// decompress block
let byte_written = lz4::decompress_safe(buf_lz4, buf)?;
Expand Down
18 changes: 9 additions & 9 deletions rust/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ impl Header {
if block_idx == 0 {
self.data_offset
} else {
let ref jump_table = *self.jump_table.as_ref().unwrap();
let jump_table = &*self.jump_table.as_ref().unwrap();
jump_table[block_idx as usize - 1]
}
}
Expand All @@ -205,7 +205,7 @@ impl Header {
match self.block_type {
BlockType::Raw => Ok(self.block_size() as usize),
BlockType::LZ4 | BlockType::LZ4HC => {
let ref jump_table = *self.jump_table.as_ref().unwrap();
let jump_table = &*self.jump_table.as_ref().unwrap();

if block_idx == 0 {
let block_size = jump_table[0] - self.data_offset;
Expand Down Expand Up @@ -247,7 +247,7 @@ impl Header {
fn from_bytes(buf: [u8; 16]) -> Result<Header> {
let raw: HeaderRaw = unsafe { mem::transmute(buf) };

if &raw.magic != "WKW".as_bytes() {
if &raw.magic != b"WKW" {
return Err(format!("Sequence of magic bytes {:?} is invalid", &raw.magic));
}

Expand Down Expand Up @@ -281,10 +281,10 @@ impl Header {

Ok(Header {
version: raw.version,
block_len_log2: block_len_log2,
file_len_log2: file_len_log2,
block_type: block_type,
voxel_type: voxel_type,
block_len_log2,
file_len_log2,
block_type,
voxel_type,
voxel_size: raw.voxel_size,
data_offset: raw.data_offset,
jump_table: None,
Expand All @@ -297,15 +297,15 @@ impl Header {
let mut raw = HeaderRaw {
magic: [0u8; 3],
version: self.version,
per_dim_log2: per_dim_log2,
per_dim_log2,
block_type: 1u8 + self.block_type as u8,
voxel_type: 1u8 + self.voxel_type as u8,
voxel_size: self.voxel_size,
data_offset: self.data_offset,
};

// set magic bytes
raw.magic.copy_from_slice("WKW".as_bytes());
raw.magic.copy_from_slice(b"WKW");

// convert to bytes
unsafe { mem::transmute::<HeaderRaw, [u8; 16]>(raw) }
Expand Down
16 changes: 8 additions & 8 deletions rust/src/mat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ impl<'a> Mat<'a> {
}

Ok(Mat {
data: data,
shape: shape,
voxel_size: voxel_size,
voxel_type: voxel_type,
data_in_c_order: data_in_c_order,
data,
shape,
voxel_size,
voxel_type,
data_in_c_order,
})
}

Expand Down Expand Up @@ -92,7 +92,7 @@ impl<'a> Mat<'a> {
x_length * y_length * self.voxel_size,
];

fn linearize(x: usize, y: usize, z: usize, stride: &Vec<usize>) -> isize {
fn linearize(x: usize, y: usize, z: usize, stride: &[usize]) -> isize {
(x * stride[0] + y * stride[1] + z * stride[2]) as isize
}
let src_ptr = self.data.as_ptr();
Expand Down Expand Up @@ -186,8 +186,8 @@ impl<'a> Mat<'a> {
* self.voxel_size) as isize;

unsafe {
let mut src_ptr = src.data.as_ptr().offset(src.offset(src_box.min()) as isize);
let mut dst_ptr = self.data.as_mut_ptr().offset(self.offset(dst_pos) as isize);
let mut src_ptr = src.data.as_ptr().add(src.offset(src_box.min()));
let mut dst_ptr = self.data.as_mut_ptr().add(self.offset(dst_pos));

for _ in 0..unified_length.z {
let mut src_ptr_cur = src_ptr;
Expand Down
58 changes: 29 additions & 29 deletions rust/src/morton.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fn unshuffle(z: u64) -> u64 {
impl<'a> From<&'a Vec3> for Morton {
fn from(vec: &'a Vec3) -> Morton {
Morton(
(shuffle(vec.x as u64) << 0)
(shuffle(vec.x as u64))
| (shuffle(vec.y as u64) << 1)
| (shuffle(vec.z as u64) << 2),
)
Expand All @@ -40,7 +40,7 @@ impl<'a> From<&'a Vec3> for Morton {
impl From<Morton> for Vec3 {
fn from(idx: Morton) -> Vec3 {
Vec3 {
x: unshuffle(idx.0 >> 0) as u32,
x: unshuffle(idx.0) as u32,
y: unshuffle(idx.0 >> 1) as u32,
z: unshuffle(idx.0 >> 2) as u32,
}
Expand Down Expand Up @@ -71,8 +71,8 @@ impl Iter {
Ok(Iter {
idx: 0,
end: 0,
log2: log2,
bbox: bbox,
log2,
bbox,
})
}

Expand All @@ -97,10 +97,10 @@ impl Iter {
} else if !bbox_inter.is_empty() {
// need to refine
debug_assert!(cur_log2 > 0);
cur_log2 = cur_log2 - 1;
cur_log2 -= 1;
} else {
// skip cube
cur_idx = cur_idx + numel;
cur_idx += numel;
cur_log2 = cur_idx.trailing_zeros() / 3;
}
}
Expand All @@ -125,37 +125,37 @@ impl Iterator for Iter {
}

// advance
self.idx = self.idx + 1;
self.idx += 1;
Some(self.idx as u64 - 1)
}
}

#[test]
fn test_encoding() {
assert!(Morton::from(&Vec3 { x: 0, y: 0, z: 0 }) == Morton::from(0 as u64));
assert!(Morton::from(&Vec3 { x: 1, y: 0, z: 0 }) == Morton::from(1 as u64));
assert!(Morton::from(&Vec3 { x: 0, y: 1, z: 0 }) == Morton::from(2 as u64));
assert!(Morton::from(&Vec3 { x: 1, y: 1, z: 0 }) == Morton::from(3 as u64));
assert!(Morton::from(&Vec3 { x: 0, y: 0, z: 1 }) == Morton::from(4 as u64));
assert!(Morton::from(&Vec3 { x: 1, y: 0, z: 1 }) == Morton::from(5 as u64));
assert!(Morton::from(&Vec3 { x: 0, y: 1, z: 1 }) == Morton::from(6 as u64));
assert!(Morton::from(&Vec3 { x: 1, y: 1, z: 1 }) == Morton::from(7 as u64));
assert!(Morton::from(&Vec3 { x: 2, y: 0, z: 0 }) == Morton::from(8 as u64));
assert!(Morton::from(&Vec3 { x: 0, y: 2, z: 0 }) == Morton::from(16 as u64));
assert!(Morton::from(&Vec3 { x: 0, y: 0, z: 2 }) == Morton::from(32 as u64));
assert_eq!(Morton::from(&Vec3 { x: 0, y: 0, z: 0 }), Morton::from(0 as u64));
assert_eq!(Morton::from(&Vec3 { x: 1, y: 0, z: 0 }), Morton::from(1 as u64));
assert_eq!(Morton::from(&Vec3 { x: 0, y: 1, z: 0 }), Morton::from(2 as u64));
assert_eq!(Morton::from(&Vec3 { x: 1, y: 1, z: 0 }), Morton::from(3 as u64));
assert_eq!(Morton::from(&Vec3 { x: 0, y: 0, z: 1 }), Morton::from(4 as u64));
assert_eq!(Morton::from(&Vec3 { x: 1, y: 0, z: 1 }), Morton::from(5 as u64));
assert_eq!(Morton::from(&Vec3 { x: 0, y: 1, z: 1 }), Morton::from(6 as u64));
assert_eq!(Morton::from(&Vec3 { x: 1, y: 1, z: 1 }), Morton::from(7 as u64));
assert_eq!(Morton::from(&Vec3 { x: 2, y: 0, z: 0 }), Morton::from(8 as u64));
assert_eq!(Morton::from(&Vec3 { x: 0, y: 2, z: 0 }), Morton::from(16 as u64));
assert_eq!(Morton::from(&Vec3 { x: 0, y: 0, z: 2 }), Morton::from(32 as u64));
}

#[test]
fn test_decoding() {
assert!(Vec3 { x: 0, y: 0, z: 0 } == Vec3::from(Morton::from(0 as u64)));
assert!(Vec3 { x: 1, y: 0, z: 0 } == Vec3::from(Morton::from(1 as u64)));
assert!(Vec3 { x: 0, y: 1, z: 0 } == Vec3::from(Morton::from(2 as u64)));
assert!(Vec3 { x: 1, y: 1, z: 0 } == Vec3::from(Morton::from(3 as u64)));
assert!(Vec3 { x: 0, y: 0, z: 1 } == Vec3::from(Morton::from(4 as u64)));
assert!(Vec3 { x: 1, y: 0, z: 1 } == Vec3::from(Morton::from(5 as u64)));
assert!(Vec3 { x: 0, y: 1, z: 1 } == Vec3::from(Morton::from(6 as u64)));
assert!(Vec3 { x: 1, y: 1, z: 1 } == Vec3::from(Morton::from(7 as u64)));
assert!(Vec3 { x: 2, y: 0, z: 0 } == Vec3::from(Morton::from(8 as u64)));
assert!(Vec3 { x: 0, y: 2, z: 0 } == Vec3::from(Morton::from(16 as u64)));
assert!(Vec3 { x: 0, y: 0, z: 2 } == Vec3::from(Morton::from(32 as u64)));
assert_eq!(Vec3 { x: 0, y: 0, z: 0 }, Vec3::from(Morton::from(0 as u64)));
assert_eq!(Vec3 { x: 1, y: 0, z: 0 }, Vec3::from(Morton::from(1 as u64)));
assert_eq!(Vec3 { x: 0, y: 1, z: 0 }, Vec3::from(Morton::from(2 as u64)));
assert_eq!(Vec3 { x: 1, y: 1, z: 0 }, Vec3::from(Morton::from(3 as u64)));
assert_eq!(Vec3 { x: 0, y: 0, z: 1 }, Vec3::from(Morton::from(4 as u64)));
assert_eq!(Vec3 { x: 1, y: 0, z: 1 }, Vec3::from(Morton::from(5 as u64)));
assert_eq!(Vec3 { x: 0, y: 1, z: 1 }, Vec3::from(Morton::from(6 as u64)));
assert_eq!(Vec3 { x: 1, y: 1, z: 1 }, Vec3::from(Morton::from(7 as u64)));
assert_eq!(Vec3 { x: 2, y: 0, z: 0 }, Vec3::from(Morton::from(8 as u64)));
assert_eq!(Vec3 { x: 0, y: 2, z: 0 }, Vec3::from(Morton::from(16 as u64)));
assert_eq!(Vec3 { x: 0, y: 0, z: 2 }, Vec3::from(Morton::from(32 as u64)));
}
4 changes: 2 additions & 2 deletions rust/src/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub struct Box3 {
impl Box3 {
pub fn new(min: Vec3, max: Vec3) -> Result<Box3> {
match min < (max + 1) {
true => Ok(Box3 { min: min, max: max }),
true => Ok(Box3 { min, max }),
false => Err(String::from("Minimum and maximum are in conflict")),
}
}
Expand Down Expand Up @@ -48,7 +48,7 @@ impl From<Vec3> for Box3 {
fn from(max: Vec3) -> Box3 {
Box3 {
min: Vec3::from(0u32),
max: max,
max,
}
}
}
Expand Down

0 comments on commit c29a789

Please sign in to comment.