summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJed Barber <jjbarber@y7mail.com>2020-04-23 23:23:44 +1000
committerJed Barber <jjbarber@y7mail.com>2020-04-23 23:23:44 +1000
commit46010b309ea6be1c233779a90df0e39e98240118 (patch)
tree66ff9ed26b288035d29722a7242db18d722be9c0
parent5db1a71fb365cf12e4e41e334e22a2e5a1205371 (diff)
Private portion of spec done except for Iterators and Pragmas
-rw-r--r--design_notes.txt4
-rw-r--r--src/ada-containers-directed_graphs.ads204
2 files changed, 206 insertions, 2 deletions
diff --git a/design_notes.txt b/design_notes.txt
index 700ed9d..9004090 100644
--- a/design_notes.txt
+++ b/design_notes.txt
@@ -99,6 +99,10 @@ List of Graph funcs:
Iterate
Iterate_Subgraph
+ First
+ Last
+ Next
+ Previous
diff --git a/src/ada-containers-directed_graphs.ads b/src/ada-containers-directed_graphs.ads
index e383c0c..cc1c39c 100644
--- a/src/ada-containers-directed_graphs.ads
+++ b/src/ada-containers-directed_graphs.ads
@@ -8,8 +8,9 @@ private with
Ada.Containers.Helpers,
Ada.Finalization,
- Ada.Streams;
- -- maps? sets?
+ Ada.Streams,
+ Ada.Containers.Hashed_Maps,
+ Ada.Containers.Vectors;
generic
@@ -20,6 +21,14 @@ generic
type Node_Label_Type is private;
type Edge_Label_Type is private;
+ with function "="
+ (Left, Right : in Node_Label_Type)
+ return Boolean is <>;
+
+ with function "="
+ (Left, Right : in Edge_Label_Type)
+ return Boolean is <>;
+
package Ada.Containers.Directed_Graphs is
@@ -532,10 +541,201 @@ package Ada.Containers.Directed_Graphs is
Position : in Cursor)
return Graph_Iterator_Interfaces.Forward_Iterator'Class;
+ function First
+ (Container : in Graph)
+ return Cursor;
+
+ function Last
+ (Container : in Graph)
+ return Cursor;
+
+ function Next
+ (Position : in Cursor)
+ return Cursor;
+
+ procedure Next
+ (Position : in out Cursor);
+
+ function Previous
+ (Position : in Cursor)
+ return Cursor;
+
+ procedure Previous
+ (Position : in out Cursor);
+
private
+ -- Put Inline Pragmas here
+
+
+
+
+ package Impl is new Helpers.Generic_Implementation;
+
+ package Node_Vectors is new Vectors
+ (Index_Type => Positive,
+ Element_Type => Node_Type);
+
+ function To_Hash
+ (Node : in Node_Type)
+ return Hash_Type;
+
+ function To_Hash
+ (Edge : in Edge_Type)
+ return Hash_Type;
+
+ package Node_Maps is new Hashed_Maps
+ (Key_Type => Node_Type,
+ Element_Type => Node_Vectors.Vector,
+ Hash => To_Hash,
+ Equivalent_Keys => "=",
+ "=" => Node_Vectors."=");
+
+ package Node_Label_Maps is new Hashed_Maps
+ (Key_Type => Node_Type,
+ Element_Type => Node_Label_Type,
+ Hash => To_Hash,
+ Equivalent_Keys => "=",
+ "=" => "=");
+
+ package Edge_Label_Maps is new Hashed_Maps
+ (Key_Type => Edge_Type,
+ Element_Type => Edge_Label_Type,
+ Hash => To_Hash,
+ Equivalent_Keys => "=",
+ "=" => "=");
+
+
+
+
+ type Graph is new Ada.Finalization.Controlled with record
+ Connections : Node_Maps.Map;
+ Node_Labels : Node_Label_Maps.Map;
+ Edge_Labels : Edge_Label_Maps.Map;
+ Tamper_Info : aliased Helpers.Tamper_Counts;
+ end record;
+
+ overriding procedure Adjust
+ (Container : in out Graph);
+
+ overriding procedure Finalize
+ (Container : in out Graph);
+
+ procedure Write
+ (Stream : not null access Streams.Root_Stream_Type'Class;
+ Container : in Graph);
+ for Graph'Write use Write;
+
+ procedure Read
+ (Stream : not null access Streams.Root_Stream_Type'Class;
+ Container : out Graph);
+ for Graph'Read use Read;
+
+ type Graph_Access is access all Graph;
+
+ Empty_Graph : constant Graph := (Ada.Finalization.Controlled with others => <>);
+
+
+
+
+ type Cursor is record
+ Container : Graph_Access;
+ Node : Node_Type := Node_Type'First;
+ end record;
+
+ procedure Write
+ (Stream : not null access Streams.Root_Stream_Type'Class;
+ Position : in Cursor);
+ for Cursor'Write use Write;
+
+ procedure Read
+ (Stream : not null access Streams.Root_Stream_Type'Class;
+ Position : out Cursor);
+ for Cursor'Read use Read;
+
+ No_Element : constant Cursor := Cursor'(null, Node_Type'First);
+
+
+
+
+ subtype Reference_Control_Type is Impl.Reference_Control_Type;
+
+ type Node_Label_Constant_Reference
+ (Element : not null access constant Node_Label_Type) is
+ record
+ Control : Reference_Control_Type :=
+ raise Program_Error with "uninitialized reference";
+ end record;
+
+ procedure Write
+ (Stream : not null access Streams.Root_Stream_Type'Class;
+ Item : in Node_Label_Constant_Reference);
+ for Node_Label_Constant_Reference'Write use Write;
+
+ procedure Read
+ (Stream : not null access Streams.Root_Stream_Type'Class;
+ Item : out Node_Label_Constant_Reference);
+ for Node_Label_Constant_Reference'Read use Read;
+
+ type Node_Label_Reference
+ (Element : not null access Node_Label_Type) is
+ record
+ Control : Reference_Control_Type :=
+ raise Program_Error with "uninitialized reference";
+ end record;
+
+ procedure Write
+ (Stream : not null access Streams.Root_Stream_Type'Class;
+ Item : in Node_Label_Reference);
+ for Node_Label_Reference'Write use Write;
+
+ procedure Read
+ (Stream : not null access Streams.Root_Stream_Type'Class;
+ Item : out Node_Label_Reference);
+ for Node_Label_Reference'Read use Read;
+
+ type Edge_Label_Constant_Reference
+ (Element : not null access constant Edge_Label_Type) is
+ record
+ Control : Reference_Control_Type :=
+ raise Program_Error with "uninitialized reference";
+ end record;
+
+ procedure Write
+ (Stream : not null access Streams.Root_Stream_Type'Class;
+ Item : in Edge_Label_Constant_Reference);
+ for Edge_Label_Constant_Reference'Write use Write;
+
+ procedure Read
+ (Stream : not null access Streams.Root_Stream_Type'Class;
+ Item : out Edge_Label_Constant_Reference);
+ for Edge_Label_Constant_Reference'Read use Read;
+
+ type Edge_Label_Reference
+ (Element : not null access Edge_Label_Type) is
+ record
+ Control : Reference_Control_Type :=
+ raise Program_Error with "uninitialized reference";
+ end record;
+
+ procedure Write
+ (Stream : not null access Streams.Root_Stream_Type'Class;
+ Item : in Edge_Label_Reference);
+ for Edge_Label_Reference'Write use Write;
+
+ procedure Read
+ (Stream : not null access Streams.Root_Stream_Type'Class;
+ Item : out Edge_Label_Reference);
+ for Edge_Label_Reference'Read use Read;
+
+
+
+
+ -- Define Iterators for general iteration and subgraph iteration here
+
+
end Ada.Containers.Directed_Graphs;