graphblas-algorithms icon indicating copy to clipboard operation
graphblas-algorithms copied to clipboard

add `id_to_key` as argument to graph constructor

Open q-aaronzolnailucas opened this issue 2 months ago • 1 comments

in ga.Graph.__init__ we can specify key_to_id. I can't see any reason why this must be a stdlib.dict and not any other class that implements the typing.Mapping protocol (__getitem__, __len__, __iter__). I have a usecase where I have a more memory efficient mapping than a dict and would like to use it.

However, whenever the id_to_key property is used, this will create a full inverse mapping, undoing any memory efficiency. It would be great to be able to pass an inverse mapping optionally (id_to_key) to avoid this calculation if possible. Currently I'm doing:

G = ga.Graph(..., key_to_id=...)
G._id_to_key = ...

but obviously this relies on setting the 'private' _id_to_key member, which has no API stability guarantees. I'd be happy to implement this change!

q-aaronzolnailucas avatar Apr 18 '24 11:04 q-aaronzolnailucas