Skip to content

Commit c740c39

Browse files
added kavll_size()
1 parent 5aa0a28 commit c740c39

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

kavl-lite.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,21 @@ int main(void) {
236236
} \
237237
} while (0)
238238

239+
#define kavll_size(__type, __head, __root, __cnt) do { \
240+
__type *_p, *_q; \
241+
*(__cnt) = 0; \
242+
for (_p = __root; _p; _p = _q) { \
243+
if (_p->__head.p[0] == 0) { \
244+
_q = _p->__head.p[1]; \
245+
++*(__cnt); \
246+
} else { \
247+
_q = _p->__head.p[0]; \
248+
_p->__head.p[0] = _q->__head.p[1]; \
249+
_q->__head.p[1] = _p; \
250+
} \
251+
} \
252+
} while (0)
253+
239254
#define __KAVLL_ITR(pre, __scope, __type, __head, __cmp) \
240255
typedef struct pre##_itr_t { \
241256
const __type *stack[KAVLL_MAX_DEPTH], **top, *right; /* _right_ points to the right child of *top */ \

0 commit comments

Comments
 (0)