Skip to content

Commit 222cac1

Browse files
committed
Add Dataset::chunk_info() for 1.10.5+
1 parent fee6f33 commit 222cac1

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

src/hl/dataset.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ use std::ops::Deref;
44

55
use num_integer::div_floor;
66

7+
#[cfg(hdf5_1_10_5)]
8+
use hdf5_sys::h5d::H5Dget_chunk_info;
79
use hdf5_sys::{
810
h5::HADDR_UNDEF,
911
h5d::{
@@ -62,6 +64,32 @@ pub enum Chunk {
6264
Manual(Vec<Ix>),
6365
}
6466

67+
#[cfg(hdf5_1_10_5)]
68+
#[derive(Clone, Debug, PartialEq, Eq)]
69+
pub struct ChunkInfo {
70+
/// Array with a size equal to the dataset’s rank whose elements contain 0-based
71+
/// logical positions of the chunk’s first element in each dimension.
72+
pub offset: Vec<u64>,
73+
/// Filter mask that indicates which filters were used with the chunk when written.
74+
/// A zero value indicates that all enabled filters are applied on the chunk.
75+
/// A filter is skipped if the bit corresponding to the filter’s position in
76+
/// the pipeline (0 ≤ position < 32) is turned on.
77+
pub filter_mask: u32,
78+
/// Chunk address in the file.
79+
pub addr: u64,
80+
/// Chunk size in bytes.
81+
pub size: u64,
82+
}
83+
84+
#[cfg(hdf5_1_10_5)]
85+
impl ChunkInfo {
86+
pub(crate) fn new(ndim: usize) -> Self {
87+
let mut offset = Vec::with_capacity(ndim);
88+
unsafe { offset.set_len(ndim) };
89+
Self { offset, filter_mask: 0, addr: 0, size: 0 }
90+
}
91+
}
92+
6593
impl Dataset {
6694
/// Returns whether this dataset is resizable along some axis.
6795
pub fn is_resizable(&self) -> bool {
@@ -88,6 +116,28 @@ impl Dataset {
88116
}))
89117
}
90118

119+
#[cfg(hdf5_1_10_5)]
120+
/// Retrieves the chunk information for the chunk specified by its index.
121+
pub fn chunk_info(&self, index: usize) -> Option<ChunkInfo> {
122+
if !self.is_chunked() {
123+
return None;
124+
}
125+
h5lock!(self.space().map_or(None, |s| {
126+
let mut chunk_info = ChunkInfo::new(self.ndim());
127+
h5check(H5Dget_chunk_info(
128+
self.id(),
129+
s.id(),
130+
index as _,
131+
chunk_info.offset.as_mut_ptr(),
132+
&mut chunk_info.filter_mask,
133+
&mut chunk_info.addr,
134+
&mut chunk_info.size,
135+
))
136+
.map(|_| chunk_info)
137+
.ok()
138+
}))
139+
}
140+
91141
/// Returns the chunk shape if the dataset is chunked.
92142
pub fn chunks(&self) -> Option<Vec<Ix>> {
93143
h5lock!({

0 commit comments

Comments
 (0)