25#import "OFInvalidFormatException.h"
27OF_ASSUME_NONNULL_BEGIN
29typedef struct _OFHuffmanTree {
30 struct _OFHuffmanTree *_Nullable leaves[2];
36OFHuffmanTreeWalk(
id _Nullable stream,
37 bool (*bitReader)(
id _Nullable, uint16_t *_Nonnull, uint8_t),
38 OFHuffmanTree _Nonnull *_Nonnull tree, uint16_t *_Nonnull value)
40 OFHuffmanTree iter = *tree;
43 while (iter->value == 0xFFFF) {
44 if OF_UNLIKELY (!bitReader(stream, &bits, 1)) {
49 if OF_UNLIKELY (iter->leaves[bits] == NULL)
52 iter = iter->leaves[bits];
62extern OFHuffmanTree _Nonnull OFHuffmanTreeNew(uint8_t lengths[_Nonnull],
64extern OFHuffmanTree _Nonnull OFHuffmanTreeNewSingle(uint16_t value);
65extern void OFHuffmanTreeFree(OFHuffmanTree _Nonnull tree);