LongTree的正確分析理解
LongTree的正確理解分析
在網上有一篇檔案介紹LongTreer的原理的,但是對於leftChildren和rightSiblings的講解似乎有些不完整。
leftChildren儲存某結點兒子在keys[]中的陣列索引值,同理rightSiblings儲存其本結點兄弟在keys[]中的陣列索引值。
透過一些測試讓我理解這一功能:
下面是從JiveMessage表中擷取的部分資料
在LongTree中的addChild方法加入了部分程式碼,也修改了部分程式碼,目的是為了輸出leftChildren 、rightSiblings的數值
下面是輸出值
keys[2] = 31
leftChildren[1] = 2
keys[3] = 32
leftChildren[2] = 3
keys[4] = 46
rightSiblings[2] = 4
keys[5] = 47
leftChildren[4] = 5
keys[6] = 61
rightSiblings[4] = 6
keys[7] = 62
rightSiblings[6] = 7
得到了這麼一組值,該如何理解呢?
假設有
leftChildren[X] = Y
正確理解是
keys[Y]是keys[X]的一個兒子結點
同理
rightSiblings[X] = Y
正確理解是
keys[Y]是keys[X]的一個兄弟結點
也就是說leftChildren、rightSiblings儲存的是它們子結點、兄弟結點在keys[]中的陣列索引值而已,而不能說leftChildren儲存的是某一結點的子結點
時間有限,懶得去好好的整理文字,大家能理解就行
願和更多的對Jive有深入研究的朋友交流
QQ:45214493(對JIVE沒有研究者勿加)
在網上有一篇檔案介紹LongTreer的原理的,但是對於leftChildren和rightSiblings的講解似乎有些不完整。
leftChildren儲存某結點兒子在keys[]中的陣列索引值,同理rightSiblings儲存其本結點兄弟在keys[]中的陣列索引值。
透過一些測試讓我理解這一功能:
下面是從JiveMessage表中擷取的部分資料
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"> |
在LongTree中的addChild方法加入了部分程式碼,也修改了部分程式碼,目的是為了輸出leftChildren 、rightSiblings的數值
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"> |
下面是輸出值
keys[2] = 31
leftChildren[1] = 2
keys[3] = 32
leftChildren[2] = 3
keys[4] = 46
rightSiblings[2] = 4
keys[5] = 47
leftChildren[4] = 5
keys[6] = 61
rightSiblings[4] = 6
keys[7] = 62
rightSiblings[6] = 7
得到了這麼一組值,該如何理解呢?
假設有
leftChildren[X] = Y
正確理解是
keys[Y]是keys[X]的一個兒子結點
同理
rightSiblings[X] = Y
正確理解是
keys[Y]是keys[X]的一個兄弟結點
也就是說leftChildren、rightSiblings儲存的是它們子結點、兄弟結點在keys[]中的陣列索引值而已,而不能說leftChildren儲存的是某一結點的子結點
時間有限,懶得去好好的整理文字,大家能理解就行
願和更多的對Jive有深入研究的朋友交流
QQ:45214493(對JIVE沒有研究者勿加)
相關文章
- 正確理解 PHP 的過載PHP
- background-position的正確理解方式
- 正確理解memcached,才能更好的使用
- 正確理解CAP理論
- 怎樣正確理解volatile?
- 如何正確理解棧和堆?
- 談如何正確理解 IP 資料的覆蓋率,兼談正確率~
- 理解並正確使用synchronized和volatilesynchronized
- 正確理解和使用JAVA中的字串常量池Java字串
- 如何正確理解「指標」和「標籤」指標
- 編寫高質量的js之正確理解正規表示式回溯JS
- 如何正確理解Python培訓?有必要嗎?Python
- Dijkstra演算法及正確性分析演算法
- “5Why分析法”的正確使用姿勢
- Troubleshooting 專題 - 問正確的問題 得到正確的答案
- 分散式系統知識分享:正確理解CAP定理分散式
- 如何正確理解神經網路在NLP領域的運用神經網路
- 理解玩家的正確姿勢:遊戲到底意味著什麼?遊戲
- PHP Opcache 的正確使用PHPopcache
- 如何正確的找BUG
- 提出問題,解答問題!這才是理解程式碼設計的正確方法
- Handler正確用法
- TiDB 的正確使用姿勢TiDB
- Redis的正確使用姿勢Redis
- node 升級的正確方法
- Android中Handler的正確使用Android
- 上帝與集合的正確用法
- OnlineJudge的正確開啟方式
- 如何進行正確的 CodeReviewView
- WikiPedia 的正確開啟方式
- JS 繼承的正確操作JS繼承
- git commit 的正確姿勢GitMIT
- 日期的正確儲存方式
- API 演進的正確方式API
- Axios的正確食用方法iOS
- ThreadLocal的正確使用與原理thread
- 如何正確的建立網站網站
- 智慧|智慧倉儲就是無人倉庫嗎?正確理解很重要
- Node.js Event Loop 的三大常見理解誤區和正確概念辨析Node.jsOOP