DCL 3.7.4
Loading...
Searching...
No Matches
MessageTree Class Reference

#include <MessageTree.h>

Classes

struct  Position

Public Member Functions

 MessageTree (int nDepth)
 MessageTree (int nDepth, int nWidth)
int depth () const
int width () const
int64_t minReplyID () const
int64_t maxReplyID () const
int64_t getSiblingGap (int nDepthIndex) const
void getPosition (int64_t nReplyID, Position &rPos) const
int64_t getFirstChildID (int64_t nReplyID) const
int64_t getLastChildID (int64_t nReplyID) const
int64_t getChildID (int64_t nReplyID, int nWidthIndex) const

Static Public Member Functions

static int getDefaultWidth (int nDepth)

Detailed Description

Definition at line 41 of file MessageTree.h.

Constructor & Destructor Documentation

◆ MessageTree() [1/2]

MessageTree::MessageTree ( int nDepth)

Definition at line 285 of file MessageTree.cpp.

286{
287 __DCL_ASSERT(2 <= nDepth && nDepth <= 17);
288
289 __nWidth = __aWidth[nDepth - 2];
290 __nDepth = nDepth;
291
292 __nMinReplyID = 1;
293 __nMaxReplyID = ((POWER(__nDepth) - 1) / (__nWidth - 1));
294}
#define __DCL_ASSERT(expr)
Definition Object.h:394

◆ MessageTree() [2/2]

MessageTree::MessageTree ( int nDepth,
int nWidth )

Definition at line 296 of file MessageTree.cpp.

297{
298 __DCL_ASSERT(nWidth >= 2);
299 __DCL_ASSERT(nDepth >= 2);
300
301 __nWidth = nWidth;
302 __nDepth = nDepth;
303
304 __nMinReplyID = 1;
305 __nMaxReplyID = ((POWER(__nDepth) - 1) / (__nWidth - 1));
306}

Member Function Documentation

◆ depth()

int MessageTree::depth ( ) const
inline

Definition at line 91 of file MessageTree.h.

92{
93 return __nDepth;
94}

◆ getChildID()

int64_t MessageTree::getChildID ( int64_t nReplyID,
int nWidthIndex ) const

Definition at line 407 of file MessageTree.cpp.

408{
409 __DCL_ASSERT(0 <= nReplyID);
410 __DCL_ASSERT(0 <= nWidthIndex && nWidthIndex < __nWidth);
411
412 Position rPos;
413 getPosition(nReplyID, rPos);
414
415 __DCL_ASSERT(rPos.nDepthIndex < __nDepth);
416
417 return nReplyID + 1 + getSiblingGap(rPos.nDepthIndex + 1) * nWidthIndex;
418}
void getPosition(int64_t nReplyID, Position &rPos) const
int64_t getSiblingGap(int nDepthIndex) const

◆ getDefaultWidth()

int MessageTree::getDefaultWidth ( int nDepth)
static

Definition at line 263 of file MessageTree.cpp.

264{
265 __DCL_ASSERT(2 <= nDepth && nDepth <= 17);
266
267 return __aWidth[nDepth - 2];
268}

◆ getFirstChildID()

int64_t MessageTree::getFirstChildID ( int64_t nReplyID) const

Definition at line 378 of file MessageTree.cpp.

379{
380 __DCL_ASSERT(0 <= nReplyID);
381 return nReplyID + 1;
382}

◆ getLastChildID()

int64_t MessageTree::getLastChildID ( int64_t nReplyID) const

Definition at line 384 of file MessageTree.cpp.

385{
386 __DCL_ASSERT(0 <= nReplyID);
387
388 Position rPos;
389 getPosition(nReplyID, rPos);
390
391 __DCL_ASSERT(rPos.nDepthIndex < (__nDepth - 1));
392
393 // nReplyID + 전체 자식노드의 개수 중 직 하위의 (nWidth - 1)/__nWidth
394 // POWER(__nDepth - rPos.nDepthIndex) / (__nWidth - 1)
395 // * (__nWidth - 1) / __nWidth
396
397 return nReplyID
398 + POWER(__nDepth - rPos.nDepthIndex) / __nWidth;
399
400 /*
401 // FirstChildID + 자식노드의 간격 * (__nWidth - 1)의 개수
402 return nReplyID + 1
403 + getSiblingGap(rPos.nDepthIndex + 1) * (__nWidth - 1);
404 */
405}

◆ getPosition()

void MessageTree::getPosition ( int64_t nReplyID,
Position & rPos ) const

Definition at line 332 of file MessageTree.cpp.

336{
337 __DCL_ASSERT(__nMinReplyID <= nReplyID); // 0 < nReplyID
338 __DCL_ASSERT(nReplyID <= __nMaxReplyID);
339
340 rPos.nParentID = 0;
341 rPos.nDepthIndex = 0;
342 rPos.nWidthIndex = 0;
343
344 int64_t __n = nReplyID - 1;
345 if (__n == 0) {
346 // 시작글(최상위 노드) ==> (0, 0)
347 return;
348 }
349
350 for(int i = 1; i < __nDepth; i++) {
351 // i == 1 ==> 0번째, 즉, 최상위 노드는 건너뛴다.
352 --__n;
353 int64_t nGap = getSiblingGap(i);
354 if (nGap > 1) {
355 int64_t nRemainder = __n % nGap;
356 if (nRemainder == 0) {
357 // nDepthIndex가 결정되었다.
358 rPos.nDepthIndex = i;
359 rPos.nWidthIndex = (int)(__n / nGap);
360 rPos.nParentID = nReplyID - (nGap * rPos.nWidthIndex) - 1;
361
362 break;
363 }
364
365 // tree의 가장 좌측으로 이동한다.
366 __n = nRemainder;
367 }
368 else {
369// __DCL_TRACE2(L"i[%d], __n[%lld]\n", i, __n);
370 rPos.nDepthIndex = i;
371 rPos.nWidthIndex = (int)__n;
372 rPos.nParentID = nReplyID - (nGap * rPos.nWidthIndex) - 1;
373 break;
374 }
375 }
376}

◆ getSiblingGap()

int64_t MessageTree::getSiblingGap ( int nDepthIndex) const

Definition at line 318 of file MessageTree.cpp.

319{
320 __DCL_ASSERT(nDepthIndex >= 0);
321
322 // 형제노드간의 간격
323 // 전체 노드의 개수 중 nDepthIndex - 1 까지의 개수를 뺀 값에서
324 // nDepthIndex 까지의 개수로 나눈 값
325 if (nDepthIndex > 0)
326 return (__nMaxReplyID - POWER(nDepthIndex - 1))
327 / POWER(nDepthIndex);
328 else
329 return __nMaxReplyID;
330}

◆ maxReplyID()

int64_t MessageTree::maxReplyID ( ) const

Definition at line 313 of file MessageTree.cpp.

314{
315 return __nMaxReplyID;
316}

◆ minReplyID()

int64_t MessageTree::minReplyID ( ) const

Definition at line 308 of file MessageTree.cpp.

309{
310 return __nMinReplyID;
311}

◆ width()

int MessageTree::width ( ) const
inline

Definition at line 96 of file MessageTree.h.

97{
98 return __nWidth;
99}

The documentation for this class was generated from the following files: