Skip to content

Support for H5Aiterate2 by creation order, H5Aopen_by_idx and H5Aget_info_by_name - #238

Open
CramBL wants to merge 10 commits into
metno:mainfrom
CramBL:attr-iteration
Open

Support for H5Aiterate2 by creation order, H5Aopen_by_idx and H5Aget_info_by_name#238
CramBL wants to merge 10 commits into
metno:mainfrom
CramBL:attr-iteration

Conversation

@CramBL

@CramBL CramBL commented Sep 7, 2026

Copy link
Copy Markdown

Builds on top of #235 & #236

Resolves #231

Both enums were private to hl::group, so iter_visit could only be
called with Default::default() for the order arguments. The previously
private TraversalOrder is renamed to IndexType with variants Name and
CreationOrder, matching H5_index_t.
index_type now comes before iteration_order, as in H5Literate2. Until
IndexType and IterationOrder were exported the order arguments could
only be passed as Default::default(), so the reorder breaks no caller.

The closure takes the link name and LinkInfo and returns Result<()>.
Its error is returned from iter_visit instead of being reported as a
stop with a partial result. The group argument is dropped since
H5Literate always passes back the group being iterated, and the
accumulator argument is dropped since the closure can capture its own
state.

find_link takes a closure returning Result<Option<B>> and stops at the
first Some, returning the value. Together with the error this maps onto
the continue, stop and fail returns of the C callback.

iter_visit_from takes a LinkCursor and returns the cursor of the next
link together with the value, so a stopped iteration can be resumed.
The cursor carries the index type and iteration order it counts along,
so it cannot be reused with a different traversal. A cursor at or past
the last link yields None instead of the HDF5 out of bounds error.

A panic in the closure is resumed after H5Literate returns instead of
being reported as an HDF5 error.
The bitflags allowed INDEXED without TRACKED, a combination HDF5 rejects
when the property list is built, so the invalid state was only caught at
runtime. The enum with Untracked, Tracked and Indexed cannot express it,
and matches LinkCreationOrder.
FileCreate and DatasetCreate already expose both. A group tracking
attribute creation order is what h5py's track_order=True and netCDF-4
produce, and it is required for iterating attributes by creation order.
H5Aiterate2 has the same shape as H5Literate: an index type, an
iteration order, an in/out position and a callback that continues,
stops or fails. IndexType, IterationOrder and the cursor move to
hl::iteration together with the callback driver, so attribute iteration
can reuse them instead of a second copy of the unsafe code. LinkCursor
is renamed IterationCursor since it no longer counts only links.
Location::iter_attrs, find_attr and iter_attrs_from mirror the link
iteration on Group, over H5Aiterate2 with the shared callback driver.
The callback receives an AttrInfo built from H5A_info_t. attr_names is
now the name order case of iter_attrs.
attr_by_index opens an attribute by its position along an index type
and order over H5Aopen_by_idx. attr_info returns the AttrInfo of a
named attribute over H5Aget_info_by_name.
The tracked group also tracks attribute creation order, and the example
lists its attributes in that order, opens one by position and looks up
the info of another by name. The example is renamed creation_order since
it no longer covers only links.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for H5Aiterate2 by creation order, H5Aopen_by_idx and H5Aget_info_by_name

1 participant