Ejemplo n.º 1
0
void* linkedlist_remove(linkedlist _list, void* data)
{
    linkedlist_t* list = (linkedlist_t*) _list;
    node* n = find_by_data(list, data);

    if(NULL == n)
        return NULL;

    if(is_first(list, n)) // at the first
    {
        if(is_last(list, n)) // only one exists
        {
            set_head(list, NULL);
            set_tail(list, NULL);
        }
        else // one or more exist
        {
            set_head(list, get_next(n));
            set_prev(n, NULL);
        }
    }
    else if(is_last((linkedlist_t*)_list, n))
    {
        set_next(get_prev(n), NULL);
        set_tail(list, get_prev(n));
    }
    else
    {
        set_prev(get_next(n), get_prev(n));
        set_next(get_prev(n), get_next(n));
    }
    list->size--;
    free(n);
    return data;
}
Ejemplo n.º 2
0
void mem_available(long *empty, long *large, long *n_holes){
	long idx = 2;
	long next;
	long prev;
	
	*empty = MEM_SIZE - mem[0] - mem[1];
	
	*large = 0;
	*n_holes = 0;
	while(idx != 0){
		next = get_next(idx);
		prev = get_prev(idx);
		/* Blok is een gat als het vrij is en de omringende blokken zijn
		 * niet vrij of bestaan niet (als dit blok het eerste of laatste
		 * blok is) */
		if(get_free(idx) && (
				(next && prev && !get_free(next) && !get_free(prev))
				|| (!prev && next && !get_free(next))
				|| (!next && prev && !get_free(prev))
				|| (!next && !prev)
			)
		){
			if(get_length(idx) > *large){
				/* Nieuw grootste gat gevonden. */
				*large = get_length(idx);
			}
			*n_holes += 1;
		}
		
		idx = get_next(idx);
	}
}
Ejemplo n.º 3
0
/* Deze methode zet het blok op index op vrij, indien mogelijk fuseert het
 * met omringende vrije blokken. */
void free_block(long index){
	long prev = get_prev(index);
	long next = get_next(index);
	
	if(!get_free(index)){
		/* Zet het blok op vrij. */
		set_free(index, 1);
		mem[0] -= get_length(index);
	}
	
	/* Voeg vorige blok samen met het huidige als deze vrij is als een groot
	 * vrij blok. */
	if(prev != 0 && get_free(prev)){
		set_length(prev, get_length(prev) + get_length(index) + ADMIN_SIZE);
		set_next(prev, next);
		
		if(next != 0){
			set_prev(next, prev);
		}
		
		mem[1] -= ADMIN_SIZE;
	}
	
	/* Voeg volgende blok samen met het huidige als deze vrij is als een 
	 * groot vrij blok. */
	if(next != 0 && get_free(next)){
		free_block(next);
	}
}
Ejemplo n.º 4
0
void new_itunes_track()
{
	currentml = new_ml();
	currentml->get_next = get_next;
	currentml->get_prev = get_prev;
	currentml->get_text = get_text_track;
	currentml->select = select_track;
	currentml->get_track = get_track;

	if ((db_init((void *) draw_itunes_parse) < 0) || !tracks) {
		pz_close_window(currentml->wid);
		free(currentml);
		return;
	}

	printf("tracks->parent: %p\n ", ((struct btree_head *) tracks)->parent);
	currentml->user = (void *) btree_first((struct btree_head *) tracks);
	printf("currentml->prev: %p\n", ((struct btree_head *) currentml->user)->prev);
	printf("currentml name: %s\n", ((struct track *) currentml->user)->name);
	get_prev(currentml);
	printf("currentml->prev: %p\n", ((struct btree_head *) currentml->user)->prev);
	printf("currentml name: %s\n", ((struct track *) currentml->user)->name);

	itunes_draw(currentml);
}
Ejemplo n.º 5
0
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;
}
Ejemplo n.º 6
0
struct bstree_node *bstree_prev(const struct bstree_node *node)
{
	struct bstree_node *left = get_left(node);
	if (left)
		return get_last(left);
	return get_prev(node);
}
Ejemplo n.º 7
0
void *dlist::prev(void *item)
{
   if (item == NULL) {
      return tail;
   }
   return get_prev(item);
}
Ejemplo n.º 8
0
static int
lru_load(const br_ssl_session_cache_class **ctx,
	br_ssl_server_context *server_ctx,
	br_ssl_session_parameters *params)
{
	br_ssl_session_cache_lru *cc;
	unsigned char id[SESSION_ID_LEN];
	uint32_t x;

	(void)server_ctx;
	cc = (br_ssl_session_cache_lru *)ctx;
	if (!cc->init_done) {
		return 0;
	}
	mask_id(cc, params->session_id, id);
	x = find_node(cc, id, NULL);
	if (x != ADDR_NULL) {
		unsigned version;

		version = br_dec16be(cc->store + x + VERSION_OFF);
		if (version == 0) {
			/*
			 * Entry is disabled, we pretend we did not find it.
			 * Notably, we don't move it to the front of the
			 * LRU list.
			 */
			return 0;
		}
		params->version = version;
		params->cipher_suite = br_dec16be(
			cc->store + x + CIPHER_SUITE_OFF);
		memcpy(params->master_secret,
			cc->store + x + MASTER_SECRET_OFF,
			MASTER_SECRET_LEN);
		if (x != cc->head) {
			/*
			 * Found node is not at list head, so move
			 * it to the head.
			 */
			uint32_t p, n;

			p = get_prev(cc, x);
			n = get_next(cc, x);
			set_next(cc, p, n);
			if (n == ADDR_NULL) {
				cc->tail = p;
			} else {
				set_prev(cc, n, p);
			}
			set_prev(cc, cc->head, x);
			set_next(cc, x, cc->head);
			set_prev(cc, x, ADDR_NULL);
			cc->head = x;
		}
		return 1;
	}
	return 0;
}
Ejemplo n.º 9
0
int linkedlist_add_at(linkedlist _list, void* data, int i)
{
    linkedlist_t* list = (linkedlist_t*) _list;
    node* slider, *n;

    if(i > (list->size - 1))
        return add_at_last(list, data);

    if(i == 0)
        return add_at_first(list, data);
    else
    {
        slider = find_by_index(list, i);
        n = node_new(data);
        set_next(get_prev(slider), n);
        set_prev(n, get_prev(slider));
        set_next(n, slider);
        list->size++;
        return list->size;
    }
}
Ejemplo n.º 10
0
static void *
get_block(Size size)
{
	void *block;
	void *best = NULL;
	int best_size;

	SpinLockAcquire(&ShemDynAllocShmem->mutex);

	block = ShemDynAllocShmem->head;
	while (block)
	{
		Size block_size = get_size(block);
		if (size > block_size)
		{
			block = get_next(block);
			continue;
		}
		if (!best || best_size > block_size)
		{
			best = block;
			best_size = block_size;
		}
		block = get_next(block);
	}

	if (best)
	{
		void *prev;
		void *next;

		mark_allocated(best);
		prev = get_prev(best);
		next = get_next(best);

		if (!prev)
			ShemDynAllocShmem->head = next;
		else
			set_next(prev, next);
		if (!next)
			ShemDynAllocShmem->tail = prev;
		else
			set_prev(next, prev);
	}

	SpinLockRelease(&ShemDynAllocShmem->mutex);

	return best;
}
Ejemplo n.º 11
0
void insert_sorted(AList_WS* list, double data, cmp_func func) {
	assert(is_sorted(list,func) && "** UNABLE TO INSERT DATA SORTED WATY IN AN UNSORTED LIST **");

	size_t pos = list->next_data_addrs[HEAD];
	for (int i = 0; i < list->current_size; ++i) {
		double a = list->data[pos];
		double b = data;
		if (!func(a,b)) {
			insert_at_loc(list, get_prev(list,pos), pos, data);
			return;
		}
			
		pos = list->next_data_addrs[pos];
	}

}
Ejemplo n.º 12
0
    /**
     * \fn void get_vertex_star( unsigned i , std::vector< unsigned >& star ) const
     *
     * \brief Gets a list with the indices of all edges incident to
     * the i-th vertex.
     *
     * \param i The index of a surface patch vertex.
     * \param star A reference to a vector of edge indices.
     *
     */
    void get_vertex_star( unsigned i , std::vector< unsigned >& star ) const
    {
      assert( i < _patch_vts.size() ) ;

      unsigned eg1 = _patch_vts[ i ].get_edge() ;
      unsigned eg2 = eg1 ;
      bool endloop = false ;
      do {
	star.push_back( eg2 ) ;
	eg2 = get_prev( eg2 ) ;
	if ( is_boundary_edge( eg2 ) ) {
	  star.push_back( eg2 ) ;
	  endloop = true ;
	}
	else {
	  eg2 = get_mate( eg2 ) ;
	}
      }
      while ( ( eg2 != eg1 ) && !endloop ) ;

      return ;  
    }
