text
stringlengths
0
234
File : File_Type;
Start_Time, End_Time : CPU_Time;
Execution_Duration : Time_Span;
Result : Natural := Natural'First;
X_Min, X_Max,
Y_Min, Y_Max : Integer;
begin
Get_File (File);
-- Get all values
declare
procedure Split_Range (Str : String; Lower, Upper : out Integer);
procedure Split_Range (Str : String; Lower, Upper : out Integer) is
use Ada.Integer_Text_IO;
Pattern : constant String := "..";
Separator_Index : constant Natural :=
Ada.Strings.Fixed.Index (Source => Str, Pattern => Pattern);
Left_Str : constant String := Str (Str'First .. Separator_Index - 1);
Right_Str : constant String := Str (Separator_Index + Pattern'Length .. Str'Last);
Last : Positive;
begin
Get (Left_Str, Lower, Last);
Get (Right_Str, Upper, Last);
end Split_Range;
Str : constant String := Get_Line (File);
Pattern : constant String := ",";
Separator_Index : constant Natural :=
Ada.Strings.Fixed.Index (Source => Str (1 .. Str'Last), Pattern => Pattern);
Left_Str : constant String := Str (16 .. Separator_Index - 1);
Right_Str : constant String := Str (Separator_Index + Pattern'Length + 3 .. Str'Last);
begin
Split_Range (Left_Str, X_Min, X_Max);
Split_Range (Right_Str, Y_Min, Y_Max);
Function Definition: procedure Main is
Function Body: use Ada.Containers, Ada.Text_IO;
use Utils;
type Binary_Rate is record
Zero : Natural;
One : Natural;
end record;
type Binary is mod 2;
package Binary_Rate_Vectors is new Ada.Containers.Vectors (Natural, Binary_Rate);
use Binary_Rate_Vectors;
File : File_Type;
Gamma : Vector := Empty_Vector;
Epsilon : Vector := Empty_Vector;
begin
Get_File (File);
-- Get all values
while not End_Of_File (File) loop
declare
procedure Process (Vec : out Vector; Index : Natural; Bit : Binary);
procedure Process (Vec : out Vector; Index : Natural; Bit : Binary) is
begin
if Count_Type (Index) > Vec.Length then
Vec.Append (New_Item => (Zero => (if Bit = 0 then 1 else 0), One => Natural (Bit)));
else
declare
Temp_Rate : Binary_Rate := Vec.Element (Index - 1);
begin
if Bit = 0 then
Temp_Rate.Zero := Temp_Rate.Zero + 1;
else
Temp_Rate.One := Temp_Rate.One + 1;
end if;
Vec.Replace_Element (Index - 1, Temp_Rate);
Function Definition: procedure Main is
Function Body: use Ada.Containers, Ada.Strings.Unbounded, Ada.Text_IO;
use Utils;
subtype Binary_Values is Natural range 0 .. 1;
package Unbounded_String_Vectors is new Ada.Containers.Vectors (Natural, Unbounded_String);
use Unbounded_String_Vectors;
package Unbounded_String_Cursor_Vectors is new Ada.Containers.Vectors (Natural, Cursor);
type Rate_Arrays is array (Binary_Values'Range) of Natural;
type Binary_Maps is array (Binary_Values'Range) of Unbounded_String_Cursor_Vectors.Vector;
type Strategies is (Most_Common, Least_Common);
-- Given a String which represents a Natural in binary format, it returns the corresponding Natural.
-- @param Str A String which represents a Natural in binary format
-- @retuns Returns the corresponding Natural