class GBN_GIDE_ITERATOR -- Emits edges in unpredictable sequence from a graph -- If the graph is undirected then the edges are -- stored in adjacent pairs of inverse directed edges, -- Edge_count counts the number of pairs in this case. -- The cursor is from 1 to edge_count; item returns -- edge indexed 2*cursor-1 in the undirected case. inherit GBN_ITERATOR [GBN_EDGE] creation {GBN_GEN_GEDGE} make feature {NONE} make ( graf : like the_graph ) is require nonvoid: graf /= Void do the_graph := graf if the_graph . edge_count > 0 then cursor := 1 end if not finished then the_graph . logon end ensure valid_graph: the_graph = graf empty_finished: the_graph.edge_count = 0 implies finished finished_empty: finished implies the_graph . edge_count = 0 valid_edge : finished or else the_graph.has_edge ( item ) protection: finished or else the_graph . is_protected end feature {ANY} the_graph : GBN_GIDGRAPH -- only public to allow -- the ensure clauses with make and forth finished: BOOLEAN is do Result := cursor <= 0 or cursor > the_graph.edge_count end forth is do cursor := cursor + 1 if cursor > the_graph.edge_count then the_graph.logoff end ensure -- forth has no postconditions in parent class, hence no then has_edge: finished or else the_graph . has_edge ( item ) end stop is do cursor := the_graph.edge_count + 1 the_graph . logoff end item : GBN_EDGE is do if the_graph.is_undirected then Result := the_graph . edges . item ( 2*cursor-1 ) else Result := the_graph . edges . item ( cursor ) end end feature {NONE} cursor : integer end -- class GBN_GIDE_ITERATOR [G]