text stringlengths 0 234 |
|---|
function Binary_String_To_Number (Str : String) return Natural; |
function Binary_String_To_Number (Str : String) return Natural |
is |
Exponent : Natural := Natural'First; |
Result : Natural := Natural'First; |
begin |
for Elt of reverse Str loop |
if Elt = '1' then |
Result := Result + 2 ** Exponent; |
end if; |
Exponent := Exponent + 1; |
end loop; |
return Result; |
end Binary_String_To_Number; |
-- Find the result in a set of String which represents a Natural in binary format according to criteria. |
-- @param Values Contains all values (String which represents a Natural in binary format) extracted from a file. |
-- @param Rate Indicate how many 0s and 1s there are at index "Index". |
-- @param Map An array (Called Map because each index corresponds to a filter) that contains for each index (0 and |
-- 1) each values of Values that contain a 0 (for index 0 of Map) or a 1 (for index 1 of Map) at index "Index" in |
-- the the value in Values. |
-- @param Index This index denote the position in the binary string representation of a Natural. |
-- @param Strategy The strategy to apply (Most Common, Least Common). |
-- @retuns Return the value that match the criteria (Strategy) |
function Find_Value_According_To_Criteria (Values : Vector; |
Rate : Rate_Arrays; |
Map : Binary_Maps; |
Index : in out Positive; |
Strategy : Strategies) |
return Natural; |
function Find_Value_According_To_Criteria (Values : Vector; |
Rate : Rate_Arrays; |
Map : Binary_Maps; |
Index : in out Positive; |
Strategy : Strategies) |
return Natural |
is |
-- Filter the result for the next recursive call of Find_Value_According_To_Criteria. |
-- @param Previous_Filtered_Values List of Cursor (pointing to value in Values) that match the previous |
-- criteria. |
-- @param Rate Indicate how many 0s and 1s there are at index "Index". |
-- @param Map An array (Called Map because each index corresponds to a filter) that contains for each index (0 |
-- and 1) each values of Values that contain a 0 (for index 0 of Map) or a 1 (for index 1 of Map) at index |
-- "Index" in the the value in Values. |
procedure Filter (Previous_Filtered_Values : Unbounded_String_Cursor_Vectors.Vector; |
Rate : in out Rate_Arrays; |
Map : in out Binary_Maps); |
procedure Filter (Previous_Filtered_Values : Unbounded_String_Cursor_Vectors.Vector; |
Rate : in out Rate_Arrays; |
Map : in out Binary_Maps) |
is |
Current_Value : Unbounded_String; |
Binary_Value : Binary_Values; |
begin |
for Curs : Cursor of Previous_Filtered_Values loop |
Current_Value := Element (Curs); |
declare |
Str : constant String := To_String (Current_Value); |
begin |
Binary_Value := Binary_Values'Value (Str (Index .. Index)); |
Map (Binary_Value).Append (Curs); |
Rate (Binary_Value) := Rate (Binary_Value) + 1; |
Function Definition: procedure Main is |
Function Body: use Ada.Execution_Time, |
Ada.Real_Time, |
Ada.Text_IO; |
use Utils; |
Nb_Tiles : constant := 1; |
subtype Risk_Level is Natural range 1 .. 9; |
type Location is record |
Line : Natural; |
Column : Natural; |
end record; |
subtype Adjacent_Index is Integer range -1 .. 1; |
type Adjacent_Location is record |
Line : Adjacent_Index; |
Column : Adjacent_Index; |
end record; |
type Adjacent is (Top, Right, Bottom, Left); |
type Adjacent_Array is array (Adjacent) of Adjacent_Location; |
-- This Hash function transform a 2 dimensional location to an unique ID using Cantor pairing enumeration. |
-- @param Loc A 2 dimensional location |
-- @returns Return the corresponding hash |
-- @link https://en.wikipedia.org/wiki/Pairing_function#Cantor_pairing_function |
function Hash (Loc : Location) return Ada.Containers.Hash_Type is |
(Ada.Containers.Hash_Type (((Loc.Line + Loc.Column) * (Loc.Line + Loc.Column + 1) / 2) + Loc.Column)); |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.