comp.lang.ada
 help / color / mirror / Atom feed
From: MADMATS@ELCGL.EPFL.CH ("", Mats Weber)
Subject: RE: Booch Graph Component Interator Question
Date: 12 Nov 90 21:00:00 GMT	[thread overview]
Message-ID: <901112220011.1ch@sic.epfl.ch> (raw)

>I want to iterate over all the current vertices of the graph,
>to see of one of them has a particular value of a charateristic
>(for purposes of discussion, having a particular "name").
> 
>I instantiate the graph-package with a STRING to contain the name
>as the vertex item, and a NATURAL to be a count as the arc attribute.>>
>
>[...]

First, you should not ITERATE if what you want is FIND

Second, for good reasons, few components will allow you to modify their 
structure while you are iterating on them.

The graph component already gives you the mapping Vertex -> String

What you seem to need is a mapping String -> Vertex, which you may obtain 
by instantiating a Map component.

Then, once you have the name of the vertex you want to modify, search for 
the corresponding Vertex in your String -> Vertex map, and then modify that 
vertex accordingly.

If you want to do some operation on all vertices, then iterate on the 
String -> Vertex map and modify the vertices within the graph from within 
that iterator. (You might have to use a String -> access Vertex mapping if 
the Map component does not provide a constructive iterator (on that allows 
you to modify subcomponents of the structure you are manipulating)).

Answer to #4: Do not use a global variable, but instantiate the iterator 
within a procedure:

   function Number_Of_Vertices (G : in Graph) return Natural is

      Count : Natural := 0;

      procedure Count_Vertex (V : in Vertex) is
      begin
         Count := Count + 1;
      end;

      procedure Count_Vertices is new Iterate_Vertices(Count_Vertex);

   begin
      Count_Vertices(G);
      return Count;
   end;

   -- I'm not shure of the names, but you get the idea.


Mats Weber
Swiss Federal Institute of Technology
EPFL DI LGL
1015 Lausanne
Switzerland

E-mail : madmats@elcgl.epfl.ch
phone  : +41 21 693 52 92
fax    : +41 21 693 39 09

             reply	other threads:[~1990-11-12 21:00 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1990-11-12 21:00 "", Mats Weber [this message]
  -- strict thread matches above, loose matches on Subject: below --
1990-11-08 14:29 Booch Graph Component Interator Question Paul Stachour
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox