static spltreeNode_t* insert_r(spltreeNode_t* current, spltreeNode_t* item, uint8_t* context) { if (!current) { *context = 0; return item; } uint8_t direction = *context; if (current->key <= item->key) { *context = RIGHT; current->right = insert_r(current->right, item, context); if (*context == ZIGZIG_STEP) { *context = direction; return rotateLeft(rotateLeft(current)); } if (*context == ZIGZAG_STEP) { *context = direction; current->right = rotateRight(current->right); return rotateLeft(current); } if (direction == ROOT) return rotateLeft(current); if (current->right == item) { *context = direction == RIGHT ? ZIGZIG_STEP : ZIGZAG_STEP; return current; } return current; } else { *context = LEFT; current->left = insert_r(current->left, item, context); if (*context == ZIGZIG_STEP) { *context = direction; return rotateRight(rotateRight(current)); } if (*context == ZIGZAG_STEP) { *context = direction; current->left = rotateLeft(current->left); return rotateRight(current); } if (direction == ROOT) return rotateRight(current); if (current->left == item) { *context = direction == LEFT ? ZIGZIG_STEP : ZIGZAG_STEP; return current; } return current; } }
void output_deque() { int option,val; clrscr(); do{ printf("\n ********** output deque menu ********"); printf("\n 1.insert at right"); printf("\n 2. insert at left"); printf("\n 3. delete from left"); printf("\n 4. display"); printf("\n enter your choice"); scanf("%d",&option); switch(option) { case 1: printf("\n enter value to be inserted from right"); scanf("%d",&val); insert_r(val); break; case 2: printf("\n enter value to be inserted from left"); scanf("%d",&val); insert_f(val); break; case 3: val=delete_f(); if(val!=-999) printf("\n value deleted from left is = %d",val); break; case 4: display(); break; default: printf("\n wroung statement"); } }while(option<=4 && option>=1); }
void insert_r(BST B,node n, void *item ){ if (B->compare( item,n->item) > 0) { // maggiore if (n->right == NULL) { n->right=newNode(item,n); return; }else{ insert_r(B, n->right, item); } }else{ if (n->left == NULL) { n->left = newNode(item,n); return; }else{ insert_r(B, n->left, item); } } }
void superposition::insert(clause * cls) { unsigned num_lits = cls->get_num_literals(); for (unsigned i = 0; i < num_lits; i++) { literal & l = cls->get_literal(i); if (l.is_p_indexed() || cls->is_eligible_for_paramodulation(m_order, l)) { if (!l.sign() && m_manager.is_eq(l.atom())) insert_p(cls, l, i); insert_r(cls, l, i); } else if (l.is_r_indexed() || cls->is_eligible_for_resolution(m_order, l)) { insert_r(cls, l, i); } } TRACE("superposition_detail", tout << "adding clause: "; cls->display(tout, m_manager); tout << "\n"; tout << "p index:\n"; m_p.display(tout); tout << "r index:\n"; m_r.display(tout););
int BST_insert(BST B, void * item){ if (B->root== NULL) { B->root = newNode(item,NULL); return 1; } insert_r(B, B->root, item); return 1; }
void cdsl_spltreeInsert(spltreeRoot_t* root, spltreeNode_t* item) { if (!root) return; if (!root->entry) { root->entry = item; return; } uint8_t context; context = ROOT; root->entry = insert_r(root->entry, item, &context); }
//Inserting a node, recursive version //NOTE: Since inserting a node can rebalance the tree, ensure that NO processing occurs // after any recursive call. node* insert_r(Key key, nall::linear_vector<node*>& parentStack, node* curr, size_t nodeHeight) { //Base case: No more nodes if (!curr) { //If nothing found, this is the valid position for a new node. realSize++; maxSize = realSize>maxSize?realSize:maxSize; curr = new node(key); //Add to the parent node* parent = parentStack[parentStack.size()-1]; node*& parentPtr = !parent?root:key<parent->key?parent->left:parent->right; parentPtr = curr; //Balance; check threshhold. Note that nodeHeight should _not_ be incremented here. if (autoBalance && realSize>=minRebalanceSize) { //From Rivest's paper: We know the tree is not height-balanced if: size_t thresh = logA.log(realSize); if (nodeHeight>thresh) { //NOTE: This will rebalance the tree; do NOTHING except return after this. findAndBalanceScapegoat(parentStack, curr, 1, 0); } } return curr; } //Base case: Node found if (curr->key==key) { //"Insert" here means inserting a node that already exists, so we // don't need to check for a scapegoat. return curr; } //Recursive case parentStack.append(curr); if (key<curr->key) { return insert_r(key, parentStack, curr->left, nodeHeight+1); } else { return insert_r(key, parentStack, curr->right, nodeHeight+1); } }
void superposition::insert_r(clause * cls, literal & l, unsigned i) { l.set_r_indexed(true); expr * atom = l.atom(); if (m_manager.is_eq(atom)) { expr * lhs = l.lhs(); expr * rhs = l.rhs(); if (l.is_oriented()) { bool left = true; if (!l.is_left()) { left = false; std::swap(lhs, rhs); } insert_r(cls, lhs, i, left); } else { insert_r(cls, lhs, i, true); insert_r(cls, rhs, i, false); } } else { insert_r(cls, atom, i, false); } m_subst.reserve_vars(m_r.get_approx_num_regs()); }
void insert(Key key, Data value) { nall::linear_vector<node*> parentStack; parentStack.append(nullptr); insert_r(key, parentStack, root, 0)->data = value; }