Exemplo n.º 1
0
        public override void CreateChildren()
        {
            // Do nothing, if children are already created
            if (Children.Count >= 9)
            {
                return;
            }

            int children_layer = layerNum + 1;
            int children_size  = getNodeSize() / 2;
            Dictionary <int, PartitionNode> added_children = new Dictionary <int, PartitionNode>();

            for (int i = 0; i < 9; i++)
            {
                if (Children.ContainsKey(i) && Children[i] != null)
                {
                    continue;
                }
                else
                {
                    PartitionNode new_child = new PartitionNode(children_layer, children_size, NodeHelperFuncs.GetChildCenter(this, i), capacity);
                    new_child.AddParent(this, NodeHelperFuncs.GetParentPosition(i));
                    Children.Add(i, new_child);
                    added_children.Add(i, new_child);
                }
            }
            ConnectSharedChildren(added_children);
        }
Exemplo n.º 2
0
        private void ConnectSharedChildren(Dictionary <int, PartitionNode> added_children)
        {
            // For created children finds and connects other parents sharing the same children.
            Dictionary <int, PartitionNode> all_siblings = GetMySiblings();

            foreach (KeyValuePair <int, PartitionNode> child in added_children)
            {
                foreach (int sibling_num in NodeHelperFuncs.getRelevantSiblings(child.Key))
                {
                    if (all_siblings.ContainsKey(sibling_num) && all_siblings[sibling_num] != null)
                    {
                        int sChildNum = NodeHelperFuncs.getSharedSiblingChildNumber(child.Key, sibling_num);
                        all_siblings[sibling_num].SetSingleChild(sChildNum, child.Value);
                        child.Value.AddParent(all_siblings[sibling_num], NodeHelperFuncs.GetParentPosition(sChildNum));
                    }
                }
            }
        }