7#if __DCL_HAVE_THIS_FILE__
15#define __I64(c) c##I64
20static int64_t __POWER(
int nBase,
int nExponent)
33static const int __aWidth[16] = {
35 2147483646, 2097151, 55108, 6208, 1448, 511, 234, 127,
37 78, 52, 38, 28, 22, 18, 15, 13
40static const int64_t __aPower[16][18] = {
44 __I64(4611686014132420609),
51 __I64(9223358842721533951),
58 __I64(167357025819712),
59 __I64(9222710978872688896),
67 __I64(1485274869661696),
68 __I64(9220586390859808768),
77 __I64(6365650776915968),
78 __I64(9217462324974321664),
87 __I64(34842114263551),
88 __I64(17804320388674561),
89 __I64(9098007718612700671),
99 __I64(164170508913216),
100 __I64(38415899085692544),
101 __I64(8989320386052055296),
111 __I64(4195872914689),
112 __I64(532875860165503),
113 __I64(67675234241018881),
114 __I64(8594754748609397887),
125 __I64(17565568854912),
126 __I64(1370114370683136),
127 __I64(106868920913284608),
128 __I64(8335775831236199424),
139 __I64(1028071702528),
140 __I64(53459728531456),
141 __I64(2779905883635712),
142 __I64(144555105949057024),
143 __I64(7516865509350965248),
155 __I64(4347792138496),
156 __I64(165216101262848),
157 __I64(6278211847988224),
158 __I64(238572050223552512),
159 __I64(9065737908494995456),
173 __I64(10578455953408),
174 __I64(296196766695424),
175 __I64(8293509467471872),
176 __I64(232218265089212416),
177 __I64(6502111422497947648),
191 __I64(1207269217792),
192 __I64(26559922791424),
193 __I64(584318301411328),
194 __I64(12855002631049216),
195 __I64(282810057883082752),
196 __I64(6221821273427820544),
211 __I64(3570467226624),
212 __I64(64268410079232),
213 __I64(1156831381426176),
214 __I64(20822964865671168),
215 __I64(374813367582081024),
216 __I64(6746640616477458432),
232 __I64(8649755859375),
233 __I64(129746337890625),
234 __I64(1946195068359375),
235 __I64(29192926025390625),
236 __I64(437893890380859375),
237 __I64(6568408355712890625),
253 __I64(1792160394037),
254 __I64(23298085122481),
255 __I64(302875106592253),
256 __I64(3937376385699289),
257 __I64(51185893014090757),
258 __I64(665416609183179841),
259 __I64(8650415919381337933)
267 return __aWidth[nDepth - 2];
270inline int64_t MessageTree::POWER(
int nExponent)
const
272#ifdef __DEBUG_ALGORITHM
276 return __POWER(__nWidth, nExponent);
280 int64_t
r = __aPower[__nDepth - 2][nExponent];
289 __nWidth = __aWidth[nDepth - 2];
293 __nMaxReplyID = ((POWER(__nDepth) - 1) / (__nWidth - 1));
305 __nMaxReplyID = ((POWER(__nDepth) - 1) / (__nWidth - 1));
310 return __nMinReplyID;
315 return __nMaxReplyID;
326 return (__nMaxReplyID - POWER(nDepthIndex - 1))
327 / POWER(nDepthIndex);
329 return __nMaxReplyID;
344 int64_t __n = nReplyID - 1;
350 for(
int i = 1; i < __nDepth; i++) {
355 int64_t nRemainder = __n % nGap;
356 if (nRemainder == 0) {
410 __DCL_ASSERT(0 <= nWidthIndex && nWidthIndex < __nWidth);
429int main(
int argc,
char* argv[])
431 DCLInitialize(
NULL, 2);
436 out << L
"USAGE: " << argv[0] << L
" width depth [id]\n";
446 out << L
"width : " << nWidth
447 << L
"\ndepth : " << nDepth
448 << L
"\nrange : " << mt.minReplyID()
449 << L
" ~ " << mt.maxReplyID()
452 out << L
"\nleft:gap\n";
456 int64_t nParentID = 1;
457 for(nDepthIndex = 1; nDepthIndex < nDepth; nDepthIndex++) {
458 int64_t nID = mt.getFirstChildID(nParentID);
459 int64_t nGap = mt.getSiblingGap(nDepthIndex);
460 out << nDepthIndex << L
":" << nGap
462 for(
int i = 0; i < nCol; i++)
463 out << nID + nGap * i << L
" ";
466 out << L
" ... " << nID + nGap * (nWidth - 1) << L
"\n";
469 out << L
"\nrifht:gap\n";
472 for(nDepthIndex = 1; nDepthIndex < nDepth; nDepthIndex++) {
473 int64_t nID = mt.getLastChildID(nParentID);
474 int64_t nGap = mt.getSiblingGap(nDepthIndex);
475 out << nDepthIndex << L
":" << nGap
477 for(
int i = 0; i < nCol; i++)
478 out << nID - (nGap * (nCol - i - 1)) << L
" ";
488 mt.getPosition(nReplyID, rPos);
489 out << L
"\nID : " << nReplyID
496 out << L
"\nFirstChildID: " << mt.getFirstChildID(nReplyID)
497 << L
"\nLastChildID: " << mt.getLastChildID(nReplyID)
499 for(
int i = 0; (i < nWidth && i < 5); i++)
500 out << L
"\n" << i << L
"-st ChildID: "
501 << mt.getChildID(nReplyID, i);
#define __DCL_ASSERT(expr)
String toStringAll() const
static int64_t parse(const wchar_t *_number, unsigned _base=10) __DCL_THROWS1(NumericConvertException *)
int64_t minReplyID() const
int64_t maxReplyID() const
int64_t getLastChildID(int64_t nReplyID) const
static int getDefaultWidth(int nDepth)
void getPosition(int64_t nReplyID, Position &rPos) const
int64_t getChildID(int64_t nReplyID, int nWidthIndex) const
int64_t getSiblingGap(int nDepthIndex) const
int64_t getFirstChildID(int64_t nReplyID) const
static unsigned int parse(const wchar_t *_number, unsigned _base=10) __DCL_THROWS1(NumericConvertException *)
int main(int argc, char *argv[])