Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

9
  • By "extra data" I mean data (variables, function pointers etc) that the algorithm needs to store for every node in order to work. Different algorithms require different data. Some don't require any, others require a couple of ints, other require a stack of pointers or other complex objects. The graph is fixed and it's a directed acyclic graph. The algorithms never modify the nodes (except for their algorithm-specific "extra data"). Usually the nodes are between 50 and 1000. An algorithm might process some nodes hundreds of thousand of times. Commented Dec 22, 2020 at 7:16
  • About "place extra data right before the node" I mean that, when the factory allocates a node, it can allocate a struct { ExtraData; Node; }. Then it returns a pointer to the Node. By using that pointer it should be able to access the ExtraData. Commented Dec 22, 2020 at 7:18
  • 1
    Do you really need to frame this as "extra data" ? Why do you need this layer of polymorphisme which looks very cool in theory? Can't you just have one uniq type of node, and have your algorythm simply not use all available field? Commented Dec 22, 2020 at 8:03
  • @s.lg: yes, that's an option too. I'll edit my question to add it as a fourth option. My intuition suggested that adding specific-case to a generic interface was a very bad design. Given the alternatives it might be a good compromise though. Commented Dec 22, 2020 at 8:12
  • @DocBrown: one hour ago I tried to add more context to the example, but I couldn't find a way without making the question huge. It's almost bedtime for me. Tomorrow I'll try again to describe what I'm working on and highlight some examples while keeping the post concise. Commented Dec 22, 2020 at 8:35