MCPcopy Create free account
hub / github.com/ElementsProject/elements / typeSkip

Function typeSkip

src/simplicity/type.h:78–85  ·  view source on GitHub ↗

Return the index of the largest subexpression of 'type_dag[i]' (possibly 'i' itself) that is either * (1) a 'SUM' type; * (2) a 'PRODUCT' type of two non-trivial type arguments. * * If there is no such subexpression at all, i.e. when 'type_dag[i]' is a trivial type, return 0 * (which is the index of the 'ONE' type). * * This functions is used for fast traversals of type expressions, skippin

Source from the content-addressed store, hash-verified

76 * as this function runs in in constant time.
77 */
78static inline size_t typeSkip(size_t i, const type* type_dag) {
79 if (0 == type_dag[i].bitSize) return 0;
80 if (PRODUCT == type_dag[i].kind &&
81 (0 == type_dag[type_dag[i].typeArg[0]].bitSize || 0 == type_dag[type_dag[i].typeArg[1]].bitSize)) {
82 return type_dag[i].skip;
83 }
84 return i;
85}
86
87/* Precondition: type type_dag[i] and 'type_dag' is well-formed.
88 * if type_dag[i] is a non-trival 'PRODUCT', then both of its two type arguments are non-trival.

Callers 2

writeValueFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected