I hope one of you guys can figure it out.
I have an array containing many objects. Each object in the array contains two things:
- The value is subject to change.
- A list of zero or more other objects in my array that, if their values ββchange, then this object must recalculate its value. This can be cascaded many times from object to object, but there are no dependency cycles.
I believe this is called a network (like a tree, but with multiple parents). In particular, it is an acyclic schedule with direct access.
What I'm doing right now is: when I change the value of an object, I check every object in the array to see if it depends on the object I just changed. If this happens, I will tell this child to count. Then the child tells the children in the same way, etc.
This works (values ββare updated correctly), but very slowly when a change occurs that cascades broadly and deeply. This is due to the fact that if an object has many parents that change, it recounts for each of them, and also indicates that the children are counted every time, so they receive several messages from only one parent. These are fast snowballs, until many objects are counted dozens of times.
What is the best way to only recount each object once, after all its parents have counted?
Thank you for your help.
source share