text stringlengths 0 234 |
|---|
type Folding_T is record |
Kind : Folding_Kind; |
Value : Natural; |
end record; |
package Folding_Vectors is new Ada.Containers.Vectors (Natural, Folding_T); |
-- This Hash function transform a 2 dimensional location to an unique ID using Cantor pairing enumeration. |
-- @param Coord A 2 dimensional location |
-- @returns Return the corresponding hash |
-- @link https://en.wikipedia.org/wiki/Pairing_function#Cantor_pairing_function |
function Hash (Coord : Coordinate_2D) return Ada.Containers.Hash_Type is |
(Ada.Containers.Hash_Type (((Coord.Line + Coord.Column) * (Coord.Line + Coord.Column + 1) / 2) + Coord.Column)); |
function Equivalent_Keys (Left, Right : Coordinate_2D) return Boolean is |
(Left.Line = Right.Line and Left.Column = Right.Column); |
package Dots_Maps is new Ada.Containers.Hashed_Maps (Key_Type => Coordinate_2D, |
Element_Type => Boolean, |
Hash => Hash, |
Equivalent_Keys => Equivalent_Keys, |
"=" => "="); |
File : File_Type; |
Start_Time, End_Time : CPU_Time; |
Execution_Duration : Time_Span; |
File_Is_Empty : Boolean := True; |
Max_Lines, Max_Columns : Positive := Positive'First; |
Folding_Instructions : Folding_Vectors.Vector := Folding_Vectors.Empty_Vector; |
Dots_Map : Dots_Maps.Map := Dots_Maps.Empty_Map; |
begin |
Get_File (File); |
-- Get all values |
begin |
while not End_Of_File (File) loop |
declare |
Str : constant String := Get_Line (File); |
begin |
if Str'Length = 0 then |
goto Continue_Next_Line; |
end if; |
if Str (Str'First) = 'f' then |
-- "fold along" instruction |
declare |
use Ada.Integer_Text_IO; |
Separator_Index : constant Integer := |
Ada.Strings.Fixed.Index (Source => Str (1 .. Str'Last), Pattern => "="); |
Kind : constant String := Str (Separator_Index - 1 .. Separator_Index - 1); |
Value_Str : constant String := Str (Separator_Index + 1 .. Str'Last); |
Last_Index : Positive := Positive'First; |
Value : Natural; |
begin |
Get (Value_Str, Value, Last_Index); |
Folding_Instructions.Append (((if Kind = "x" then K_Column else K_Line), Value)); |
Function Definition: procedure Main is |
Function Body: use Ada.Containers, |
Ada.Execution_Time, |
Ada.Real_Time, |
Ada.Text_IO; |
use Utils; |
type Coordinate_2D is record |
Line : Natural; |
Column : Natural; |
end record; |
type Segment is record |
Start_Line : Coordinate_2D; |
End_Line : Coordinate_2D; |
end record; |
package Segment_Vectors is new Ada.Containers.Vectors (Natural, Segment); |
use Segment_Vectors; |
File : File_Type; |
Start_Time, End_Time : CPU_Time; |
Execution_Duration : Time_Span; |
Segments : Vector := Empty_Vector; |
Max_Lines, Max_Columns : Positive := Positive'First; |
Nb_Dangerous_Cells : Natural := Natural'First; |
begin |
Get_File (File); |
if End_Of_File (File) then |
raise Program_Error with "Empty file"; |
end if; |
-- Get all segments |
while not End_Of_File (File) loop |
declare |
use Ada.Integer_Text_IO; |
Line : constant String := Get_Line (File); |
First : Positive := Line'First; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.