小编jfo*_*kes的帖子

如何为向量创建整数的散列映射?

我正在学习Ada(通过尝试https://adventofcode.com/2018/问题).

我有一个向量ActivityVectorActivityRecord记录:

type ActivityRecord is 
record
   dt: Ada.Calendar.Time;
   str: UStr.Unbounded_String;
end record;

package ActivityVector is new Ada.Containers.Vectors
   (Element_Type => ActivityRecord,
   Index_Type => Natural);
Run Code Online (Sandbox Code Playgroud)

我想把它们放在键盘的地图上Integer.我有以下内容:

function IntegerHash(i: Integer) return Ada.Containers.Hash_Type;

package ActivityMap is new Ada.Containers.Indefinite_Hashed_Maps(
   Key_Type => Integer,
   Element_Type => Activity.ActivityVector.Vector,
   Hash => IntegerHash,
   Equivalent_Keys => "="
);
Run Code Online (Sandbox Code Playgroud)

当我尝试编译时,我得到:

act_map.ads:9:04: instantiation error at a-cihama.ads:46
act_map.ads:9:04: no visible subprogram matches the specification for "="
act_map.ads:9:04: instantiation error at a-cihama.ads:46
act_map.ads:9:04: default "=" on "Vector" …
Run Code Online (Sandbox Code Playgroud)

ada

4
推荐指数
1
解决办法
107
查看次数

如何在Ada中动态创建固定大小的数组?

作为学习Ada的一部分,我正在处理一些基本的编码挑战。我遇到了一种情况,我想创建一个固定大小的2D整数数组(大小在运行时确定)。我的想法是要有一个小的实用程序函数,该函数可以传递数组的大小,创建它,填充它并返回它以便在其他函数中使用。

我该怎么做呢?我看到的其他答案将创建的数组保留在function-scope中,并且不返回它。

到目前为止,这是我的主要过程:

with Ada.Integer_Text_IO;
with Ada.Text_IO;

with Coord;
with Grid;

procedure test is

   boundary : Coord.Box;

   -- This is the array I want to create and fill
   -- Note sure about what I put here for the "initial" size
   new_grid : Grid.GridType (0 .. 1,  0 .. 1);

begin

   --  This is just for the example, actually these
   --  values are calculated from values in a text file 
   Ada.Text_IO.Put ("X Min?");
   Ada.Integer_Text_IO.Get (boundary.min.x);
   Ada.Text_IO.Put ("X Max?");
   Ada.Integer_Text_IO.Get (boundary.max.x);
   Ada.Text_IO.Put …
Run Code Online (Sandbox Code Playgroud)

ada

1
推荐指数
1
解决办法
137
查看次数

标签 统计

ada ×2