             guard index < self.leafCount else {
                 return -1
             }
-            switch self.tree[index] {
-            case .leaf(let symbol):
-                if symbol > -1 {
-                    return symbol
-                }
-            default:
-                continue
+            if self.tree[index] > -1 {
+                return self.tree[index]
             }
         }
     }

                index = bit == 0 ? 2 * index + 1 : 2 * index + 2
                treeCode >>= 1
            }
            self.tree[index] = .leaf(length[0])
        }

        if coding {
            for treeIndex in stride(from: self.leafCount - 1, through: 0, by: -1) {
                switch self.tree[treeIndex] {
                case .leaf(let symbol):
                    if symbol == -1 {
                        var replacementArray = Set<Int>()

                        let leftChildIndex = 2 * treeIndex + 1
                        if leftChildIndex < self.leafCount {
                            switch self.tree[leftChildIndex] {
                            case .leaf(let leftSymbol):
                                replacementArray.insert(leftSymbol)
                            case .branch(let leftArray):
                                for leftChild in leftArray {
                                    replacementArray.insert(leftChild)
                                }
                            }
                        }

                        let rightChildIndex = 2 * treeIndex + 2
                        if rightChildIndex < self.leafCount {
                            switch self.tree[rightChildIndex] {
                            case .leaf(let rightSymbol):
                                replacementArray.insert(rightSymbol)
                            case .branch(let rightArray):
                                for rightChild in rightArray {
                                    replacementArray.insert(rightChild)
                                }
                            }
                        }

                        self.tree[treeIndex] = .branch(replacementArray)
                    }
                default:
                    continue
                }
            }
        }
    }



class HuffmanTree {

    private var pointerData: DataWithPointer

    private var tree: [Int]
    private let leafCount: Int

    private var codingIndices: [[Int]]
    private let coding: Bool

    init(bootstrap: [[Int]], _ pointerData: inout DataWithPointer, _ coding: Bool = false) {
        self.coding = coding
