text stringlengths 0 234 |
|---|
C_Idx := K; |
-- Try smaller tables up to z bits |
loop |
J := J + 1; |
exit when J >= Z; |
F := F * 2; |
C_Idx := C_Idx + 1; |
exit when F - Count (C_Idx) <= 0; |
F := F - Count (C_Idx); |
end loop; |
end if; |
if W + J > El and then W < El then |
J := El - W; -- Make EOB code end at table |
end if; |
if W = 0 then |
J := M; -- Fix: main table always m bits! |
end if; |
Z := Integer (Shift_Left (Unsigned_32'(1), J)); -- z:= 2 ** j; |
Bits (Table_Level) := J; |
-- Allocate and link new table |
begin |
Current_Table_Ptr := new Huft_Table (0 .. Z); |
New_Node_Ptr := new Table_List'(Current_Table_Ptr, null); |
exception |
when Storage_Error => |
raise Huft_Out_Of_Memory; |
Function Definition: procedure Dispose is new Ada.Unchecked_Deallocation (Dir_Node, P_Dir_Node); |
Function Body: procedure Dispose is new Ada.Unchecked_Deallocation (String, P_String); |
package Binary_Tree_Rebalancing is |
procedure Rebalance (Root : in out P_Dir_Node); |
end Binary_Tree_Rebalancing; |
package body Binary_Tree_Rebalancing is |
------------------------------------------------------------------- |
-- Tree Rebalancing in Optimal Time and Space -- |
-- QUENTIN F. STOUT and BETTE L. WARREN -- |
-- Communications of the ACM September 1986 Volume 29 Number 9 -- |
------------------------------------------------------------------- |
-- http://www.eecs.umich.edu/~qstout/pap/CACM86.pdf |
-- |
-- Translated by (New) P2Ada v. 15-Nov-2006 |
procedure Tree_To_Vine (Root : P_Dir_Node; Size : out Integer) is |
-- Transform the tree with pseudo-root "root^" into a vine with |
-- pseudo-root node "root^", and store the number of nodes in "size" |
Vine_Tail, Remainder, Temp : P_Dir_Node; |
begin |
Vine_Tail := Root; |
Remainder := Vine_Tail.Right; |
Size := 0; |
while Remainder /= null loop |
if Remainder.Left = null then |
-- Move vine-tail down one: |
Vine_Tail := Remainder; |
Remainder := Remainder.Right; |
Size := Size + 1; |
else |
-- Rotate: |
Temp := Remainder.Left; |
Remainder.Left := Temp.Right; |
Temp.Right := Remainder; |
Remainder := Temp; |
Vine_Tail.Right := Temp; |
end if; |
end loop; |
end Tree_To_Vine; |
procedure Vine_To_Tree (Root : P_Dir_Node; Size_Given : Integer) is |
-- Convert the vine with "size" nodes and pseudo-root |
-- node "root^" into a balanced tree |
Leaf_Count : Integer; |
Size : Integer := Size_Given; |
procedure Compression (Root_Compress : P_Dir_Node; Count : Integer) is |
-- Compress "count" spine nodes in the tree with pseudo-root "root_compress^" |
Scanner, Child : P_Dir_Node; |
begin |
Scanner := Root_Compress; |
for Counter in reverse 1 .. Count loop |
Child := Scanner.Right; |
Scanner.Right := Child.Right; |
Scanner := Scanner.Right; |
Child.Right := Scanner.Left; |
Scanner.Left := Child; |
end loop; |
end Compression; |
-- Returns n - 2 ** Integer( Float'Floor( log( Float(n) ) / log(2.0) ) ) |
-- without Float-Point calculation and rounding errors with too short floats |
function Remove_Leading_Binary_1 (N : Integer) return Integer is |
X : Integer := 2**16; -- supposed maximum |
begin |
if N < 1 then |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.