[Gambas-user] RFC: How to identify vertices and edges in a Graph class?

Benoît Minisini gambas at ...1...
Mon Jul 7 18:26:58 CEST 2014


Le 07/07/2014 17:59, Tobias Boege a écrit :
>>
>> 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?
>

For integer keys: _get(Index As Integer) As ...

For string keys: _get(Index As String) As ...

For both: _get(Index As Variant) As...
-> That needs more work to check the index, and it is confusing, so 
forget the "both" case!

-- 
Benoît Minisini




More information about the User mailing list