agpl_1.0.0_b5da3320/src/agpl-containers-indefinite_matrix2d.ads

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
private with Ada.Containers.Indefinite_Ordered_Maps;
with Ada.Containers.Indefinite_Vectors;

generic
   type Index (<>) is private;
   type Value (<>) is private;
   with function "<" (L, R : Index) return Boolean is <>;
package Agpl.Containers.Indefinite_Matrix2d is

   --  This is a sparse 2D matrix
   --  Care has been taken to make this type as efficient as possible given
   --  the Ada.Containers it internally uses.
   --  This type is *not* thread-safe.

   pragma Preelaborate;

   package Index_Vectors is new Ada.Containers.Indefinite_Vectors
     (Positive, Index);

   subtype Index_Vector is Index_Vectors.Vector;

   type Matrix is tagged private;

   function Contains (This : Matrix; R, C : Index) return Boolean;

   function Get (This : Matrix; R, C : Index) return Value;

   procedure Get (This : Matrix; R, C : Index; V : out Value; Found : out Boolean);
   --  If found, V will be valid

   procedure Set (This : in out Matrix; R, C : Index; V : Value);

   function Row_Indexes (This : Matrix) return Index_Vector;
   --  O(n)



   function Column_Indexes (This : Matrix) return Index_Vector;
   --  All found in all rows
   --  O(n**2)

private

   package Index_Value_Maps is new
     Ada.Containers.Indefinite_Ordered_Maps (Index, Value);

   use type Index_Value_Maps.Map;

   package Index_Index_Value_Maps is new
     Ada.Containers.Indefinite_Ordered_Maps (Index, Index_Value_Maps.Map);

   type Matrix is new Index_Index_Value_Maps.Map with null record;

end Agpl.Containers.Indefinite_Matrix2d;