Ejemplo n.º 13
0
bool marky::Backend_SQLite::get_prev(const State& state, selector_t selector,
        scorer_t scorer, const words_t& search_words, word_t& prev) {
#ifdef READ_DEBUG_ENABLED
    DEBUG("get_prev(%s)", str(search_words).c_str());
#endif
    if (!bind_words(stmt_get_prevs, 1, search_words)) {
        sqlite3_clear_bindings(stmt_get_prevs);
        sqlite3_reset(stmt_get_prevs);
        return false;
    }

    bool ok = true;
    snippets_ptr_t snippets(new snippet_ptr_set_t);
    for (;;) {
        int step = sqlite3_step(stmt_get_prevs);
        bool done = false;
        switch (step) {
            case SQLITE_DONE:
                done = true;
                break;
            case SQLITE_ROW:
                {
                    words_t words;
                    unpack((const char*)sqlite3_column_text(stmt_get_prevs, 0), words);
                    snippet_t snippet(new Snippet(words,
                                    sqlite3_column_int64(stmt_get_prevs, 1),
                                    sqlite3_column_int64(stmt_get_prevs, 2),
                                    sqlite3_column_int64(stmt_get_prevs, 3)));
                    snippets->insert(snippet);
                    break;
                }
            default:
                ok = false;
                ERROR("Error when parsing response to '%s': %d/%s",
                        QUERY_GET_PREVS, step, sqlite3_errmsg(db));
                break;
        }
        if (!ok || done) {
            break;
        }
    }
    sqlite3_clear_bindings(stmt_get_prevs);
    sqlite3_reset(stmt_get_prevs);

    if (snippets->empty()) {
        if (search_words.size() >= 2) {
            words_t search_words_shortened(search_words);
            search_words_shortened.pop_back();
#ifdef READ_DEBUG_ENABLED
            DEBUG("get_prev -> %s", str(search_words_shortened).c_str());
#endif
            /* recurse with shorter search */
            return get_prev(state, selector, scorer, search_words_shortened, prev);
        } else {
#ifdef READ_DEBUG_ENABLED
            DEBUG("    prev_snippet -> NOTFOUND");
#endif
            prev = IBackend::LINE_START;
        }
    } else {
        const words_t& prev_snippet = selector(*snippets, scorer, state)->words;
#ifdef READ_DEBUG_ENABLED
        for (snippet_ptr_set_t::const_iterator siter = snippets->begin();
             siter != snippets->end(); ++siter) {
            DEBUG("  prevs%s = snippet(%s, %lu)", str(search_words).c_str(),
                    str((*siter)->words).c_str(), (*siter)->score(scorer, state));
        }
        DEBUG("    prev_snippet -> %s", str(prev_snippet).c_str());
#endif
        prev = prev_snippet.front();
    }
    return ok;
}
Ejemplo n.º 14
0
int main() {
  int d,m,y;
  char query[1024];
  char *env;
  char *coord=NULL;
  char *search=NULL;
  char buf[1024];
  char *tmp;

  time_t t;
  struct tm *tt;

  time(&t);
  tt = localtime(&t);
  d = tt->tm_mday;
  m = tt->tm_mon+1;
  y = tt->tm_year+1900;

  env = getenv("QUERY_STRING");
  if (env) {
    char *s;
    s = strstr(env, "d="); if (s) sscanf(s, "d=%d", &d);
    s = strstr(env, "m="); if (s) sscanf(s, "m=%d", &m);
    s = strstr(env, "y="); if (s) sscanf(s, "y=%d", &y);
    s = strstr(env, "c="); 
    if (s) s+=2; else { // spatna kompatibilita so znackami
      s = strstr(env, "in=");
      if (s) s+=3;
    }
    if (s) {
      query[0]=0;
      sscanf(s, "%1000[^&]", query);
      coord=StringDecode(query);
    }
    s = strstr(env, "search="); 
    if (s) {
      query[0]=0;
      sscanf(s+7, "%1000[^&]", query);
      search = StringDecode(query);
    }
  }

  if (db_init()<0) return 1;

  printf("Content-Type: text/html; charset=UTF-8\n\n");

  printf("<html><head>\n"
      "<link rel=\"stylesheet\" href=\"breviar.css\">\n");

  Rst(&kontext);
  kontext_last_hb=kontext_last_he=-1;
  first.h=last.h=-1;

  if (coord) {
    printf("<title>%s</title>\n"
      "</head><body>\n"
      "<div class=\"nadpis\">%s</div>\n\n", coord, coord);
    kalendar = 0;
    scan_string(coord);
    yyparse();
    printf("<p>\n"
        "<form action=\"pismo.cgi\" method=\"get\">\n"
        "<input type=\"text\" name=\"c\">\n"
        "<input type=\"submit\" value=\"Zobraz\">\n"
        "</form>\n");
    {
      char *tmp = StringEncode(kontext.buf+1);
      printf(// "<p>\n"
          "<a href=\"pismo.cgi?c=%s\">Kontext</a>", tmp);
      free(tmp);
    }
    printf("&nbsp; &nbsp;");
    if (first.h!=-1) {
      char *b;
      int h;
      get_prev(first.k, first.h, &b, &h);
      if (b!=NULL) {
        snprintf(buf, sizeof(buf), "%s %d", b, h);
        tmp = StringEncode(buf);
        printf(// "<p>\n"
            "<a href=\"pismo.cgi?c=%s\">Dozadu (%s %d)</a>", tmp, b, h);
        free(tmp);
        free(b);
      }
    }
    printf("&nbsp; &nbsp;");
    if (last.h!=-1){
      char *b;
      int h;
      get_next(last.k, last.h, &b, &h);
      if (b!=NULL) {
        snprintf(buf, sizeof(buf), "%s %d", b, h);
        tmp = StringEncode(buf);
        printf(// "<p>\n"
            "<a href=\"pismo.cgi?c=%s\">Dopredu (%s %d)</a>", tmp, b, h);
        free(tmp);
        free(b);
      }
    }
    printf("<p>\n"
        "<form action=\"pismo.cgi\" method=\"get\">\n"
        "<input type=\"text\" name=\"search\">\n"
        "<input type=\"submit\" value=\"Hľadaj\">\n"
        "</form>\n");
  } else if (search) {
    char *b,*t;
    int h,v;

    printf("<title>Vyhľadávanie \"%s\"</title>\n"
        "</head><body>\n"
        "<div class=\"nadpis\">Vyhľadávanie \"%s\"</div>\n\n",
        search, search);

    fulltext_search(search);

    while (get_fulltext_result(&b, &h, &v, &t)) {
      int i,in,var;
      snprintf(buf, sizeof(buf), "%s%d", b,h);
      tmp = StringEncode(buf);
      printf("\n<p> <a href=\"pismo.cgi?c=%s\">%s%d", tmp, b, h);
      if (v!=-1) printf(",%d", v);
      printf("</a>: ");
      free(tmp);
      for (i=in=var=0; t[i]; i++) {
        if (t[i]=='<') {
          in = 1;
          if (!strncmp(t+i+1, "var>", 4)) var = 1;
          if (!strncmp(t+i+1, "/var>", 5)) var = 0;
        }
        if (!in && !var) printf("%c", t[i]);
        if (t[i]=='>') in = 0;
      }
    }

    printf("<p>\n"
        "<form action=\"pismo.cgi\" method=\"get\">\n"
        "<input type=\"text\" name=\"c\">\n"
        "<input type=\"submit\" value=\"Zobraz\">\n"
        "</form>\n");
    printf("<p>\n"
        "<form action=\"pismo.cgi\" method=\"get\">\n"
        "<input type=\"text\" name=\"search\">\n"
        "<input type=\"submit\" value=\"Hľadaj\">\n"
        "</form>\n");
    
    free_fulltext_search();
  } else {
    char *ct;
    if (!get_citania(y,m,d, &zalm, &ct)) return 3;

    kalendar = 1;

    //  printf("%s %s %s %s\n", row[0], row[1], row[2], row[3]);

    printf("<title>Čítania na %d.%d.%d</title>\n"
        "</head><body>\n"
        "<div class=\"nadpis\">Liturgické čítania na %d.%d.%d</div>\n\n",
        d,m,y,d,m,y);
    scan_string(ct);
    yyparse();

    /* toto asi nechceme
    {
      char *tmp = StringEncode(kontext.buf+1);
      printf("<p>\n"
          "<a href=\"pismo.cgi?c=%s\">Kontext</a>", tmp);
      free(tmp);
    }
    */

    free(zalm);
    free(ct);
  }
  printf("</body></html>\n");

  free_scan_string();

  db_close();
  return 0;
}
Ejemplo n.º 15
0
void shape_cd::draw ( draw_vars& dr, stack&, QGraphicsScene& sc)
{
  shapes* prev = get_prev();
  if(prev && prev->type()== QString("shape_e") && dr.drawAsHorisontal())
  {
    return;
  }
    if ( is_current() ) dr.draw_marker ( sc );

    int nSegments = get_n_segment();

    for ( int i = 0 ; i < nSegments; ++i )
    {
        draw_point p_start = dr.get_p_otn();   //Начальная точка сегмента дуги.
        draw_point delta_p = get_delta_p ( i ) * dr.get_masht() ;
        qreal C = abs ( get_c ( i ) );   //Значение параметра кривизны.
        qreal C_sign = get_c ( i ) / C; //Знак параметра кривизны.
        dr.move_coords ( delta_p );
        draw_point p_end = dr.get_p_otn();    //Конечная точка сегмента дуги.

        if (dr.drawWhisOutPenUpMovement() && !dr.get_pero()) ;
        else if ( get_c ( i ) != 0 )
        {
            qreal D = p_start.dist ( p_end );  //Расстояние между конечными точками сегмента.
            qreal H = C * D / qreal ( 2 ) / qreal ( 127 );   //Высота сегмента.
            qreal R = D * D / ( H * qreal ( 8 ) ) + H / qreal ( 2 ); //Радиус дуги.

            qreal ang = p_start.agnle ( p_end );
            draw_point p_mid_hord = p_start.polar ( ang, D / qreal ( 2 ) );
            draw_point p_center = p_mid_hord.polar ( ang + C_sign * M_PI / qreal ( 2 ), R - H );

            draw_point p_radius ( R, R );
            qreal ang_start = draw_point::rtd ( p_center.agnle ( p_start ) );
            qreal ang_4 = draw_point::rtd ( atan2 ( H, D / qreal ( 2 ) ) );
            qreal ang_number = C_sign * ang_4 * qreal ( 4 );
            if ( is_current() )
            {
                QPen pen( QBrush
                          ( QColor ( draw_vars::s_color_cur ), Qt::SolidPattern ),
                          qreal ( draw_vars::s_width_cur ) ,
                          Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin );
                pen.setCosmetic ( true );
                if ( i == get_current())
                    pen.setColor(QColor ( draw_vars::s_color_9d));
                else
                    pen.setColor(QColor ( draw_vars::s_color_cur));
                {
                    QPainterPath path;
                    path.arcMoveTo ( p_center.x - p_radius.x , p_center.y - p_radius.y , p_radius.x * 2, p_radius.y * 2,  -ang_start );
                    path.arcTo ( p_center.x - p_radius.x , p_center.y - p_radius.y , p_radius.x * 2, p_radius.y * 2,  -ang_start , -ang_number );
                    QGraphicsPathItem *pathItem = new QGraphicsPathItem ( path );
                    pathItem->setPen ( pen );
                    sc.addItem ( pathItem );
                }
            }
            else if ( dr.get_pero() )
            {
                QPen pen ( QBrush
                           ( QColor ( draw_vars::s_color_pen_down ), Qt::SolidPattern ),
                           qreal ( draw_vars::s_width_pen_down ) ,
                           Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin );

                pen.setCosmetic ( true );
                {
                    QPainterPath path;
                    path.arcMoveTo ( p_center.x - p_radius.x , p_center.y - p_radius.y , p_radius.x * 2, p_radius.y * 2,  -ang_start );
                    path.arcTo ( p_center.x - p_radius.x , p_center.y - p_radius.y , p_radius.x * 2, p_radius.y * 2,  -ang_start , -ang_number );
                    QGraphicsPathItem *pathItem = new QGraphicsPathItem ( path );
                    pathItem->setPen ( pen );
                    sc.addItem ( pathItem );
                }
            }
            else
            {
                QPen pen ( QBrush
                           ( QColor ( draw_vars::s_color_pen_up ), Qt::SolidPattern ),
                           qreal ( draw_vars::s_width_pen_up ) ,
                           Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin );

                pen.setCosmetic ( true );
                {
                    QPainterPath path;
                    path.arcMoveTo ( p_center.x - p_radius.x , p_center.y - p_radius.y , p_radius.x * 2, p_radius.y * 2,  -ang_start );
                    path.arcTo ( p_center.x - p_radius.x , p_center.y - p_radius.y , p_radius.x * 2, p_radius.y * 2,  -ang_start , -ang_number );
                    QGraphicsPathItem *pathItem = new QGraphicsPathItem ( path );
                    pathItem->setPen ( pen );
                    sc.addItem ( pathItem );
                }
            }

        }
        else
        {
            if ( dr.get_pero() )
            {
                QPen pen ( QBrush
                           ( QColor ( draw_vars::s_color_pen_down ), Qt::SolidPattern ),
                           qreal ( draw_vars::s_width_pen_down ) ,
                           Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin );
                pen.setCosmetic ( true );

                sc.addLine ( p_start.x, p_start.y, p_end.x, p_end.y, pen );
            }
            else
            {
                QPen pen ( QBrush
                           ( QColor ( draw_vars::s_color_pen_up ), Qt::SolidPattern ),
                           qreal ( draw_vars::s_width_pen_up ) ,
                           Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin );
                pen.setCosmetic ( true );

                sc.addLine ( p_start.x, p_start.y, p_end.x, p_end.y, pen );
            }
        }
    }
}
Ejemplo n.º 16
0
int main (int argc, char** argv)
{
    world_skeleton_t *s;
    map_t *map;
    announcer_t a;

    char* name = "mrscolumbo";

    brain_t* brain;

    if(argc>1)
    {
	    srand(argv[1][0]);
	    
    }

    a = init_announcer(stdout);
    announce_reg(a, name, PTYPE_COP_FOOT);

    s = parse_world_skeleton(stdin);

    //parser_print_world_skeleton(s);

    map = build_map(s);

    dprintf("NAME: %s\n", s->name);

    brain = create_brain(s->name, map);
    /*
    printf("dist: %d\n", get_dist(map, CHOOSE_FOOT,
				  node_index(map, "55-and-woodlawn"),
				  node_index(map, "54-and-ridgewood")));
    */


    for(;;)
    {
	world_message_t *m;
	node_line_t *my_node;
	cop_inform_msg_t* inform;
	cop_plan_msg_t* plans;
	cop_vote_msg_t* votes;
	vote_tally_t* tally;
	int bestdst;
	int* path;

	m = parse_world_message(s);
	
	announce_inform(a, NULL);

	if(!m->game_running)
		break; 

	my_node = player_node(m, map, s->name, 0); 

	update_brain(s, m, map, brain);
	
	inform = parse_inform_messages(s);
	free_inform_messages(inform);

	announce_plan(a, NULL);
	plans = parse_plan_messages(s);

	free_plan_messages(plans);
	
	votes = make_stupid_votes(s, brain);
	announce_vote(a, votes);
	free(votes);

	tally = parse_vote_tally(s);
	free_vote_tally(tally);


	bestdst = get_dest(s, m, map, brain);
	
	if(ada_kurds_here_p(s, m, map, brain))
	{
		bestdst = (rand()%(map->num_nodes));
	}


	//path = get_combined_prev(map, CHOOSE_FROM_PTYPE(brain->my_ptype), brain->my_pos);
	// ALERT
	path = get_prev(map, CHOOSE_FROM_PTYPE(brain->my_ptype), brain->my_pos);
	
	if(get_combined_switchp(map, CHOOSE_FROM_PTYPE(brain->my_ptype), brain->my_pos))
	{
		// ALERT
		//switch_transport(brain, map);
	}
	

	while(path[bestdst]!=brain->my_pos)
	{
		bestdst = path[bestdst];
	}

	announce_move(a, s, m, node_by_index(map, bestdst)->loc, brain->my_ptype);
    }
	

    return 0;
}
Ejemplo n.º 17
0
void bstree_remove(struct bstree_node *node, struct bstree *tree)
{
	struct bstree_node *left, *right, *next;
	struct bstree_node fake_parent, *parent;
	int is_left;

	do_lookup(node, tree, &parent, &is_left);

	if (!parent) {
		INIT_NODE(&fake_parent);
		parent = &fake_parent;
		is_left = 0;
	}
	left  = get_left(node);
	right = get_right(node);

	if (!left && !right) {
		if (is_left)
			set_prev(get_prev(node), parent);
		else
			set_next(get_next(node), parent);
		next = parent;
		goto update_first_last;
	}
	if (!left) {
		next = get_first(right);
		set_prev(get_prev(node), next);
		set_child(right, parent, is_left);
		goto update_first_last;
	}
	if (!right) {
		next = get_last(left);
		set_next(get_next(node), next);
		set_child(left, parent, is_left);
		goto update_first_last;
	}

	next = get_first(right);
	if (next != right) {
		/* 'm' is the parent of 'next' */
		struct bstree_node *m = get_next(get_last(next));

		if (get_right(next))
			set_left(get_right(next), m);
		else
			set_prev(next, m);

		set_right(right, next);
	}
	set_child(next, parent, is_left);
	set_left(left, next);
	set_next(next, get_last(left));
out:
	if (parent == &fake_parent)
		tree->root = get_right(parent);
	return;

update_first_last:
	if (node == tree->first)
		tree->first = next;
	if (node == tree->last)
		tree->last = next;
	goto out;
}
Ejemplo n.º 18
0
static void
lru_save(const br_ssl_session_cache_class **ctx,
	br_ssl_server_context *server_ctx,
	const br_ssl_session_parameters *params)
{
	br_ssl_session_cache_lru *cc;
	unsigned char id[SESSION_ID_LEN];
	uint32_t x, alx;

	cc = (br_ssl_session_cache_lru *)ctx;

	/*
	 * If the buffer is too small, we don't record anything. This
	 * test avoids problems in subsequent code.
	 */
	if (cc->store_len < LRU_ENTRY_LEN) {
		return;
	}

	/*
	 * Upon the first save in a session cache instance, we obtain
	 * a random key for our indexing.
	 */
	if (!cc->init_done) {
		br_hmac_drbg_generate(&server_ctx->eng.rng,
			cc->index_key, sizeof cc->index_key);
		cc->hash = br_hmac_drbg_get_hash(&server_ctx->eng.rng);
		cc->init_done = 1;
	}
	mask_id(cc, params->session_id, id);

	/*
	 * Look for the node in the tree. If the same ID is already used,
	 * then reject it. This is a collision event, which should be
	 * exceedingly rare.
	 * Note: we do NOT record the emplacement here, because the
	 * removal of an entry may change the tree topology.
	 */
	if (find_node(cc, id, NULL) != ADDR_NULL) {
		return;
	}

	/*
	 * Find some room for the new parameters. If the cache is not
	 * full yet, add it to the end of the area and bump the pointer up.
	 * Otherwise, evict the list tail entry. Note that we already
	 * filtered out the case of a ridiculously small buffer that
	 * cannot hold any entry at all; thus, if there is no room for an
	 * extra entry, then the cache cannot be empty.
	 */
	if (cc->store_ptr > (cc->store_len - LRU_ENTRY_LEN)) {
		/*
		 * Evict tail. If the buffer has room for a single entry,
		 * then this may also be the head.
		 */
		x = cc->tail;
		cc->tail = get_prev(cc, x);
		if (cc->tail == ADDR_NULL) {
			cc->head = ADDR_NULL;
		} else {
			set_next(cc, cc->tail, ADDR_NULL);
		}

		/*
		 * Remove the node from the tree.
		 */
		remove_node(cc, x);
	} else {
		/*
		 * Allocate room for new node.
		 */
		x = cc->store_ptr;
		cc->store_ptr += LRU_ENTRY_LEN;
	}

	/*
	 * Find the emplacement for the new node, and link it.
	 */
	find_node(cc, id, &alx);
	set_link(cc, alx, x);
	set_left(cc, x, ADDR_NULL);
	set_right(cc, x, ADDR_NULL);

	/*
	 * New entry becomes new list head. It may also become the list
	 * tail if the cache was empty at that point.
	 */
	if (cc->head == ADDR_NULL) {
		cc->tail = x;
	} else {
		set_prev(cc, cc->head, x);
	}
	set_prev(cc, x, ADDR_NULL);
	set_next(cc, x, cc->head);
	cc->head = x;

	/*
	 * Fill data in the entry.
	 */
	memcpy(cc->store + x + SESSION_ID_OFF, id, SESSION_ID_LEN);
	memcpy(cc->store + x + MASTER_SECRET_OFF,
		params->master_secret, MASTER_SECRET_LEN);
	br_enc16be(cc->store + x + VERSION_OFF, params->version);
	br_enc16be(cc->store + x + CIPHER_SUITE_OFF, params->cipher_suite);
}
Ejemplo n.º 19
0
/*!

\brief Gets the last String in the container.
\param[in] it StringContainerIterator used to iterate over the container.
\param[out] value String containing the last String in the container.
\return Returns dmz::True if a \a value was returned. Returns dmz::False if there
are no Strings in the container.

*/
dmz::Boolean
dmz::StringContainer::get_last (StringContainerIterator &it, String &value) const {

   it.state.it.reset ();
   return get_prev (it, value);
}
Ejemplo n.º 20
0
void insert_head(AList_WS* list, double data) {
	insert_at_loc(list, get_prev(list, list_begin(list)), list_begin(list), data);
}
Ejemplo n.º 21
0
void insert_prev(AList_WS* list, size_t pos, double data) {
	insert_at_loc(list, get_prev(list,inter_pos(list,pos)), inter_pos(list,pos), data);
}