text stringlengths 0 234 |
|---|
El := B (256); |
else |
El := B_Max; |
end if; |
-- Generate counts for each bit length |
for K in B'Range loop |
if B (K) > B_Max then |
-- m := 0; -- GNAT 2005 doesn't like it (warning). |
raise Huft_Error; |
end if; |
Count (B (K)) := Count (B (K)) + 1; |
end loop; |
if Count (0) = B'Length then |
M := 0; |
Huft_Incomplete := False; -- Spotted by Tucker Taft, 19-Aug-2004 |
return; -- Complete |
end if; |
-- Find minimum and maximum length, bound m by those |
J := 1; |
while J <= B_Max and then Count (J) = 0 loop |
J := J + 1; |
end loop; |
Kcc := J; |
if M < J then |
M := J; |
end if; |
I := B_Max; |
while I > 0 and then Count (I) = 0 loop |
I := I - 1; |
end loop; |
G := I; |
if M > I then |
M := I; |
end if; |
-- Adjust last length count to fill out codes, if needed |
Y := Integer (Shift_Left (Unsigned_32'(1), J)); -- y:= 2 ** j; |
while J < I loop |
Y := Y - Count (J); |
if Y < 0 then |
raise Huft_Error; |
end if; |
Y := Y * 2; |
J := J + 1; |
end loop; |
Y := Y - Count (I); |
if Y < 0 then |
raise Huft_Error; |
end if; |
Count (I) := Count (I) + Y; |
-- Generate starting offsets into the value table for each length |
Offset (1) := 0; |
J := 0; |
for Idx in 2 .. I loop |
J := J + Count (Idx - 1); |
Offset (Idx) := J; |
end loop; |
-- Make table of values in order of bit length |
for Idx in B'Range loop |
J := B (Idx); |
if J /= 0 then |
V (Offset (J)) := Idx - B'First; |
Offset (J) := Offset (J) + 1; |
end if; |
end loop; |
-- Generate huffman codes and for each, make the table entries |
Code_Stack (0) := 0; |
I := 0; |
V_Idx := V'First; |
Bits (-1) := 0; |
-- Go through the bit lengths (kcc already is bits in shortest code) |
for K in Kcc .. G loop |
for Am1 in reverse 0 .. Count (K) - 1 loop -- A counts codes of length k |
-- Here i is the huffman code of length k bits for value v(v_idx) |
while K > W + Bits (Table_Level) loop |
W := W + Bits (Table_Level); -- Length of tables to this position |
Table_Level := Table_Level + 1; |
Z := G - W; -- Compute min size table <= m bits |
if Z > M then |
Z := M; |
end if; |
J := K - W; |
F := Integer (Shift_Left (Unsigned_32'(1), J)); -- f:= 2 ** j; |
if F > Am1 + 2 then |
-- Try a k-w bit table |
F := F - (Am1 + 2); |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.