messageID ParentMessageID threadID forumID 2 NULL 1 31 31 2 1 31 46 2 1 31 61 2 1 31 62 2 1 31 32 31 1 31 47 46 1 31 <p class="indent">
public void addChild(long parentKey, long newKey) { // 找到一个给定的节点parentKey的父结点 char parentIndex = findKey(parentKey, (char) 1); //System.out.println("父节点索引号:" + (int)parentIndex + "-----父结点:" + parentKey + // "-----子结点:" + (int)newKey); if (parentIndex == 0) { throw new IllegalArgumentException("Parent key " + parentKey + " not found when adding child " + newKey + "."); } keys[nextIndex] = newKey; leftChildren[nextIndex] = 0; rightSiblings[nextIndex] = 0; System.out.println("keys[" + (int) nextIndex + "] = " + (int) newKey); // Adjust references. Check to see if the parent has any children. if (leftChildren[parentIndex] == 0) { // No children, therefore make the new key the first child. leftChildren[parentIndex] = nextIndex; System.out.println("leftChildren[" + (int) parentIndex + "] = " + (int) nextIndex); } else { // The parent has children, so find the right-most child. long siblingIndex = leftChildren[parentIndex]; while (rightSiblings[new Long(siblingIndex).intValue()] != 0) { siblingIndex = rightSiblings[new Long(siblingIndex).intValue()]; } // Add the new entry as a sibling of that last child. //rightSiblings[new Long(siblingIndex).intValue()] = nextIndex; int tmpint = new Long(siblingIndex).intValue(); rightSiblings[tmpint] = nextIndex ; System.out.println("rightSiblings[" + tmpint +"] = " + (int)nextIndex); } // Finally, increment nextIndex so it's ready for next add. nextIndex++; } <p class="indent">