Current section

Files

Jump to
kadabra lib huffman.ex
Raw

lib/huffman.ex

defmodule Kadabra.Huffman do
@moduledoc """
Huffman decoder.
"""
def decode(bin), do: decode(bin, [])
def decode(bin, acc) do
case bin do
<< 0x1ff8 :: 13, rest::bitstring>> -> decode(rest, [0 | acc])
<< 0x7fffd8 :: 23, rest::bitstring>> -> decode(rest, [1 | acc])
<< 0xfffffe2 :: 28, rest::bitstring>> -> decode(rest, [2 | acc])
<< 0xfffffe3 :: 28, rest::bitstring>> -> decode(rest, [3 | acc])
<< 0xfffffe4 :: 28, rest::bitstring>> -> decode(rest, [4 | acc])
<< 0xfffffe5 :: 28, rest::bitstring>> -> decode(rest, [5 | acc])
<< 0xfffffe6 :: 28, rest::bitstring>> -> decode(rest, [6 | acc])
<< 0xfffffe7 :: 28, rest::bitstring>> -> decode(rest, [7 | acc])
<< 0xfffffe8 :: 28, rest::bitstring>> -> decode(rest, [8 | acc])
<< 0xffffea :: 24, rest::bitstring>> -> decode(rest, [9 | acc])
<< 0x3ffffffc :: 30, rest::bitstring>> -> decode(rest, [10 | acc])
<< 0xfffffe9 :: 28, rest::bitstring>> -> decode(rest, [11 | acc])
<< 0xfffffea :: 28, rest::bitstring>> -> decode(rest, [12 | acc])
<< 0x3ffffffd :: 30, rest::bitstring>> -> decode(rest, [13 | acc])
<< 0xfffffeb :: 28, rest::bitstring>> -> decode(rest, [14 | acc])
<< 0xfffffec :: 28, rest::bitstring>> -> decode(rest, [15 | acc])
<< 0xfffffed :: 28, rest::bitstring>> -> decode(rest, [16 | acc])
<< 0xfffffee :: 28, rest::bitstring>> -> decode(rest, [17 | acc])
<< 0xfffffef :: 28, rest::bitstring>> -> decode(rest, [18 | acc])
<< 0xffffff0 :: 28, rest::bitstring>> -> decode(rest, [19 | acc])
<< 0xffffff1 :: 28, rest::bitstring>> -> decode(rest, [20 | acc])
<< 0xffffff2 :: 28, rest::bitstring>> -> decode(rest, [21 | acc])
<< 0x3ffffffe :: 30, rest::bitstring>> -> decode(rest, [22 | acc])
<< 0xffffff3 :: 28, rest::bitstring>> -> decode(rest, [23 | acc])
<< 0xffffff4 :: 28, rest::bitstring>> -> decode(rest, [24 | acc])
<< 0xffffff5 :: 28, rest::bitstring>> -> decode(rest, [25 | acc])
<< 0xffffff6 :: 28, rest::bitstring>> -> decode(rest, [26 | acc])
<< 0xffffff7 :: 28, rest::bitstring>> -> decode(rest, [27 | acc])
<< 0xffffff8 :: 28, rest::bitstring>> -> decode(rest, [28 | acc])
<< 0xffffff9 :: 28, rest::bitstring>> -> decode(rest, [29 | acc])
<< 0xffffffa :: 28, rest::bitstring>> -> decode(rest, [30 | acc])
<< 0xffffffb :: 28, rest::bitstring>> -> decode(rest, [31 | acc])
<< 0x14 :: 6, rest::bitstring>> -> decode(rest, [32 | acc])
<< 0x3f8 :: 10, rest::bitstring>> -> decode(rest, [33 | acc])
<< 0x3f9 :: 10, rest::bitstring>> -> decode(rest, [34 | acc])
<< 0xffa :: 12, rest::bitstring>> -> decode(rest, [35 | acc])
<< 0x1ff9 :: 13, rest::bitstring>> -> decode(rest, [36 | acc])
<< 0x15 :: 6, rest::bitstring>> -> decode(rest, [37 | acc])
<< 0xf8 :: 8, rest::bitstring>> -> decode(rest, [38 | acc])
<< 0x7fa :: 11, rest::bitstring>> -> decode(rest, [39 | acc])
<< 0x3fa :: 10, rest::bitstring>> -> decode(rest, [40 | acc])
<< 0x3fb :: 10, rest::bitstring>> -> decode(rest, [41 | acc])
<< 0xf9 :: 8, rest::bitstring>> -> decode(rest, [42 | acc])
<< 0x7fb :: 11, rest::bitstring>> -> decode(rest, [43 | acc])
<< 0xfa :: 8, rest::bitstring>> -> decode(rest, [44 | acc])
<< 0x16 :: 6, rest::bitstring>> -> decode(rest, [45 | acc])
<< 0x17 :: 6, rest::bitstring>> -> decode(rest, [46 | acc])
<< 0x18 :: 6, rest::bitstring>> -> decode(rest, [47 | acc])
<< 0x0 :: 5, rest::bitstring>> -> decode(rest, [48 | acc])
<< 0x1 :: 5, rest::bitstring>> -> decode(rest, [49 | acc])
<< 0x2 :: 5, rest::bitstring>> -> decode(rest, [50 | acc])
<< 0x19 :: 6, rest::bitstring>> -> decode(rest, [51 | acc])
<< 0x1a :: 6, rest::bitstring>> -> decode(rest, [52 | acc])
<< 0x1b :: 6, rest::bitstring>> -> decode(rest, [53 | acc])
<< 0x1c :: 6, rest::bitstring>> -> decode(rest, [54 | acc])
<< 0x1d :: 6, rest::bitstring>> -> decode(rest, [55 | acc])
<< 0x1e :: 6, rest::bitstring>> -> decode(rest, [56 | acc])
<< 0x1f :: 6, rest::bitstring>> -> decode(rest, [57 | acc])
<< 0x5c :: 7, rest::bitstring>> -> decode(rest, [58 | acc])
<< 0xfb :: 8, rest::bitstring>> -> decode(rest, [59 | acc])
<< 0x7ffc :: 15, rest::bitstring>> -> decode(rest, [60 | acc])
<< 0x20 :: 6, rest::bitstring>> -> decode(rest, [61 | acc])
<< 0xffb :: 12, rest::bitstring>> -> decode(rest, [62 | acc])
<< 0x3fc :: 10, rest::bitstring>> -> decode(rest, [63 | acc])
<< 0x1ffa :: 13, rest::bitstring>> -> decode(rest, [64 | acc])
<< 0x21 :: 6, rest::bitstring>> -> decode(rest, [65 | acc])
<< 0x5d :: 7, rest::bitstring>> -> decode(rest, [66 | acc])
<< 0x5e :: 7, rest::bitstring>> -> decode(rest, [67 | acc])
<< 0x5f :: 7, rest::bitstring>> -> decode(rest, [68 | acc])
<< 0x60 :: 7, rest::bitstring>> -> decode(rest, [69 | acc])
<< 0x61 :: 7, rest::bitstring>> -> decode(rest, [70 | acc])
<< 0x62 :: 7, rest::bitstring>> -> decode(rest, [71 | acc])
<< 0x63 :: 7, rest::bitstring>> -> decode(rest, [72 | acc])
<< 0x64 :: 7, rest::bitstring>> -> decode(rest, [73 | acc])
<< 0x65 :: 7, rest::bitstring>> -> decode(rest, [74 | acc])
<< 0x66 :: 7, rest::bitstring>> -> decode(rest, [75 | acc])
<< 0x67 :: 7, rest::bitstring>> -> decode(rest, [76 | acc])
<< 0x68 :: 7, rest::bitstring>> -> decode(rest, [77 | acc])
<< 0x69 :: 7, rest::bitstring>> -> decode(rest, [78 | acc])
<< 0x6a :: 7, rest::bitstring>> -> decode(rest, [79 | acc])
<< 0x6b :: 7, rest::bitstring>> -> decode(rest, [80 | acc])
<< 0x6c :: 7, rest::bitstring>> -> decode(rest, [81 | acc])
<< 0x6d :: 7, rest::bitstring>> -> decode(rest, [82 | acc])
<< 0x6e :: 7, rest::bitstring>> -> decode(rest, [83 | acc])
<< 0x6f :: 7, rest::bitstring>> -> decode(rest, [84 | acc])
<< 0x70 :: 7, rest::bitstring>> -> decode(rest, [85 | acc])
<< 0x71 :: 7, rest::bitstring>> -> decode(rest, [86 | acc])
<< 0x72 :: 7, rest::bitstring>> -> decode(rest, [87 | acc])
<< 0xfc :: 8, rest::bitstring>> -> decode(rest, [88 | acc])
<< 0x73 :: 7, rest::bitstring>> -> decode(rest, [89 | acc])
<< 0xfd :: 8, rest::bitstring>> -> decode(rest, [90 | acc])
<< 0x1ffb :: 13, rest::bitstring>> -> decode(rest, [91 | acc])
<< 0x7fff0 :: 19, rest::bitstring>> -> decode(rest, [92 | acc])
<< 0x1ffc :: 13, rest::bitstring>> -> decode(rest, [93 | acc])
<< 0x3ffc :: 14, rest::bitstring>> -> decode(rest, [94 | acc])
<< 0x22 :: 6, rest::bitstring>> -> decode(rest, [95 | acc])
<< 0x7ffd :: 15, rest::bitstring>> -> decode(rest, [96 | acc])
<< 0x3 :: 5, rest::bitstring>> -> decode(rest, [97 | acc])
<< 0x23 :: 6, rest::bitstring>> -> decode(rest, [98 | acc])
<< 0x4 :: 5, rest::bitstring>> -> decode(rest, [99 | acc])
<< 0x24 :: 6, rest::bitstring>> -> decode(rest, [100 | acc])
<< 0x5 :: 5, rest::bitstring>> -> decode(rest, [101 | acc])
<< 0x25 :: 6, rest::bitstring>> -> decode(rest, [102 | acc])
<< 0x26 :: 6, rest::bitstring>> -> decode(rest, [103 | acc])
<< 0x27 :: 6, rest::bitstring>> -> decode(rest, [104 | acc])
<< 0x6 :: 5, rest::bitstring>> -> decode(rest, [105 | acc])
<< 0x74 :: 7, rest::bitstring>> -> decode(rest, [106 | acc])
<< 0x75 :: 7, rest::bitstring>> -> decode(rest, [107 | acc])
<< 0x28 :: 6, rest::bitstring>> -> decode(rest, [108 | acc])
<< 0x29 :: 6, rest::bitstring>> -> decode(rest, [109 | acc])
<< 0x2a :: 6, rest::bitstring>> -> decode(rest, [110 | acc])
<< 0x7 :: 5, rest::bitstring>> -> decode(rest, [111 | acc])
<< 0x2b :: 6, rest::bitstring>> -> decode(rest, [112 | acc])
<< 0x76 :: 7, rest::bitstring>> -> decode(rest, [113 | acc])
<< 0x2c :: 6, rest::bitstring>> -> decode(rest, [114 | acc])
<< 0x8 :: 5, rest::bitstring>> -> decode(rest, [115 | acc])
<< 0x9 :: 5, rest::bitstring>> -> decode(rest, [116 | acc])
<< 0x2d :: 6, rest::bitstring>> -> decode(rest, [117 | acc])
<< 0x77 :: 7, rest::bitstring>> -> decode(rest, [118 | acc])
<< 0x78 :: 7, rest::bitstring>> -> decode(rest, [119 | acc])
<< 0x79 :: 7, rest::bitstring>> -> decode(rest, [120 | acc])
<< 0x7a :: 7, rest::bitstring>> -> decode(rest, [121 | acc])
<< 0x7b :: 7, rest::bitstring>> -> decode(rest, [122 | acc])
<< 0x7ffe :: 15, rest::bitstring>> -> decode(rest, [123 | acc])
<< 0x7fc :: 11, rest::bitstring>> -> decode(rest, [124 | acc])
<< 0x3ffd :: 14, rest::bitstring>> -> decode(rest, [125 | acc])
<< 0x1ffd :: 13, rest::bitstring>> -> decode(rest, [126 | acc])
<< 0xffffffc :: 28, rest::bitstring>> -> decode(rest, [127 | acc])
<< 0xfffe6 :: 20, rest::bitstring>> -> decode(rest, [128 | acc])
<< 0x3fffd2 :: 22, rest::bitstring>> -> decode(rest, [129 | acc])
<< 0xfffe7 :: 20, rest::bitstring>> -> decode(rest, [130 | acc])
<< 0xfffe8 :: 20, rest::bitstring>> -> decode(rest, [131 | acc])
<< 0x3fffd3 :: 22, rest::bitstring>> -> decode(rest, [132 | acc])
<< 0x3fffd4 :: 22, rest::bitstring>> -> decode(rest, [133 | acc])
<< 0x3fffd5 :: 22, rest::bitstring>> -> decode(rest, [134 | acc])
<< 0x7fffd9 :: 23, rest::bitstring>> -> decode(rest, [135 | acc])
<< 0x3fffd6 :: 22, rest::bitstring>> -> decode(rest, [136 | acc])
<< 0x7fffda :: 23, rest::bitstring>> -> decode(rest, [137 | acc])
<< 0x7fffdb :: 23, rest::bitstring>> -> decode(rest, [138 | acc])
<< 0x7fffdc :: 23, rest::bitstring>> -> decode(rest, [139 | acc])
<< 0x7fffdd :: 23, rest::bitstring>> -> decode(rest, [140 | acc])
<< 0x7fffde :: 23, rest::bitstring>> -> decode(rest, [141 | acc])
<< 0xffffeb :: 24, rest::bitstring>> -> decode(rest, [142 | acc])
<< 0x7fffdf :: 23, rest::bitstring>> -> decode(rest, [143 | acc])
<< 0xffffec :: 24, rest::bitstring>> -> decode(rest, [144 | acc])
<< 0xffffed :: 24, rest::bitstring>> -> decode(rest, [145 | acc])
<< 0x3fffd7 :: 22, rest::bitstring>> -> decode(rest, [146 | acc])
<< 0x7fffe0 :: 23, rest::bitstring>> -> decode(rest, [147 | acc])
<< 0xffffee :: 24, rest::bitstring>> -> decode(rest, [148 | acc])
<< 0x7fffe1 :: 23, rest::bitstring>> -> decode(rest, [149 | acc])
<< 0x7fffe2 :: 23, rest::bitstring>> -> decode(rest, [150 | acc])
<< 0x7fffe3 :: 23, rest::bitstring>> -> decode(rest, [151 | acc])
<< 0x7fffe4 :: 23, rest::bitstring>> -> decode(rest, [152 | acc])
<< 0x1fffdc :: 21, rest::bitstring>> -> decode(rest, [153 | acc])
<< 0x3fffd8 :: 22, rest::bitstring>> -> decode(rest, [154 | acc])
<< 0x7fffe5 :: 23, rest::bitstring>> -> decode(rest, [155 | acc])
<< 0x3fffd9 :: 22, rest::bitstring>> -> decode(rest, [156 | acc])
<< 0x7fffe6 :: 23, rest::bitstring>> -> decode(rest, [157 | acc])
<< 0x7fffe7 :: 23, rest::bitstring>> -> decode(rest, [158 | acc])
<< 0xffffef :: 24, rest::bitstring>> -> decode(rest, [159 | acc])
<< 0x3fffda :: 22, rest::bitstring>> -> decode(rest, [160 | acc])
<< 0x1fffdd :: 21, rest::bitstring>> -> decode(rest, [161 | acc])
<< 0xfffe9 :: 20, rest::bitstring>> -> decode(rest, [162 | acc])
<< 0x3fffdb :: 22, rest::bitstring>> -> decode(rest, [163 | acc])
<< 0x3fffdc :: 22, rest::bitstring>> -> decode(rest, [164 | acc])
<< 0x7fffe8 :: 23, rest::bitstring>> -> decode(rest, [165 | acc])
<< 0x7fffe9 :: 23, rest::bitstring>> -> decode(rest, [166 | acc])
<< 0x1fffde :: 21, rest::bitstring>> -> decode(rest, [167 | acc])
<< 0x7fffea :: 23, rest::bitstring>> -> decode(rest, [168 | acc])
<< 0x3fffdd :: 22, rest::bitstring>> -> decode(rest, [169 | acc])
<< 0x3fffde :: 22, rest::bitstring>> -> decode(rest, [170 | acc])
<< 0xfffff0 :: 24, rest::bitstring>> -> decode(rest, [171 | acc])
<< 0x1fffdf :: 21, rest::bitstring>> -> decode(rest, [172 | acc])
<< 0x3fffdf :: 22, rest::bitstring>> -> decode(rest, [173 | acc])
<< 0x7fffeb :: 23, rest::bitstring>> -> decode(rest, [174 | acc])
<< 0x7fffec :: 23, rest::bitstring>> -> decode(rest, [175 | acc])
<< 0x1fffe0 :: 21, rest::bitstring>> -> decode(rest, [176 | acc])
<< 0x1fffe1 :: 21, rest::bitstring>> -> decode(rest, [177 | acc])
<< 0x3fffe0 :: 22, rest::bitstring>> -> decode(rest, [178 | acc])
<< 0x1fffe2 :: 21, rest::bitstring>> -> decode(rest, [179 | acc])
<< 0x7fffed :: 23, rest::bitstring>> -> decode(rest, [180 | acc])
<< 0x3fffe1 :: 22, rest::bitstring>> -> decode(rest, [181 | acc])
<< 0x7fffee :: 23, rest::bitstring>> -> decode(rest, [182 | acc])
<< 0x7fffef :: 23, rest::bitstring>> -> decode(rest, [183 | acc])
<< 0xfffea :: 20, rest::bitstring>> -> decode(rest, [184 | acc])
<< 0x3fffe2 :: 22, rest::bitstring>> -> decode(rest, [185 | acc])
<< 0x3fffe3 :: 22, rest::bitstring>> -> decode(rest, [186 | acc])
<< 0x3fffe4 :: 22, rest::bitstring>> -> decode(rest, [187 | acc])
<< 0x7ffff0 :: 23, rest::bitstring>> -> decode(rest, [188 | acc])
<< 0x3fffe5 :: 22, rest::bitstring>> -> decode(rest, [189 | acc])
<< 0x3fffe6 :: 22, rest::bitstring>> -> decode(rest, [190 | acc])
<< 0x7ffff1 :: 23, rest::bitstring>> -> decode(rest, [191 | acc])
<< 0x3ffffe0 :: 26, rest::bitstring>> -> decode(rest, [192 | acc])
<< 0x3ffffe1 :: 26, rest::bitstring>> -> decode(rest, [193 | acc])
<< 0xfffeb :: 20, rest::bitstring>> -> decode(rest, [194 | acc])
<< 0x7fff1 :: 19, rest::bitstring>> -> decode(rest, [195 | acc])
<< 0x3fffe7 :: 22, rest::bitstring>> -> decode(rest, [196 | acc])
<< 0x7ffff2 :: 23, rest::bitstring>> -> decode(rest, [197 | acc])
<< 0x3fffe8 :: 22, rest::bitstring>> -> decode(rest, [198 | acc])
<< 0x1ffffec :: 25, rest::bitstring>> -> decode(rest, [199 | acc])
<< 0x3ffffe2 :: 26, rest::bitstring>> -> decode(rest, [200 | acc])
<< 0x3ffffe3 :: 26, rest::bitstring>> -> decode(rest, [201 | acc])
<< 0x3ffffe4 :: 26, rest::bitstring>> -> decode(rest, [202 | acc])
<< 0x7ffffde :: 27, rest::bitstring>> -> decode(rest, [203 | acc])
<< 0x7ffffdf :: 27, rest::bitstring>> -> decode(rest, [204 | acc])
<< 0x3ffffe5 :: 26, rest::bitstring>> -> decode(rest, [205 | acc])
<< 0xfffff1 :: 24, rest::bitstring>> -> decode(rest, [206 | acc])
<< 0x1ffffed :: 25, rest::bitstring>> -> decode(rest, [207 | acc])
<< 0x7fff2 :: 19, rest::bitstring>> -> decode(rest, [208 | acc])
<< 0x1fffe3 :: 21, rest::bitstring>> -> decode(rest, [209 | acc])
<< 0x3ffffe6 :: 26, rest::bitstring>> -> decode(rest, [210 | acc])
<< 0x7ffffe0 :: 27, rest::bitstring>> -> decode(rest, [211 | acc])
<< 0x7ffffe1 :: 27, rest::bitstring>> -> decode(rest, [212 | acc])
<< 0x3ffffe7 :: 26, rest::bitstring>> -> decode(rest, [213 | acc])
<< 0x7ffffe2 :: 27, rest::bitstring>> -> decode(rest, [214 | acc])
<< 0xfffff2 :: 24, rest::bitstring>> -> decode(rest, [215 | acc])
<< 0x1fffe4 :: 21, rest::bitstring>> -> decode(rest, [216 | acc])
<< 0x1fffe5 :: 21, rest::bitstring>> -> decode(rest, [217 | acc])
<< 0x3ffffe8 :: 26, rest::bitstring>> -> decode(rest, [218 | acc])
<< 0x3ffffe9 :: 26, rest::bitstring>> -> decode(rest, [219 | acc])
<< 0xffffffd :: 28, rest::bitstring>> -> decode(rest, [220 | acc])
<< 0x7ffffe3 :: 27, rest::bitstring>> -> decode(rest, [221 | acc])
<< 0x7ffffe4 :: 27, rest::bitstring>> -> decode(rest, [222 | acc])
<< 0x7ffffe5 :: 27, rest::bitstring>> -> decode(rest, [223 | acc])
<< 0xfffec :: 20, rest::bitstring>> -> decode(rest, [224 | acc])
<< 0xfffff3 :: 24, rest::bitstring>> -> decode(rest, [225 | acc])
<< 0xfffed :: 20, rest::bitstring>> -> decode(rest, [226 | acc])
<< 0x1fffe6 :: 21, rest::bitstring>> -> decode(rest, [227 | acc])
<< 0x3fffe9 :: 22, rest::bitstring>> -> decode(rest, [228 | acc])
<< 0x1fffe7 :: 21, rest::bitstring>> -> decode(rest, [229 | acc])
<< 0x1fffe8 :: 21, rest::bitstring>> -> decode(rest, [230 | acc])
<< 0x7ffff3 :: 23, rest::bitstring>> -> decode(rest, [231 | acc])
<< 0x3fffea :: 22, rest::bitstring>> -> decode(rest, [232 | acc])
<< 0x3fffeb :: 22, rest::bitstring>> -> decode(rest, [233 | acc])
<< 0x1ffffee :: 25, rest::bitstring>> -> decode(rest, [234 | acc])
<< 0x1ffffef :: 25, rest::bitstring>> -> decode(rest, [235 | acc])
<< 0xfffff4 :: 24, rest::bitstring>> -> decode(rest, [236 | acc])
<< 0xfffff5 :: 24, rest::bitstring>> -> decode(rest, [237 | acc])
<< 0x3ffffea :: 26, rest::bitstring>> -> decode(rest, [238 | acc])
<< 0x7ffff4 :: 23, rest::bitstring>> -> decode(rest, [239 | acc])
<< 0x3ffffeb :: 26, rest::bitstring>> -> decode(rest, [240 | acc])
<< 0x7ffffe6 :: 27, rest::bitstring>> -> decode(rest, [241 | acc])
<< 0x3ffffec :: 26, rest::bitstring>> -> decode(rest, [242 | acc])
<< 0x3ffffed :: 26, rest::bitstring>> -> decode(rest, [243 | acc])
<< 0x7ffffe7 :: 27, rest::bitstring>> -> decode(rest, [244 | acc])
<< 0x7ffffe8 :: 27, rest::bitstring>> -> decode(rest, [245 | acc])
<< 0x7ffffe9 :: 27, rest::bitstring>> -> decode(rest, [246 | acc])
<< 0x7ffffea :: 27, rest::bitstring>> -> decode(rest, [247 | acc])
<< 0x7ffffeb :: 27, rest::bitstring>> -> decode(rest, [248 | acc])
<< 0xffffffe :: 28, rest::bitstring>> -> decode(rest, [249 | acc])
<< 0x7ffffec :: 27, rest::bitstring>> -> decode(rest, [250 | acc])
<< 0x7ffffed :: 27, rest::bitstring>> -> decode(rest, [251 | acc])
<< 0x7ffffee :: 27, rest::bitstring>> -> decode(rest, [252 | acc])
<< 0x7ffffef :: 27, rest::bitstring>> -> decode(rest, [253 | acc])
<< 0x7fffff0 :: 27, rest::bitstring>> -> decode(rest, [254 | acc])
<< 0x3ffffee :: 26, rest::bitstring>> -> decode(rest, [255 | acc])
<< 0x3fffffff :: 30, rest::bitstring>> -> decode(rest, [256 | acc])
_ -> acc |> Enum.reverse
end
end
end