bool predecessor(const Key& k, Key& pre) { BSTNode* cur = find_rec(this->root_, k); if (cur == nullptr) return false; BSTNode* pre_node = predecessor(cur); if (pre_node != nullptr) pre = pre_node->key_; return pre_node != nullptr; }
bool successor(const Key& k, Key& suc) { BSTNode* cur = find_rec(this->root_, k); if (cur == nullptr) return false; BSTNode* suc_node = successor(cur); if (suc_node != nullptr) suc = suc_node->key_; return suc_node != nullptr; }
int delete_leaf (tree_s *tree, leaf_s *leaf, u32 key) { rec_s *r; FN; r = find_rec(leaf, key); if (r) { leaf->l_total += sizeof(rec_s) + r->r_size; memmove(r, r + 1, (char *)&leaf->l_rec[--leaf->l_num] - (char *)r); return 0; } eprintf("Key not found %llx\n", key); return qERR_NOT_FOUND; }
void delete_leaf (leaf_s *leaf, u64 key) { rec_s *r; FN; r = find_rec(leaf, key); if (r) { leaf->l_total += sizeof(rec_s) + r->r_len; memmove(r, r + 1, (char *)&leaf->l_rec[--leaf->l_num] - (char *)r); bdirty(leaf); return; } printf("Key not found %llu\n", key); exit(2); }
ColMsg * ColMsg::find_rec(const QString & hr, ColMsgList & top) { Q3PtrListIterator<ColMsg> it(top); int index; for (index = 0; it.current(); ++it, index += 1) { if (it.current()->hierarchical_rank == hr) return it.current(); ColMsg * result = find_rec(hr, it.current()->msgs); if (result != 0) return result; } return 0; }
static void libdef_rec(BuildCtx *ctx, char *p, int arg) { UNUSED(arg); if (ctx->mode == BUILD_recdef) { char *q; uint32_t n; for (; recffid+1 < ffid; recffid++) fprintf(ctx->fp, ",\n0"); recffid = ffid; if (*p == '.') p = funcname; q = strchr(p, ' '); if (q) *q++ = '\0'; n = find_rec(p); if (q) fprintf(ctx->fp, ",\n0x%02x00+(%s)", n, q); else fprintf(ctx->fp, ",\n0x%02x00", n); } }
BSTNode* find_rec(BSTNode* cur, const Key& k) { if (cur == nullptr || cur->key_ == k) return cur; if (k < cur->key_) return find_rec(cur->left_, k); return find_rec(cur->right_, k); }
void remove(const Key& k) { BSTNode* cur = find_rec(this->root_, k); remove_rec(cur); }