Skip to main content

Module composite

Module composite 

Source
Expand description

Writing a composite from C: the node array, and the borrowed tree it becomes.

The mirror of crate::item. A C caller describes a composite the way the format does — a head, then its members, each node declaring how many of the nodes after it are its own (ADR-027 § Binding) — and hands the whole thing over as one preorder array:

  index  kind       name    member_count  payloads
  0      composite  "w"     2             -             <- the head, nodes[0]
  1      tensor     "w.0"   0             1 slice
  2      composite  "w.1"   2             -
  3      tensor     "w.1.0" 0             1 slice
  4      tensor     "w.1.1" 0             1 slice

One array rather than a tree of pointers, for the reason crate::item gives: a pointer tree crossing an ABI can be cyclic, and preorder with member counts cannot describe a cycle. It is also one allocation for the caller instead of one per level.

hurray-io wants that as a tree of borrowed nodes — CompositeNode<'a> for a stream, FileCompositeNode<'a> for a file — so this module turns one into the other, with an explicit stack and no recursion (ADR-041 § 10), and with the payload slices left borrowed from the caller the whole way (§ 3).

Structs§

HurrayCompositeNode
One node of a composite to write: a tensor member, or a head whose members follow it.