sp<MonBase> MonDiskstats::depth(int no, uint64_t sec, sp<MonBase>& old_) { sp<MonDiskstats> old = old_; sp<MonDiskstats> ret = create(sec); sp<Data> d, c, o; for( int k=0; k<m_aLists.size(); k++){ d = new Data(); c = m_aLists.get(k); o = old->getData(k); d->m_type = c->m_type; d->m_devtype = c->m_devtype; d->m_sName = c->m_sName; depth_l(no, d, c, o); ret->m_aLists.insert(d); } d = ret->m_all; c = m_all; o = old->m_all; depth_l(no, d, c, o); return ret; }
void avl_check_balance(TREE *tree) { if (tree->root) { assert( !IS_DEEPER(tree->root)); if (IS_X(tree)) depth_x(tree->x_root, true); else depth_l(tree->l_root, true); } }
int avl_depth(TREE *tree) { if (tree->root) { if (IS_X(tree)) return depth_x(tree->x_root, false); else return depth_l(tree->l_root, false); } else { return 0; } }
static int depth_l(L_NODE *root, bool check) { int depth_left, depth_right; depth_left = root->left ? depth_l(PTR_OF(root->left ), check) : 0; depth_right = root->right ? depth_l(PTR_OF(root->right), check) : 0; if (check) { assert(depth_left <= depth_right + 1); assert(depth_right <= depth_left + 1); if (depth_left > depth_right) { assert( IS_DEEPER(root->left )); assert( !IS_DEEPER(root->right)); } else if (depth_left < depth_right) { assert( !IS_DEEPER(root->left )); assert( IS_DEEPER(root->right)); } else { assert( !IS_DEEPER(root->left )); assert( !IS_DEEPER(root->right)); } } return (depth_left > depth_right ? depth_left : depth_right) + 1; }
void avl_dump_w_ctx(TREE *tree, void (*callback)(void *data, int idx, int bal, void *context), void *context) { if (tree->root) { int max_depth = 0; int idx, idx_top; void **data_v; int *bal_v; if (IS_X(tree)) max_depth = depth_x(PTR_OF(tree->x_root), false); else max_depth = depth_l(PTR_OF(tree->l_root), false); idx_top = 1 << max_depth; data_v = calloc(idx_top, sizeof(void*)); bal_v = calloc(idx_top, sizeof(int)); if (IS_X(tree)) prepare_for_dump_x(PTR_OF(tree->x_root), 1, data_v, bal_v); else prepare_for_dump_l(PTR_OF(tree->l_root), 1, data_v, bal_v); for (idx = 1; idx < idx_top; idx++) { (*callback)(data_v[idx], idx, bal_v[idx], context); } free(data_v); free(bal_v); } else { (*callback)(NULL, 1, 0, context); } }