(May-07-2023, 03:45 AM)deanhystad Wrote: When graphing points or vertices, are they treated differently? Or are you making two classes because you think you need one graph class for each class of item you are trying to graph?
Yes, maybe I am overthinking everythig. I took great inspiration in the networx package, where they have different classes for each graph type (graph, multigraph,..) but there the internal structure is always different, so it makes sense. Maybe not in my case, since only the node types are different. I really liked netwokx structure, where they store all data as dictionaries and then have different views on this data so the user can access it more naturally.
(May-07-2023, 06:14 AM)Gribouillis Wrote: Dataclases are probably the appropriate tools instead of dictionaries, and it solves the problem of identifying the type of the objects in a collection with mixed objects. Namedtuples could perhaps be used too.Hm... but for the nodes I would really need the functionality of a list, since a node is really just a list of neighbouring nodes. And I will often change particular items at particular indices, so
__setitem__
and __getitem__
will be often called.Surely I could add a data parameter to the dataclass, but then it would be less clear for the end user, they would access the data through
node.data[i]
instead of node[i]
. What if I just wrap a list and have a name parameter
class Vertex(list): def __init__(self, data): super(Vertex, self).__init__(data) self.name = "vertex"And then use filters so the user can iterate over certain types.
But I kinda hate the idea to have an almost empty class just for determining its "type".