-
Notifications
You must be signed in to change notification settings - Fork 3
/
generic_directed_graph.adb
911 lines (867 loc) · 29.5 KB
/
generic_directed_graph.adb
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
-- --
-- package Copyright (c) Dmitry A. Kazakov --
-- Generic_Directed_Graph Luebeck --
-- Implementation Winter, 2009 --
-- --
-- Last revision : 22:45 07 Apr 2016 --
-- --
-- This library is free software; you can redistribute it and/or --
-- modify it under the terms of the GNU General Public License as --
-- published by the Free Software Foundation; either version 2 of --
-- the License, or (at your option) any later version. This library --
-- is distributed in the hope that it will be useful, but WITHOUT --
-- ANY WARRANTY; without even the implied warranty of --
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU --
-- General Public License for more details. You should have --
-- received a copy of the GNU General Public License along with --
-- this library; if not, write to the Free Software Foundation, --
-- Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. --
-- --
-- As a special exception, if other files instantiate generics from --
-- this unit, or you link this unit with other files to produce an --
-- executable, this unit does not by itself cause the resulting --
-- executable to be covered by the GNU General Public License. This --
-- exception does not however invalidate any other reasons why the --
-- executable file might be covered by the GNU Public License. --
--____________________________________________________________________--
with Ada.Numerics; use Ada.Numerics;
with Ada.Unchecked_Conversion;
package body Generic_Directed_Graph is
use Node_Arrays;
use Node_Address_Sets;
use Node_Sets;
Offset : Storage_Offset := -1; -- Offset to the object's dope
Blocks : Address := Null_Address;
--
-- Deref -- Node to its address conversion
--
function Deref (Item : Node) return Address;
type Nodes_Set (Size : Natural) is limited record
Last : Natural;
List : Nodes_Array (1..Size);
end record;
type Nodes_Set_Ptr is access Nodes_Set;
for Nodes_Set_Ptr'Storage_Pool use Pool;
procedure Free is
new Ada.Unchecked_Deallocation (Nodes_Set, Nodes_Set_Ptr);
--
-- Add -- Node into a set
--
procedure Add
( Set : in out Address;
Item : Node;
Minimal_Size : Positive
);
procedure Add
( Set : in out Nodes_Set_Ptr;
Item : Node;
Minimal_Size : Positive
);
pragma Inline (Add);
--
-- Find -- Binary search for a node
--
-- Vector - The nodes array
-- Size - Of the array
-- Item - To search for
--
-- Returns :
--
-- Node postion if found, negated would be position if not found
--
function Find
( Vector : Nodes_Array;
Size : Positive;
Item : Node
) return Integer;
--
-- Find -- Location
--
function Find (Set : Nodes_Set_Ptr; Item : Node) return Natural;
--
-- Is_In -- Membership test
--
function Is_In (Set : Nodes_Set; Item : Node) return Boolean;
function Is_In (Set : Nodes_Set_Ptr; Item : Node) return Boolean;
pragma Inline (Is_In);
--
-- Remove -- Node from a set
--
procedure Remove (Set : Nodes_Set_Ptr; Item : Node);
procedure Remove (Set : Address; Item : Node);
pragma Inline (Remove);
type Node_Header is limited record
Parents : Address;
Children : Address;
end record;
type Node_Header_Ptr is access all Node_Header;
Header_Size : constant Storage_Offset :=
Node_Header'Max_Size_In_Storage_Elements;
function Header is
new Ada.Unchecked_Conversion (Address, Node_Header_Ptr);
function Nodes is
new Ada.Unchecked_Conversion (Address, Nodes_Set_Ptr);
procedure Add
( Set : in out Nodes_Set_Ptr;
Item : Node;
Minimal_Size : Positive
) is
begin
if Set = null then
Set := new Nodes_Set (Minimal_Size);
Set.Last := 1;
Set.List (1) := Item;
elsif Set.Last = 0 then
Set.Last := 1;
Set.List (1) := Item;
else
declare
Location : Integer := Find (Set.List, Set.Last, Item);
begin
if Location < 0 then
Location := -Location;
if Set.Size = Set.Last then
declare
Ptr : constant Nodes_Set_Ptr :=
new Nodes_Set
( Set.Size
+ Natural'Max
( Minimal_Size,
( ( Set.Size
* (100 + Increment)
)
/ 100
) ) );
begin
Ptr.List (1..Location - 1) :=
Set.List (1..Location - 1);
Ptr.List (Location + 1..Set.Size + 1) :=
Set.List (Location..Set.Size);
Free (Set);
Set := Ptr;
end;
else
Set.List (Location + 1..Set.Last + 1) :=
Set.List (Location..Set.Last);
end if;
Set.List (Location) := Item;
Set.Last := Set.Last + 1;
elsif Set.List (Location) /= Item then
raise Argument_Error;
end if;
end;
end if;
end Add;
procedure Add
( Set : in out Address;
Item : Node;
Minimal_Size : Positive
) is
This : Nodes_Set_Ptr := Nodes (Set);
begin
Add (This, Item, Minimal_Size);
Set := This.all'Address;
end Add;
procedure Allocate
( Pool : in out Node_Storage_Pool;
Storage_Address : out Address;
Size : Storage_Count;
Alignment : Storage_Count
) is
Header_Alignment : constant Storage_Count :=
Storage_Count'Max (Node_Header'Alignment, Alignment);
Header_Offset : constant Storage_Offset :=
Header_Size + (-Header_Size) mod Header_Alignment;
begin
Allocate
( Pool.Host.all,
Storage_Address,
Size + Header_Offset,
Header_Alignment
);
declare
This : Node_Header renames Header (Storage_Address).all;
begin
This.Parents := Null_Address;
This.Children := Null_Address;
if Offset < 0 then
--
-- The offset to the object address according to the
-- attribute X'Address is unknown. For this reason the block
-- allocated is added to the list of allocated blocks to
-- determine the offset later.
--
if Blocks = Null_Address then
This.Parents := Storage_Address;
This.Children := Storage_Address;
Blocks := Storage_Address;
else
declare
Head : Node_Header renames Header (Blocks).all;
Tail : Node_Header renames Header (Head.Parents).all;
begin
This.Parents := Head.Parents;
This.Children := Blocks;
Tail.Children := Storage_Address;
Head.Parents := Storage_Address;
end;
end if;
end if;
end;
Storage_Address := Storage_Address + Header_Offset;
end Allocate;
procedure Connect
( Parent : Node;
Child : Node;
Acyclic : Boolean := True
) is
begin
if ( Parent = null
or else
Child = null
or else
( Acyclic
and then
( Child = Parent
or else
Is_Ancestor (Parent => Child, Child => Parent)
) ) )
then
raise Constraint_Error;
else
Add
( Header (Deref (Parent)).Children,
Child,
Minimal_Children_Size
);
begin
Add
( Header (Deref (Child)).Parents,
Parent,
Minimal_Parents_Size
);
exception
when others =>
Remove (Header (Deref (Parent)).Children, Child);
raise;
end;
end if;
end Connect;
procedure Deallocate
( Pool : in out Node_Storage_Pool;
Storage_Address : in Address;
Size : Storage_Count;
Alignment : Storage_Count
) is
Header_Alignment : constant Storage_Count :=
Storage_Count'Max (Node_Header'Alignment, Alignment);
Header_Offset : constant Storage_Offset :=
Header_Size + (-Header_Size) mod Header_Alignment;
begin
if Offset < 0 then
--
-- The node is deallocated before placement of any other nodes
-- in any graphs. It is removed from the list of allocated
-- blocks.
--
if Blocks = Null_Address then
raise Program_Error;
end if;
declare
Freed : constant Address := Storage_Address - Header_Offset;
This : Node_Header renames Header (Freed).all;
begin
if This.Parents = Freed then
Blocks := Null_Address;
else
if Blocks = Freed then
Blocks := This.Children;
end if;
Header (This.Parents).Children := This.Children;
Header (This.Children).Parents := This.Parents;
end if;
end;
else
--
-- Checking for dangling pointers. No deallocated item can be
-- in any of the lists.
--
declare
Ptr : Nodes_Set_Ptr;
This : Node_Header renames
Header (Storage_Address - Header_Offset).all;
begin
if This.Parents /= Null_Address then
Ptr := Nodes (This.Parents);
if Ptr.Last > 0 then
raise Program_Error;
end if;
Free (Ptr);
end if;
if This.Children /= Null_Address then
Ptr := Nodes (This.Children);
if Ptr.Last > 0 then
raise Program_Error;
end if;
Free (Ptr);
end if;
end;
end if;
Deallocate
( Pool.Host.all,
Storage_Address - Header_Offset,
Size + Header_Offset,
Header_Alignment
);
end Deallocate;
procedure Delete
( Vertex : in out Node;
Subgraph : Subgraph_Type := Any
) is
Visited : Node_Address_Sets.Set;
Queued : Unbounded_Array;
Current : Node := Vertex;
Count : Positive := 1;
begin
if Vertex = null then
return;
end if;
loop
Add (Visited, Current);
declare
This : Node_Header renames Header (Deref (Current)).all;
begin
if This.Parents /= Null_Address then
declare
Parents : Nodes_Set renames Nodes (This.Parents).all;
Parent : Node;
begin
for Index in 1..Parents.Last loop
Parent := Parents.List (Index);
if not Is_In (Visited, Parent) then
Remove
( Header (Deref (Parent)).Children,
Current
);
if (Subgraph and Ancestor) /= 0 then
Put (Queued, Count, Parent);
Count := Count + 1;
end if;
end if;
end loop;
Parents.Last := 0;
end;
end if;
if This.Children /= Null_Address then
declare
Children : Nodes_Set renames
Nodes (This.Children).all;
Child : Node;
begin
for Index in 1..Children.Last loop
Child := Children.List (Index);
if not Is_In (Visited, Child) then
Remove
( Header (Deref (Child)).Parents,
Current
);
if (Subgraph and Descendant) /= 0 then
Put (Queued, Count, Child);
Count := Count + 1;
end if;
end if;
end loop;
Children.Last := 0;
end;
end if;
end;
if Vertex /= Current or else (Subgraph and Self) /= 0 then
Free (Current);
end if;
exit when Count = 1;
Count := Count - 1;
Current := Get (Queued, Count);
end loop;
end Delete;
function Deref (Item : Node) return Address is
function Node_To_Address is
new Ada.Unchecked_Conversion (Node, Address);
begin
if Item = null then
raise Constraint_Error;
end if;
if Offset < 0 then
--
-- Searching for the memory block closest to the given address
-- from the left. The offset between Item and the block address
-- is the size of the dope plus the size of the header.
--
if Blocks = Null_Address then
raise Program_Error;
end if;
Offset := Storage_Offset'Last;
declare
Addr : constant Address := Node_To_Address (Item);
Current : Address := Blocks;
begin
loop
if Current < Addr then
Offset := Storage_Offset'Min (Offset, Addr - Current);
end if;
declare
This : Node_Header renames Header (Current).all;
begin
Current := This.Children;
This.Parents := Null_Address;
This.Children := Null_Address;
end;
exit when Current = Blocks;
end loop;
end;
if Offset = Storage_Offset'Last then
raise Program_Error;
end if;
end if;
return Node_To_Address (Item) - Offset;
end Deref;
procedure Disconnect (Parent : Node; Child : Node) is
This : Node_Header renames Header (Deref (Parent)).all;
That : Node_Header renames Header (Deref (Child)).all;
begin
Remove (This.Children, Child);
Remove (That.Parents, Parent);
end Disconnect;
function Find
( Vector : Nodes_Array;
Size : Positive;
Item : Node
) return Integer is
From : Natural := 0;
To : Natural := Size + 1;
This : Natural;
begin
loop
This := (From + To) / 2;
if Item = Vector (This) then
return This;
elsif Item.all'Address < Vector (This).all'Address then
if This - From <= 1 then
return -This;
end if;
To := This;
else
if To - This <= 1 then
return - This - 1;
end if;
From := This;
end if;
end loop;
end Find;
function Find (Set : Nodes_Set_Ptr; Item : Node) return Natural is
begin
if Set /= null and then Set.Last > 0 then
declare
Location : constant Integer :=
Find (Set.List, Set.Last, Item);
begin
if Location > 0 then
return Location;
end if;
end;
end if;
return 0;
end Find;
function Find_Child (Parent : Node; Child : Node) return Natural is
This : Node_Header renames Header (Deref (Parent)).all;
begin
if Child = null then
raise Constraint_Error;
elsif This.Children = Null_Address then
return 0;
else
return Find (Nodes (This.Children), Child);
end if;
end Find_Child;
function Find_Parent (Parent : Node; Child : Node) return Natural is
This : Node_Header renames Header (Deref (Child)).all;
begin
if Parent = null then
raise Constraint_Error;
elsif This.Parents = Null_Address then
return 0;
else
return Find (Nodes (This.Parents), Parent);
end if;
end Find_Parent;
function Get_Child (Parent : Node; Child : Positive) return Node is
This : Node_Header renames Header (Deref (Parent)).all;
begin
if This.Children = Null_Address then
raise Constraint_Error;
else
declare
Set : Nodes_Set renames Nodes (This.Children).all;
begin
if Child > Set.Last then
raise Constraint_Error;
else
return Set.List (Child);
end if;
end;
end if;
end Get_Child;
function Get_Children (Parent : Node) return Nodes_Array is
This : Node_Header renames Header (Deref (Parent)).all;
begin
if This.Children = Null_Address then
return (1..0 => null);
else
declare
Children : Nodes_Set renames Nodes (This.Children).all;
begin
return Children.List (1..Children.Last);
end;
end if;
end Get_Children;
function Get_Children (Parent : Node) return Node_Sets.Set is
This : Node_Header renames Header (Deref (Parent)).all;
Result : Node_Sets.Set;
begin
if This.Children /= Null_Address then
declare
Children : Nodes_Set renames Nodes (This.Children).all;
begin
for Index in 1..Children.Last loop
Add (Result, Children.List (Index));
end loop;
end;
end if;
return Result;
end Get_Children;
function Get_Children_Number (Parent : Node) return Natural is
This : Node_Header renames Header (Deref (Parent)).all;
begin
if This.Children = Null_Address then
return 0;
else
return Nodes (This.Children).Last;
end if;
end Get_Children_Number;
function Get_Parent (Child : Node; Parent : Positive) return Node is
This : Node_Header renames Header (Deref (Child)).all;
begin
if This.Parents = Null_Address then
raise Constraint_Error;
else
declare
Set : Nodes_Set renames Nodes (This.Parents).all;
begin
if Parent > Set.Last then
raise Constraint_Error;
else
return Set.List (Parent);
end if;
end;
end if;
end Get_Parent;
function Get_Parents (Child : Node) return Nodes_Array is
This : Node_Header renames Header (Deref (Child)).all;
begin
if This.Parents = Null_Address then
return (1..0 => null);
else
declare
Parents : Nodes_Set renames Nodes (This.Parents).all;
begin
return Parents.List (1..Parents.Last);
end;
end if;
end Get_Parents;
function Get_Parents (Child : Node) return Node_Sets.Set is
This : Node_Header renames Header (Deref (Child)).all;
Result : Node_Sets.Set;
begin
declare
Parents : Nodes_Set renames Nodes (This.Parents).all;
begin
for Index in 1..Parents.Last loop
Add (Result, Parents.List (Index));
end loop;
end;
return Result;
end Get_Parents;
function Get_Parents_Number (Child : Node) return Natural is
This : Node_Header renames Header (Deref (Child)).all;
begin
if This.Parents = Null_Address then
return 0;
else
return Nodes (This.Parents).Last;
end if;
end Get_Parents_Number;
function Is_Ancestor (Parent : Node; Child : Node) return Boolean is
Visited : Node_Address_Sets.Set;
Queued : Unbounded_Array;
Current : Node := Parent;
Count : Positive := 1;
begin
if Child = null then
raise Constraint_Error;
end if;
loop
declare
This : Node_Header renames Header (Deref (Current)).all;
begin
Add (Visited, Current);
if This.Children /= Null_Address then
declare
Successor : Node;
Children : Nodes_Set renames
Nodes (This.Children).all;
begin
if Is_In (Children, Child) then
return True;
end if;
for Index in 1..Children.Last loop
Successor := Children.List (Index);
if not Is_In (Visited, Successor) then
Put (Queued, Count, Successor);
Count := Count + 1;
end if;
end loop;
end;
end if;
end;
exit when Count = 1;
Count := Count - 1;
Current := Get (Queued, Count);
end loop;
return False;
end Is_Ancestor;
function Is_Connected (Vertex : Node) return Boolean is
This : Node_Header renames Header (Deref (Vertex)).all;
begin
return
( ( This.Parents /= Null_Address
and then
Nodes (This.Parents).Last > 0
)
or else
( This.Children /= Null_Address
and then
Nodes (This.Children).Last > 0
) );
end Is_Connected;
function Is_Descendant (Child : Node; Parent : Node)
return Boolean is
Visited : Node_Address_Sets.Set;
Queued : Unbounded_Array;
Current : Node := Child;
Count : Positive := 1;
begin
if Parent = null then
raise Constraint_Error;
end if;
loop
declare
This : Node_Header renames Header (Deref (Current)).all;
begin
Add (Visited, Current);
if This.Parents /= Null_Address then
declare
Predecessor : Node;
Parents : Nodes_Set renames
Nodes (This.Parents).all;
begin
if Is_In (Parents, Parent) then
return True;
end if;
for Index in 1..Parents.Last loop
Predecessor := Parents.List (Index);
if not Is_In (Visited, Predecessor) then
Put (Queued, Count, Predecessor);
Count := Count + 1;
end if;
end loop;
end;
end if;
end;
exit when Count = 1;
Count := Count - 1;
Current := Get (Queued, Count);
end loop;
return False;
end Is_Descendant;
function Is_In (Set : Nodes_Set_Ptr; Item : Node) return Boolean is
begin
return
( Set /= null
and then
Set.Last > 0
and then
Find (Set.List, Set.Last, Item) > 0
);
end Is_In;
function Is_In (Set : Nodes_Set; Item : Node) return Boolean is
begin
return Set.Last > 0 and then Find (Set.List, Set.Last, Item) > 0;
end Is_In;
function Is_Sibling (Left, Right : Node) return Boolean is
This : Node_Header renames Header (Deref (Left)).all;
That : Node_Header renames Header (Deref (Right)).all;
begin
if ( This.Parents = Null_Address
or else
That.Parents = Null_Address
)
then
return False;
end if;
declare
This_Parents : Nodes_Set renames Nodes (This.Parents).all;
That_Parents : Nodes_Set renames Nodes (That.Parents).all;
begin
if This_Parents.Last > That_Parents.Last then
for Index in 1..That_Parents.Last loop
if Is_In (This_Parents, That_Parents.List (Index)) then
return True;
end if;
end loop;
else
for Index in 1..This_Parents.Last loop
if Is_In (That_Parents, This_Parents.List (Index)) then
return True;
end if;
end loop;
end if;
return False;
end;
end Is_Sibling;
function Precedes (Left, Right : Node) return Boolean is
begin
return
( Right /= null
and then
(Left = null or else Less (Left, Right))
);
end Precedes;
function Related (Parent : Node; Child : Node) return Boolean is
This : Node_Header renames Header (Deref (Parent)).all;
begin
if Child = null then
raise Constraint_Error;
elsif This.Children = Null_Address then
return False;
else
return Is_In (Nodes (This.Children), Child);
end if;
end Related;
procedure Remove (Set : Nodes_Set_Ptr; Item : Node) is
begin
if Set.Last > 0 then
declare
Location : constant Integer :=
Find (Set.List, Set.Last, Item);
begin
if Location > 0 then
Set.List (Location..Set.Last - 1) :=
Set.List (Location + 1..Set.Last);
Set.Last := Set.Last - 1;
end if;
end;
end if;
end Remove;
procedure Remove (Set : Address; Item : Node) is
begin
Remove (Nodes (Set), Item);
end Remove;
procedure Remove (Vertex : Node) is
This : Node_Header renames Header (Deref (Vertex)).all;
begin
if This.Parents = Null_Address then
if This.Children = Null_Address then
return;
end if;
declare
Children : Nodes_Set_Ptr renames Nodes (This.Children);
begin
for Child in 1..Children.Last loop
Remove
( Header (Deref (Children.List (Child))).Parents,
Vertex
);
end loop;
Children.Last := 0;
end;
elsif This.Children = Null_Address then
declare
Parents : Nodes_Set_Ptr renames Nodes (This.Parents);
begin
for Parent in 1..Parents.Last loop
Remove
( Header (Deref (Parents.List (Parent))).Children,
Vertex
);
end loop;
Parents.Last := 0;
end;
else
declare
Parents : Nodes_Set_Ptr renames Nodes (This.Parents);
Children : Nodes_Set_Ptr renames Nodes (This.Children);
begin
for Child in 1..Children.Last loop
Remove
( Header (Deref (Children.List (Child))).Parents,
Vertex
);
end loop;
for Parent in 1..Parents.Last loop
Remove
( Header (Deref (Parents.List (Parent))).Children,
Vertex
);
for Child in 1..Children.Last loop
Add
( Header (Deref (Parents.List (Parent))).Children,
Children.List (Child),
Minimal_Children_Size
);
Add
( Header (Deref (Children.List (Child))).Parents,
Parents.List (Parent),
Minimal_Parents_Size
);
end loop;
end loop;
Parents.Last := 0;
Children.Last := 0;
end;
end if;
end Remove;
function Same (Left, Right : Node) return Boolean is
begin
return
( Right = Left
or else
( Left /= null
and then
Right /= null
and then
Equal (Left, Right)
) );
end Same;
function Storage_Size (Pool : Node_Storage_Pool)
return Storage_Count is
begin
return Storage_Size (Pool.Host.all);
end Storage_Size;
function "<" (Left, Right : Node) return Boolean is
begin
return
( Right /= null
and then
(Left = null or else Left.all'Address < Right.all'Address)
);
end "<";
end Generic_Directed_Graph;