Rectangle::Rectangle(float Left, float Bottom, float Width, float Height) { set_left ( Left ); set_right ( Left + Width ); set_top ( Bottom + Height ); set_bottom( Bottom ); }
static void set_child(struct bstree_node *child, struct bstree_node *node, int left) { if (left) set_left(child, node); else set_right(child, node); }
void state_pause() { while(1) { set_left(0); set_right(0); while(!wireless_buffer_f); wireless_buffer_f = false; switch(wireless_buffer[0]) { case PLAY: state_play(); break; case DETANGLE: state_detangle(); break; case GOALA: event_goal('a'); break; case GOALB: event_goal('b'); break; } } }
Rectangle::Rectangle() { set_left ( 0. ); set_right ( 0. ); set_top ( 0. ); set_bottom( 0. ); }
int main(void) { int x; struct data d; struct tree *t,*p,*q; d.val = value[0]; t = alloc_tree(&d); //root node x=1; while(value[x]!=0){ d.val = value[x]; p = t; /* get to the leaf */ while(p!=NULL){ q = p; //Remember the last valid p if(d.val > p->d.val) p = right(p); else p = left(p); } if(d.val > q->d.val) set_right(q,&d); else set_left(q,&d); x++; } inorder_trav(t); return 0; }
static off_t del_push(brtr_t *b, off_t r, size_t size, off_t id) /* puts a node in the delete tree */ { struct brtr_node *n; struct brtr_node *m; if ((n = brtr_node(b, r)) != NULL) { size_t ns = node_size(n->ksize, n->vsize); if (size < ns) r = set_left(b, r, del_push(b, n->left, size, id)); else if (size > ns) r = set_right(b, r, del_push(b, n->right, size, id)); else { /* a node of this size already exist; enqueue to its stree */ m = brtr_node(b, id); m->stree = n->stree; n->stree = id; } } else { m = brtr_node(b, id); m->left = m->right = m->stree = 0; m->c = 1; r = id; } return r; }
static off_t del_pull(brtr_t *b, off_t r, size_t size, off_t *id) /* pulls a node with the specified size from the delete queue */ { struct brtr_node *n; if ((n = brtr_node(b, r)) != NULL) { size_t ns = node_size(n->ksize, n->vsize); if (size < ns) r = set_left(b, r, del_pull(b, n->left, size, id)); else if (size > ns) r = set_right(b, r, del_pull(b, n->right, size, id)); else { struct brtr_node *m; /* found; does the node has an stree of equal nodes? */ if ((m = brtr_node(b, n->stree)) != NULL) { *id = n->stree; n->stree = m->stree; } else { /* unique node: return it */ *id = r; r = merge_nodes(b, n->left, n->right); } } } return r; }
struct bstree_node *bstree_insert(struct bstree_node *node, struct bstree *tree) { struct bstree_node *key, *parent; int is_left; key = do_lookup(node, tree, &parent, &is_left); if (key) return key; if (!parent) { INIT_NODE(node); tree->root = tree->first = tree->last = node; return NULL; } if (is_left) { if (parent == tree->first) tree->first = node; set_prev(get_prev(parent), node); set_next(parent, node); set_left(node, parent); } else { if (parent == tree->last) tree->last = node; set_prev(parent, node); set_next(get_next(parent), node); set_right(node, parent); } return NULL; }
void state_detangle() { m_red(ON); set_left(-90); set_right(-50); m_wait(2000); m_red(OFF); set_left(0); set_right(0); char transition = wireless_buffer[0]; switch(transition) { case 0xA1: state_play(); return; } }
void set_car(unsigned int FB, unsigned int LR, unsigned long fast, unsigned long slow) { if (FB){ set_back(); } else { set_go(); } if (LR){ set_left(slow); set_right(fast); } else { set_left(fast); set_right(slow); } }
struct splaytree_node *splaytree_insert(struct splaytree_node *node, struct splaytree *tree) { struct splaytree_node *root = tree->root; int res; if (!root) { INIT_NODE(node); tree->root = node; tree->first = node; tree->last = node; return NULL; } res = do_splay(node, tree); if (res == 0) return tree->root; root = tree->root; if (res < 0) { struct splaytree_node *left = get_left(root); set_left(left, node); set_right(root, node); if (left) set_next(node, get_last(left)); else tree->first = node; set_prev(node, root); } else { struct splaytree_node *right = get_right(root); set_right(right, node); set_left(root, node); if (right) set_prev(node, get_first(right)); else tree->last = node; set_next(node, root); } tree->root = node; return NULL; }
FractalProto * Fractal::serialize() { auto fp = new FractalProto(); fp->set_bottom(bottom); fp->set_height(height); fp->set_left(left); fp->set_right(right); fp->set_width(width); fp->set_top(top); fp->set_maxiter(maxiter); return fp; }
static inline void rotate_right(struct splaytree_node *node) { struct splaytree_node *left = get_left(node); /* can't be NULL */ struct splaytree_node *r = get_right(left); if (r) set_left(r, node); else set_prev(left, node); set_right(node, left); }
static inline void rotate_left(struct splaytree_node *node) { struct splaytree_node *right = get_right(node); /* can't be NULL */ struct splaytree_node *l = get_left(right); if (l) set_right(l, node); else set_next(right, node); set_left(node, right); }
Node::Node(const Node& src_node) { data = src_node.data; count = src_node.count; if( src_node.left ) { Node *new_left = new Node(*(src_node.left)); set_left(new_left); } if( src_node.right ) { Node *new_right = new Node(*(src_node.right)); set_right(new_right); } }
void tree_cloner::visit_impl(const binary_mult* v) { v->left()->accept(this); auto newleft = cloned_; v->right()->accept(this); auto newright = cloned_; auto& ar = root_->get_arena(); auto newbinop = ar.create<binary_mult>(); newbinop->set_left(newleft); newbinop->set_right(newright); cloned_ = newbinop; }
void rblist::right_rotate(void *item) { void *x, *y; y = item; x = left(y); set_left(y, right(x)); if (right(x)) { set_parent(right(x), y); } set_parent(x, parent(y)); /* if no parent then we have a new head */ if (!parent(y)) { head = x; } else if (y == left(parent(y))) { set_left(parent(y), x); } else { set_right(parent(y), x); } set_right(x, y); set_parent(y, x); }
/* x is item, y is below and to right, then rotated to below left */ void rblist::left_rotate(void *item) { void *y; void *x; x = item; y = right(x); set_right(x, left(y)); if (left(y)) { set_parent(left(y), x); } set_parent(y, parent(x)); /* if no parent then we have a new head */ if (!parent(x)) { head = y; } else if (x == left(parent(x))) { set_left(parent(x), y); } else { set_right(parent(x), y); } set_left(y, x); set_parent(x, y); }
Node tree_create(int key, void* value, int elementSize, Node left, Node right) { assert(value); assert(elementSize > 0); Node node = malloc(sizeof(*node)); assert(node); set_key(node, key); set_value(node, value, elementSize); set_elementSize(node, elementSize); set_left(node, left); set_right(node, right); return node; }
void tree_cloner::visit_impl(const assign* v) { v->var()->accept(this); auto newvar = reinterpret_cast<variable*>(cloned_); v->right()->accept(this); auto newval = cloned_; auto& ar = root_->get_arena(); auto newasgn = ar.create<assign>(); newasgn->set_left(newvar); newasgn->set_right(newval); auto ty = symbol_table::lookup(curr_->table(), v->var()).type; symbol_table::set(root_->table(), newvar, newval, ty); cloned_ = newasgn; }
void sniper() { init_all(); // set voltage reference to 5V clear(ADMUX, REFS1); set(ADMUX, REFS0); m_disableJTAG();//allowing gpio of F pins //setting ADC prescaler set(ADCSRA,ADPS2); set(ADCSRA,ADPS1); set(ADCSRA,ADPS0); //setting pins to turn off digital circuitry set(DIDR0,ADC1D);//setting F1 set(DIDR0,ADC4D);//setting F4 set(DIDR0,ADC5D);//setting F5 set(DIDR0,ADC6D);//setting F6 set(DIDR0,ADC7D);//setting F7 set(ADCSRA, ADEN); play_state = 1; set_position(1024/2, 768/2); first = true; //state_before_game(); //state_play(); m_usb_init(); /* while(!m_usb_isconnected()); m_green(ON); */ set_left(30); set_right(100); while(1) { adc(); // m_usb_tx_string("left: "); //m_usb_tx_int(a_left); wait(1); } }
void InputMessage::MergeFrom(const InputMessage& from) { GOOGLE_CHECK_NE(&from, this); if (from._has_bits_[0 / 32] & (0xffu << (0 % 32))) { if (from.has_ahead()) { set_ahead(from.ahead()); } if (from.has_back()) { set_back(from.back()); } if (from.has_left()) { set_left(from.left()); } if (from.has_right()) { set_right(from.right()); } } mutable_unknown_fields()->MergeFrom(from.unknown_fields()); }
void orderStartRightTurn(void) { set_right(MOTOR_DEFAULT_TURN_SPEED,MOTOR_DEFAULT_TURN_SPEED); setOrderTargetTicks(MOTOR_RIGHT_TICKS); setOrderActive(); switch(MP.heading_state) { case(PLATFORM_HEADING_XNEG): MP.heading_state = PLATFORM_HEADING_YPOS; break; case(PLATFORM_HEADING_XPOS): MP.heading_state = PLATFORM_HEADING_YNEG; break; case(PLATFORM_HEADING_YNEG): MP.heading_state = PLATFORM_HEADING_XNEG; break; case(PLATFORM_HEADING_YPOS): MP.heading_state = PLATFORM_HEADING_XPOS; break; } }
/* Destroy the tree contents. Not totally working */ void rblist::destroy() { void *x, *y = NULL; x = first(); // printf("head=%p first=%p left=%p right=%p\n", head, x, left(x), right(x)); for ( ; (y=any(x)); ) { /* Prune the last item */ if (parent(x)) { if (x == left(parent(x))) { set_left(parent(x), NULL); } else if (x == right(parent(x))) { set_right(parent(x), NULL); } } if (!left(x) && !right(x)) { if (head == x) { head = NULL; } // if (num_items<30) { // printf("free nitems=%d item=%p left=%p right=%p\n", num_items, x, left(x), right(x)); // } free((void *)x); /* free previous node */ num_items--; } x = y; /* save last node */ } if (x) { if (x == head) { head = NULL; } // printf("free nitems=%d item=%p left=%p right=%p\n", num_items, x, left(x), right(x)); free((void *)x); num_items--; } if (head) { // printf("Free head\n"); free((void *)head); } // printf("free nitems=%d\n", num_items); head = NULL; }
int rotate(double theta) { if(theta < pi / 2 || theta > 3*pi/2 ) { if(theta < -pi/2) { set_left(20); set_right(-20); return 1; } if(theta < -pi / 4) { set_left(20); set_right(-20); return 2; } if(theta < -pi / 8) { set_left(15); set_right(-15); return 3; } } else { if(theta > pi/2) { set_left(-20); set_right(20); return 1; } if(theta > pi / 4) { set_left(-20); set_right(20); return 2; } if(theta > pi / 8) { set_left(-15); set_right(15); return 3; } } return 0; }
std::unique_ptr<Expression> AssignmentParser::parse(ElsaParser* parser, std::unique_ptr<Expression> left) { parser->consume(TokenType::Equals); auto exp = std::make_unique<AssignmentExpression>(); exp->set_left(std::move(left)); assert_valid_assignment(parser, exp->get_left()); exp->set_right(std::move(parser->parse_expression(precedence()))); auto left_type = std::unique_ptr<ElsaType>(parser->type_checker().get_expression_type(exp->get_left())); if(!parser->type_checker().valid_assignment(exp.get())) throw ParsingException(L"Invalid assignment. The right hand side of the expression must be of type '" + left_type->get_name() + L"'", parser->current_token()); if(parser->current_token()->get_type() == TokenType::Semicolon) parser->consume(TokenType::Semicolon); return std::move(exp); }
void state_detangle() { while(1) { set_left(-30); set_right(-30); while(!wireless_buffer_f); wireless_buffer_f = false; char inst = wireless_buffer[0]; switch(inst) { case PAUSE: state_pause(); return; case PLAY: state_play(); return; default: break; } } }
void state_pause() { set_left(0); set_right(0); while(!wireless_buffer_f); wireless_buffer_f = false; char inst = wireless_buffer[0]; switch(inst) { case 0xA4: state_pause(); return; case 0xA1: state_play(); return; case 0xA5: state_detangle(); return; default: state_pause(); return; } }
static off_t merge_nodes(brtr_t *b, off_t left, off_t right) { off_t id = 0; struct brtr_node *l; if ((l = brtr_node(b, left)) != NULL) { struct brtr_node *r; if ((r = brtr_node(b, right)) != NULL) { if (l->c > r->c) id = set_right(b, left, merge_nodes(b, l->right, right)); else id = set_left(b, right, merge_nodes(b, left, r->left)); } else id = left; } else id = right; return id; }
void splaytree_remove(struct splaytree_node *node, struct splaytree *tree) { struct splaytree_node *right, *left, *prev; do_splay(node, tree); assert(tree->root == node); /* 'node' must be present */ right = get_right(node); left = get_left(node); if (!left) { tree->root = right; tree->first = splaytree_next(node); prev = NULL; } else { tree->root = left; do_splay(node, tree); set_right(right, tree->root); prev = tree->root; } if (right) set_prev(prev, get_first(right)); else tree->last = prev; }