Function Name: DataPlacement (a recursive function) |
Input: dtNode: The root of the data sub-tree prepared to be allocated |
ctNode: The root of the server sub-tree prepared to allocate into |
Output: whether this data placement success |
) if (ctNode.LeftNode == Null && ctNode.RightNode == Null) //leaf node! |
) If (the remainder storage space >= the total size of the current data tree) |
) //Allocate success! And record the allocation result |
) for (every node in the tree rooted by ctNode) |
) dataPlace[node.number] = ctNode.number; |
) update ctNode’s Ccr and size; //update the remainder computation and storage value |
) Return True; |
) /Bottom-up server sub-tree selection strategy. First, try to allocate to the left node, and then the right / |
) else if (dtNode.size < ctNode.LeftNode.size) |
) if (DataPlacement (dtNode, ctNode.LeftNode) == True) return True; //allocated! |
) else if (dtNode.size < ctNode.RightNode.size) //try to allocate to the right node |
) if (DataPlacement (dtNode, ctNode.RightNode) == True) return True; //allocated! |
) /Top-down data tree selection principle. If the overall current data tree cannot be allocated to any server sub-tree, |
then try to allocate its left sub-tree and right-subtree/ |
) Bool LeftSuccess, RightSuccess; |
) if (max (dtNode.LeftNode.size, dtNode.RightNode.size) < min (ctNode.LeftNode.size, |
) ctNode.RightNode.size)) //the two methods of distributing subtrees (left to left, right to |
) //right; or left to right, right to left) are both possible |
) /First try to allocate the data sub-tree with more storage requirements/ |
) If (dtNode.LeftNode.size >= dtNode.RightNode.size) |
) if (DataPlacement (dtNode.LeftNode, ctNode.LeftNode) == True) LeftSuccess = True; |
) else if (DataPlacement (dtNode.LeftNode, ctNode.RightNode) == True) LeftSuccess = True; |
) if (LeftSuccess == True ) allocate the reminder data sub-tree to the other server sub-tree, if success, |
RightSuccess = True, else: |
) //Bottom-up server sub-tree selection strategy. Try to allocate the data sub-tree to the parent node |
(the higher level sub-tree) |
) if (DataPlacement (dtNode.RightNode, ctNode) == True) RightSuccess = True; |
) else if (DataPlacement (dtNode.LeftNode, ctNode) == True) LeftSuccess = True; |
) /Else, the right node has more storage requirements, allocate it / |
) else if (dtNode.RightNode.size > dtNode.LeftNode.size) |
) if (DataPlacement (dtNode.RightNode, ctNode.LeftNode) == True) RightSuccess = True; |
) else if (DataPlacement (dtNode.RightNode, ctNode.RightNode) == True) RightSuccess = True; |
) if (RightSuccess == True ) allocate the reminder data sub-tree to the other server sub-tree, if success, |
LeftSuccess = True, else: |
) if (DataPlacement (dtNode.LeftNode, ct Node) == True) LeftSuccess = True; |
) else if (DataPlacement (dtNode.RightNode, ctNode) == True) RightSuccess = True; |
) if (LeftSuccess == True && RightSuccess == True) return True; |
) else return False; |