A
A
Alexander2017-02-17 12:29:28
Algorithms
Alexander, 2017-02-17 12:29:28

How to correctly synchronize a hierarchical structure that has a parallel hierarchy?

Good afternoon. There was such a difficulty, perhaps someone knows a competent solution.
There is a hierarchical data structure that is periodically updated based on an upload from an external source. Unloading can be complete or for one specific node.
Each node has a boolean 'hidden' attribute that comes in the upload. Also, the node has some content, which may be empty. Also, each node has a boolean 'empty' attribute that needs to be recalculated at the time of synchronization.
The empty attribute must be set to true if the node matches all conditions:

  • Node has empty content
  • Node has no non-empty and non-hidden children

In the unloading, the descendants are guaranteed to go after their parents, so earlier the definition of empty was carried out as follows:
The program goes through the unloading sequentially, each node adds to the database or updates it if it is already there. Looks in the upload to see if it has empty content. Selects in its base the immediate children of this node that are neither empty nor hidden. Sets the value to empty based on this.
After that, the program sequentially goes up the chain of parents of this node and performs the same procedure for them. This is necessary because the unprocessed part of the unload will contain information about the children, and if their list or their empty and hidden values ​​​​are updated, then this may invalidate the empty value of the parent, and it needs to be recalculated.
I know the algorithm looks suboptimal, but I didn't write it.
Now the task has come: to make it so that the node could be, as it were, an alias (link) to another node. This is necessary to implement a parallel hierarchy.
Accordingly, in the empty calculation, it must be taken into account that the node must be non-empty if it refers to a non-empty node. The problem is that an alias can be present in the unloading both before and after the node to which it refers.
What is the best way to implement such a structure, taking into account the described requirements?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2017-02-17
@Rsa97

Do everything in a transaction. First, enter the data, while monitoring for the occurrence of cycles. Then recursively recalculate the empty attribute for all entries. And only after that complete the transaction.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question