Skip to main content

Module item

Module item 

Source
Expand description

A read item: one tensor, or a composite and everything under it.

hurray-io hands a driver a sum type — StreamItem and FileItem are each a tensor or a composite whose members are items in turn — and C has no sum type to receive it in. This module is the answer ADR-041 § Open Questions asked for: an item crosses as the sequence the format itself uses, a head followed by its members, with each node declaring how many of the nodes after it are its own (ADR-027 § Binding).

So walking a composite from C is a loop over an array, and the nesting is in the member_count column:

  index  kind       name    member_count
  0      composite  "w"     2              <- the head, nodes[0]
  1      tensor     "w.0"   0
  2      composite  "w.1"   2              <- a nested head: its members follow it
  3      tensor     "w.1.0" 0
  4      tensor     "w.1.1" 0

Preorder rather than a tree of pointers, for a reason that outlives taste: a pointer tree crossing an ABI can be cyclic, and a walker on either side loops forever on one. An array with member counts cannot describe a cycle at all — every child sits after its parent.

Both surfaces produce this: hurray_reader_next_item from the stream core’s assembler, and hurray_file_reader_read_composite from the file core’s walk. A composite is the same shape whichever one carried it.

Structs§

HurrayItem
Opaque handle to one read item: a tensor, or a composite and its whole subtree.
HurrayItemNode
One node of an item, as a C caller sees it.

Constants§

HURRAY_ITEM_COMPOSITE
A composite head: it owns no buffers, and the next member_count sibling-level nodes are its members.
HURRAY_ITEM_TENSOR
A plain tensor: it owns buffers and no node after it belongs to it.

Functions§

hurray_item_destroy⚠
Destroys an item, every tensor and name it owns, then writes null through handle.
hurray_item_kind⚠
The item’s own kind: HURRAY_ITEM_TENSOR or HURRAY_ITEM_COMPOSITE.
hurray_item_node⚠
Copies node index into out_node.
hurray_item_node_count⚠
How many nodes the item has in total, counting the root and every nested member.