(
defn-
decode1
[
bb
^
long
n-out
]
(
let
[
freqs
(
read-frequencies1
bb
)
^
"[[I"
cum-freqs
(
make-array
int-array-type
256
)
_
(
dotimes
[
i
256
]
(
aset
cum-freqs
i
(
cumulative-frequencies
(
aget
freqs
i
)
)
)
)
^
"[[B"
tables
(
make-array
byte-array-type
256
)
_
(
dotimes
[
i
256
]
(
aset
tables
i
(
reverse-lookup-table
(
aget
cum-freqs
i
)
)
)
)
quarter
(
quot
n-out
4
)
truncated
(
*
4
quarter
)
states
(
bb/read-ints
bb
4
)
last-syms
(
int-array
4
)
out
(
byte-array
n-out
)
]
(
dotimes
[
i
quarter
]
(
dotimes
[
j
4
]
(
let
[
state
(
aget
states
j
)
f
(
bit-and
state
0xfff
)
last-sym
(
aget
last-syms
j
)
^
ints
cfreqs
(
aget
cum-freqs
last-sym
)
sym
(
bit-and
(
aget
^
bytes
(
aget
tables
last-sym
)
f
)
0xff
)
state'
(
->>
state
(
advance-step
(
aget
cfreqs
sym
)
(
aget
^
ints
(
aget
freqs
last-sym
)
sym
)
)
(
renormalize-state
bb
)
)
]
(
aset
out
(
+
i
(
*
j
quarter
)
)
(
byte
sym
)
)
(
aset
states
j
state'
)
(
aset
last-syms
j
sym
)
)
)
)
(
dotimes
[
i
(
-
n-out
truncated
)
]
(
let
[
state
(
aget
states
3
)
f
(
bit-and
state
0xfff
)
last-sym
(
aget
last-syms
3
)
^
ints
cfreq
(
aget
cum-freqs
last-sym
)
sym
(
bit-and
(
aget
^
bytes
(
aget
tables
last-sym
)
f
)
0xff
)
state'
(
->>
state
(
advance-step
(
aget
cfreq
sym
)
(
aget
^
ints
(
aget
freqs
last-sym
)
sym
)
)
(
renormalize-state
bb
)
)
]
(
aset
out
(
+
i
truncated
)
(
byte
sym
)
)
(
aset
states
3
state'
)
(
aset
last-syms
3
sym
)
)
)
out
)
)