summaryrefslogtreecommitdiff
path: root/src/directed_graphs.adb
diff options
context:
space:
mode:
authorJed Barber <jjbarber@y7mail.com>2020-05-23 15:31:27 +1000
committerJed Barber <jjbarber@y7mail.com>2020-05-23 15:31:27 +1000
commit7f56d08907ffdd192f4b4898bfb22c1dce8f1cd0 (patch)
tree791bc8ca10d1f23226aafca9fd24c8c7612a1a02 /src/directed_graphs.adb
parent5bb4bfd85fb558380a8b06ac77d0e5b27aee1feb (diff)
Added Iterate_By function for custom iteration
Diffstat (limited to 'src/directed_graphs.adb')
-rw-r--r--src/directed_graphs.adb66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/directed_graphs.adb b/src/directed_graphs.adb
index 12916d1..bacb040 100644
--- a/src/directed_graphs.adb
+++ b/src/directed_graphs.adb
@@ -1019,6 +1019,12 @@ package body Directed_Graphs is
Impl.Unbusy (Object.Container.Tamper_Info);
end Finalize;
+ procedure Finalize
+ (Object : in out By_Iterator) is
+ begin
+ Impl.Unbusy (Object.Container.Tamper_Info);
+ end Finalize;
+
@@ -1163,6 +1169,17 @@ package body Directed_Graphs is
end if;
end First;
+ function First
+ (Object : in By_Iterator)
+ return Cursor is
+ begin
+ if Object.Filter = null or else Object.Filter (Object.Start) then
+ return Object.Start;
+ else
+ return Next (Object, Object.Start);
+ end if;
+ end First;
+
@@ -1628,6 +1645,40 @@ package body Directed_Graphs is
+ ----------------
+ -- Iterate_By --
+ ----------------
+
+ function Iterate_By
+ (Container : in Graph;
+ Start : in Cursor;
+ Chooser : in Choice_Function;
+ Filter : in Filter_Function := null)
+ return Graph_Iterator_Interfaces.Forward_Iterator'Class is
+ begin
+ if Impl.Checks then
+ if Start.Container /= Container'Unrestricted_Access then
+ raise Constraint_Error with "Cursor points to different graph";
+ end if;
+ if not Has_Element (Start) then
+ raise Constraint_Error with "Start Cursor points to nothing";
+ end if;
+ if Chooser = null then
+ raise Constraint_Error with "No choice function supplied";
+ end if;
+ end if;
+ return It : By_Iterator do
+ It.Container := Container'Unrestricted_Access;
+ It.Start := Start;
+ It.Chooser := Chooser;
+ It.Filter := Filter;
+ Impl.Busy (Container.Tamper_Info'Unrestricted_Access.all);
+ end return;
+ end Iterate_By;
+
+
+
+
----------------------
-- Iterate_Subgraph --
----------------------
@@ -2010,6 +2061,21 @@ package body Directed_Graphs is
end if;
end Next;
+ function Next
+ (Object : in By_Iterator;
+ Position : in Cursor)
+ return Cursor
+ is
+ Result : Cursor := Position;
+ begin
+ loop
+ Result := Object.Chooser (Result);
+ if Object.Filter = null or else Object.Filter (Result) then
+ return Result;
+ end if;
+ end loop;
+ end Next;
+