DCL 3.7.4
Loading...
Searching...
No Matches
MessageTree.h
Go to the documentation of this file.
1#ifndef __DCL_HS_MESSAGE_TREE_H__
2#define __DCL_HS_MESSAGE_TREE_H__ 20051210
3
4#ifndef __DCL_CONFIG_H__
5#include <dcl/Config.h>
6#endif
7
8#define __DEBUG_ALGORITHM 0
9
10__DCL_BEGIN_NAMESPACE
11
12/*
13 이 알고리즘은 트리의 각 노드에 64bit 정수값을 사용하여 절대주소를 할당한다.
14 width와 depth가 적용된 모든 트리는 완전트리의 구조를 가지며
15 width, depth는 다음의 값을 가질때 가장 넓은 범위를 갖는다.
16
17 width depth(depth index) : 수치의 범위
18 -----------------------------------------
19 2147483647 2(0 ~ 1) : 1 ~ 2147483648(INT32_MAX + 1)
20 2097151 3(0 ~ 2) : 1 ~ 4398044413953
21 55108 4(0 ~ 3) : 1 ~ 167360062766485
22 6208 5(0 ~ 4) : 1 ~ 1485514159958081
23 1448 6(0 ~ 5) : 1 ~ 6370049982705129
24 511 7(0 ~ 6) : 1 ~ 17839230820809217
25 234 8(0 ~ 7) : 1 ~ 38580774189064615
26 127 9(0 ~ 8) : 1 ~ 68212339274677761
27 78 10(0 ~ 9) : 1 ~ 108256828977093499
28 52 11(0 ~ 10) : 1 ~ 147389519791195397
29 38 12(0 ~ 11) : 1 ~ 245019943472837715
30 28 13(0 ~ 12) : 1 ~ 240818941573998061
31 22 14(0 ~ 13) : 1 ~ 296277203496562883
32 18 15(0 ~ 14) : 1 ~ 396861212733968143
33 15 16(0 ~ 15) : 1 ~ 469172025408063616
34 13 17(0 ~ 16) : 1 ~ 720867993281778161
35
36 depth 2(1)의 width는 더 큰값도 가능하지만
37 32bit 컴파일러에서 int는 INT32이기 때문에 위와 같이 정한다.
38
39 제곱근을 구하기 위해 반복문을 사용한다. depth가 깊을수록 성능이 떨어진다.
40*/
42{
43private:
44 int __nDepth; // 트리의최대 깊이, 최상위 노드에서 시작, 1 ~
45 int __nWidth; // 1 이상의 각 깊이에서 최대 형제노드의 개수
46
47 int64_t __nMinReplyID; // == 1
48 int64_t __nMaxReplyID; // width가 홀수이고 depth가 짝수이면 홀수
49
50 int64_t POWER(int nExponent) const; // __nWidth ^ nExponent
51
52public:
53 static int getDefaultWidth(int nDepth);
54
55 MessageTree(int nDepth);
56#ifdef __DEBUG_ALGORITHM
57 MessageTree(int nDepth, int nWidth);
58#endif
59
60 int depth() const;
61 int width() const;
62
63 int64_t minReplyID() const;
64 int64_t maxReplyID() const;
65
66 // 형제노드간의 간격
67 int64_t getSiblingGap(int nDepthIndex) const;
68
69 struct Position
70 {
71 int64_t nParentID;
72 int nDepthIndex; // 0 ~
73 int nWidthIndex; // 같은 nParentID인 형제 노드간의 위치 0 ~
74 };
75
76 void getPosition(
77 int64_t nReplyID,
78 Position& rPos
79 ) const;
80
81 // 자식노드 중 첫번째 노드(nWidthIndex == 0)의 값
82 int64_t getFirstChildID(int64_t nReplyID) const;
83
84 // 자식노드 중 마지막 노드(nWidthIndex == (__nWidth - 1)의 값
85 int64_t getLastChildID(int64_t nReplyID) const;
86
87 // nReplyID의 nWidthIndex(0 based)번째의 자식노드의 값
88 int64_t getChildID(int64_t nReplyID, int nWidthIndex) const;
89};
90
91inline int MessageTree::depth() const
92{
93 return __nDepth;
94}
95
96inline int MessageTree::width() const
97{
98 return __nWidth;
99}
100
101__DCL_END_NAMESPACE
102
103#endif // __DCL_HS_MESSAGE_TREE_H__
int64_t minReplyID() const
int depth() const
Definition MessageTree.h:91
int64_t maxReplyID() const
int64_t getLastChildID(int64_t nReplyID) const
int width() const
Definition MessageTree.h:96
static int getDefaultWidth(int nDepth)
void getPosition(int64_t nReplyID, Position &rPos) const
int64_t getChildID(int64_t nReplyID, int nWidthIndex) const
MessageTree(int nDepth)
int64_t getSiblingGap(int nDepthIndex) const
int64_t getFirstChildID(int64_t nReplyID) const