[Gambas-user] RFC: How to identify vertices and edges in a Graph class?
Tobias Boege
taboege at ...626...
Mon Jul 7 17:59:29 CEST 2014
On Mon, 07 Jul 2014, Beno?t Minisini wrote:
> Le 07/07/2014 10:51, Tobias Boege a ?crit :
> >
> > We keep these generalisations and advanced topics in mind but for now, one
> > point I can and want readily apply is: in your opinion, it would be better
> > to address vertices by Strings, in a human-readable form, not just integers,
> > right? I'm still torn.
> >
> > I will make the Graph act like a Collection, i.e. once you have associated a
> > value to an ID, that ID is not changed by other operations on the Graph. You
> > had a point there; everything else hardly bearable for the programmer.
> > However, I want to use Integers as IDs because they are easier to store and
> > sort and abstract enough for the job.
> >
> > If you want to associate more human-readable names with your vertices, I
> > think you can easily achieve it by having a Collection asscoaite your names
> > with the numerical IDs. In fact that's what I'd do in the Graph internals if
> > I was to offer String IDs.
> >
> > Regards,
> > Tobi
> >
>
> Internally, you have to use an hash table anyway, haven't you? You just
> don't want to necessarily use string keys, as they are heavier than
> integer keys?
>
Oh! My thoughts were: I'll need a translation table for vertex IDs into
internal indices (e.g. over an adjacency matrix) and to search for a
mapping, that table must be sorted, so I have to compare a lot. That alone
would actually be negligible overhead. And with a hash table, not even
this problem arises. Thanks for doubting me :-) No problem to use String
keys straight from the beginning.
> Anyway, you must use a Collection-like interface to access the graph
> nodes (to be consistent with the other Gambas containers). You can use
> integer keys with no problems, as later you can switch to string keys
> and keep the backward-compatibility.
>
> You can have both too : I mean having a Gambas hash table to reference
> nodes by names, and a special hash table using integer keys. A void hash
> table does not take a lot of memory.
>
How would I write the signature of _get() down in this case?
Regards,
Tobi
--
"There's an old saying: Don't change anything... ever!" -- Mr. Monk
More information about the User
mailing list