Esempio n. 1
0
int main() {
  {
    struct map map;

    map_init(&map);

    char key1[] = "This is a really long key.",
         key2[] = "Another key.";

    assertError("map_set (1)", map_set(&map, key1, sizeof key1, (void*)123));
    assertEq("Key is now retrievable", map_get(&map, key1, sizeof key1), (void*)123);

    assertError("map_set (2)", map_set(&map, key2, sizeof key2, (void*)456));
    assertEq("New key is now retrievable", map_get(&map, key2, sizeof key2), (void*)456);
    assertEq("Old key is still retrievable (1)", map_get(&map, key1, sizeof key1), (void*)123);

    assertError("map_set existing", map_set(&map, key1, sizeof key1, (void*)789));
    assertEq("Key has updated value", map_get(&map, key1, sizeof key1), (void*)789);
    assertEq("Old key is still retrievable (2)", map_get(&map, key2, sizeof key2), (void*)456);

    assertError("map_set small key (1)", map_set(&map, (void*)1, 0, (void*)10));
    assertError("map_set small key (2)", map_set(&map, (void*)2, 0, (void*)20));
    assertEq("Can retrieve short key (1)", map_get(&map, (void*)1, 0), (void*)10);
    assertEq("Can retrieve short key (2)", map_get(&map, (void*)2, 0), (void*)20);

    map_free(&map);
  }
}
Esempio n. 2
0
int main()
{
  //printf("Some random hashes:\n");
  //printf("\tBazinga: %d\n", map_hash_key("Bazinga"));
  //printf("\tFlabagoobie: %d\n", map_hash_key("Flabagoobie"));
  //printf("\tScooby: %d\n", map_hash_key("Scooby"));
  //printf("\tMcDooby: %d\n", map_hash_key("McDooby"));
  //printf("\tagnizaB: %d\n", map_hash_key("agnizaB"));

  Map map;
  map_init(&map);

  map_set(&map, "bazinga", "bazonga");
  map_set(&map, "zabinga", "zabonga");
  map_set(&map, "zabniga", "maponya");
  map_set(&map, "kabanooga", "daboogawoofa");

  MapItem *item;

  print_map(&map);
  map_get(&map, "abzinga");

  printf("================================\n");

  print_map(&map);
  map_free(&map);
}
Esempio n. 3
0
void start_all_threads_interfaces() {
    if(!m_threads) {
        m_threads = new_map(free_string, NULL, compare_string, free_uli, NULL, compare_uli);
    }
    if(cfg_sip) {
        iterator_map *p_it = cfg_sip->begin;
        while(p_it) {
            config_sip_t *sip = p_it->value;
            char *name = calloc(sizeof(sip->name)+1, sizeof(char));
            strcpy(name, sip->name);
            pthread_t *p_thread = calloc(1, sizeof(pthread_t));
            pthread_create(p_thread, NULL, func_listen_sip, sip);
            map_set(m_threads, name, p_thread);
            p_it = p_it->next;
        }
    }
    if(cfg_smpp) {
        iterator_map *p_it = cfg_smpp->begin;
        while(p_it) {
            config_smpp_t *smpp = p_it->value;
            char *name = calloc(sizeof(smpp->name)+1, sizeof(char));
            strcpy(name, smpp->name);
            pthread_t *p_thread = calloc(1, sizeof(pthread_t));
            pthread_create(p_thread, NULL, func_listen_smpp, smpp);
            map_set(m_threads, name, p_thread);
            p_it = p_it->next;
        }
    }
    return;
}
void map_new (unsigned width, unsigned height)
{
  map_allocate (width, height);

  for (int x = 0; x < width; x++)
    map_set (x, height - 1, 0); // Ground

  for (int y = 0; y < height - 1; y++) {
    map_set (0, y, 1); // Wall
    map_set (width - 1, y, 1); // Wall
  }

  map_object_begin (6);

  // Texture pour le sol
  map_object_add ("images/ground.png", 1, MAP_OBJECT_SOLID);
  // Mur
  map_object_add ("images/wall.png", 1, MAP_OBJECT_SOLID);
  // Gazon
  map_object_add ("images/grass.png", 1, MAP_OBJECT_SEMI_SOLID);
  // Marbre
  map_object_add ("images/marble.png", 1, MAP_OBJECT_SOLID | MAP_OBJECT_DESTRUCTIBLE);
	map_object_add("images/flower.png", 1, MAP_OBJECT_AIR | MAP_OBJECT_DESTRUCTIBLE);
	map_object_add("images/coin.png", 20, MAP_OBJECT_AIR | MAP_OBJECT_COLLECTIBLE); 
  map_object_end ();

}
Esempio n. 5
0
void test_strings() {   
   struct map_t *test;

   printf("\nExercising maps of strings...\n");
   printf("------\n");
   test=map_create();
   map_set(test,"One","Won");
   map_set(test,"Two","Too");
   map_set(test,"Four","Fore");


      // display them out of order
   display_both(test,"Two");
   display_both(test,"Four");
   display_both(test,"One");

   printf("\n");

      // reset an existing entry
   map_set(test,"Two","To");

   display_both(test,"Two");
   display_both(test,"Four");
   display_both(test,"One");

   printf("\n");

   display_both(test,"Eight");

   map_set(test,"Eight","Ate");

   printf("\n");

   display_both(test,"Eight");
}
Esempio n. 6
0
int
do_look(int type)
{
    int i;
    struct nstr_item ni;
    union empobj_storage unit;
    struct sctstr sect;
    int x, y;
    unsigned char *bitmap;
    int changed = 0;

    if (CANT_HAPPEN(type != EF_LAND && type != EF_SHIP))
	type = EF_SHIP;

    if (!snxtitem(&ni, type, player->argp[1], NULL))
	return RET_SYN;
    bitmap = calloc((WORLD_SZ() + 7) / 8, 1);
    if (!bitmap) {
	logerror("malloc failed in do_look\n");
	pr("Memory error.  Tell the deity.\n");
	return RET_FAIL;
    }
    while (nxtitem(&ni, &unit)) {
	if (!player->owner)
	    continue;
	if (type == EF_LAND) {
	    if (unit.land.lnd_ship >= 0)
		continue;
	    if (unit.land.lnd_land >= 0)
		continue;
	    /* Spies don't need military to do a "llook".  Other
	       units do */
	    if ((unit.land.lnd_item[I_MILIT] <= 0) &&
		!(lchr[(int)unit.land.lnd_type].l_flags & L_SPY))
		continue;
	    look_land(&unit.land);
	} else
	    look_ship(&unit.ship);
	for (i = 0; i <= 6; i++) {
	    x = diroff[i][0] + unit.gen.x;
	    y = diroff[i][1] + unit.gen.y;
	    if (emp_getbit(x, y, bitmap))
		continue;
	    emp_setbit(x, y, bitmap);
	    getsect(x, y, &sect);
	    if (sect.sct_type == SCT_WATER)
		continue;
	    look_at_sect(&sect, 10);
	    changed += map_set(player->cnum, x, y,
			       dchr[sect.sct_type].d_mnem, 0);
	    if (opt_HIDDEN) {
		setcont(player->cnum, sect.sct_own, FOUND_LOOK);
	    }
	}
    }
    if (changed)
	writemap(player->cnum);
    free(bitmap);
    return RET_OK;
}
Esempio n. 7
0
File: map.c Progetto: erwinnv/test
struct map_t *file_to_new_map( const char * filename)
{
    FILE *in_file = fopen( filename, "r");
    if( in_file == NULL)
    {
        return NULL;
    }
    scalar x = 0, y = 0;
    fscanf( in_file, "%u\n", &x);
    fscanf( in_file, "%u\n", &y);

    struct map_t *new_map = map_new( x, y);
    for( int j = 0; j < y; j++)
    {
        for( int i = 0; i < x; i++)
        {
            char symbol = 0, space = 0;
            fscanf( in_file, "%c%c", &symbol, &space);
            map_set( new_map, i, j, symbol);
        }
    }
    fclose( in_file);
    
    return new_map;
}
Esempio n. 8
0
File: map.c Progetto: erwinnv/test
scalar map_fire( struct map_t *map, scalar x, scalar y)
{
    scalar aim = map_get( map, x, y);
    if( ! is_ship( aim))
    {
        map_set( map, x, y, Hit);
        return Hit;
    }
    if( is_ship( aim) && aim != Destroyed_ship)
    {
        map_set( map, x, y, Hit_ship);
        map_check_ship( map, x, y);
        return Hit_ship;
    }
    return 0;
}
Esempio n. 9
0
void make_world(Map *map, int p, int q) {
    int pad = 1;
    for (int dx = -pad; dx < CHUNK_SIZE + pad; dx++) {
        for (int dz = -pad; dz < CHUNK_SIZE + pad; dz++) {
            int x = p * CHUNK_SIZE + dx;
            int z = q * CHUNK_SIZE + dz;
            float f = simplex2(x * 0.01, z * 0.01, 4, 0.5, 2);
            float g = simplex2(-x * 0.01, -z * 0.01, 2, 0.9, 2);
            int mh = g * 32 + 16;
            int h = f * mh;
            int w = 1;
            int t = 12;
            if (h <= t) {
                h = t;
                w = 2;
            }
            if (dx < 0 || dz < 0 || dx >= CHUNK_SIZE || dz >= CHUNK_SIZE) {
                w = -1;
            }
            for (int y = 0; y < h; y++) {
                map_set(map, x, y, z, w);
            }
        }
    }
    db_update_chunk(map, p, q);
}
Esempio n. 10
0
static int map_resize(map_t map, int newsize, int force)
{
	if ((newsize = map_calc_size(newsize)) == -1)
		return -1;

	if (force || newsize > map->size)
	{
		map_t newmap;
		int i;
		bucket_t *b;

		newmap = map_new(newsize, map->hashf, map->compf, map->allocf, map->freef);
		if (!newmap)
			return -1;
		for (i = 0; i < map->size; ++i)
		{
			b = map->buckets[i];
			while (b)
			{
				map_set(newmap, b->key, b->data, 0);
				b = b->next;
			}
		}
		map_set_buckets(map, newmap->buckets, newsize);
		free(newmap);
	}
	return map->size;
}
Esempio n. 11
0
static int
Map_init(Map *self, PyObject *args, PyObject *kwds)
{                    
	int size_pixels;
	double size_meters;
	PyObject * py_bytes = NULL;
	
    static char * argnames[] = {"size_pixels", "size_meters", "bytes", NULL};

    if(!PyArg_ParseTupleAndKeywords(args, kwds,"id|O", argnames, 
        &size_pixels, 
        &size_meters, 
        &py_bytes))
    {
        return error_on_raise_argument_exception("Map");
    }
           
    map_init(&self->map, size_pixels, size_meters);
    
    if (py_bytes && !bad_mapbytes(py_bytes, size_pixels, "__init__"))
    {    
        map_set(&self->map, PyByteArray_AsString(py_bytes));
    }
    
    return 0;
}
Esempio n. 12
0
void
pln_mine(struct emp_qelem *list, coord tx, coord ty)
{
    struct emp_qelem *qp;
    struct plist *plp;
    int amt;
    struct sctstr sect;

    amt = 0;
    for (qp = list->q_forw; qp != list; qp = qp->q_forw) {
	plp = (struct plist *)qp;
	amt += plp->load;

    }
    if (amt > 0) {
	getsect(tx, ty, &sect);
	if (sect.sct_type != SCT_WATER) {
	    pr("Your seamines have no effect here.\n");
	    return;
	}
	sect.sct_mines = MIN(sect.sct_mines + amt, MINES_MAX);
	pr("%d mines laid in %s.\n", amt, xyas(tx, ty, player->cnum));
	if (map_set(player->cnum, tx, ty, 'X', 0))
	    writemap(player->cnum);
	putsect(&sect);
    }
}
Esempio n. 13
0
/* ARGSUSED */
bool_t
rpcbproc_set_com(rpcb *regp, bool_t *result, ar_svc_req_t *rqstp,
		 arpcvers_t rpcbversnum)
{
	bool_t ans;
	char owner[64];

#ifdef RPCBIND_DEBUG
	if (debugging) {
		fprintf(stderr, "RPCB_SET request for (%lu, %lu, %s, %s) : ",
			(unsigned long)regp->r_prog, 
			(unsigned long)regp->r_vers,
			regp->r_netid, regp->r_addr);
	}
#endif
	ans = map_set(regp, getowner(rqstp->rq_xprt, owner, sizeof owner));
#ifdef RPCBIND_DEBUG
	if (debugging) {
		fprintf(stderr, "%s\n", ans == TRUE ? "succeeded" : "failed");
	}
#endif
	/* XXX: should have used some defined constant here */
	rpcbs_set(rpcbversnum - 2, ans);
	*result = ans;
	return TRUE;
}
Esempio n. 14
0
void* textures_load(char* path) {
    void* map = map_init();

    chdir(path);
    DIR* dir = opendir(".");
    if (!dir) {
        fprintf(stderr, "cannot open dir: %s\n", path);
        return map;
    }

    struct dirent* file;
    while ((file = readdir(dir)) != NULL) {
        char* name = file->d_name;
        size_t length = strlen(name);
        if (length > 4 && strcmp(".png", &name[length - 4]) == 0) {
            char file_path[80];
            strcat(file_path, path);
            texture_t* texture = malloc(sizeof(texture_t));
            texture_load(texture, name);
            map = map_set(map, strtok(name, "."), texture);
        }
        
    }
    chdir("..");

    return map;
}
Esempio n. 15
0
//!
//! Main entry point of the application
//!
//! @param[in] argc the number of parameter passed on the command line
//! @param[in] argv the list of arguments
//!
//! @return EUCA_OK on success or EUCA_ERROR on failure.
//!
//! @note little unit test: compile with gcc -g -D_TEST_MAP map.c
//!
int main(int argc, char *argv[])
{
    char *s1 = "string 1";
    char *s2 = "string 2";
    map *m = map_create(10);

    assert(map_get(m, "foo") == NULL);
    map_set(m, "k1", s1);
    assert(map_get(m, "k1") == s1);
    map_set(m, "k2", s2);
    assert(map_get(m, "k2") == s2);
    map_set(m, "k2", s1);
    assert(map_get(m, "k2") == s1);

    return (EUCA_OK);
}
Esempio n. 16
0
/*
 * assign (dest = src)
 */
void v_set(var_t *dest, const var_t *src) {
  v_free(dest);
  dest->const_flag = 0;
  dest->type = src->type;

  switch (src->type) {
  case V_INT:
    dest->v.i = src->v.i;
    break;
  case V_STR:
    dest->v.p.size = strlen(src->v.p.ptr) + 1;
    dest->v.p.ptr = (char *)malloc(dest->v.p.size);
    strcpy(dest->v.p.ptr, src->v.p.ptr);
    break;
  case V_NUM:
    dest->v.n = src->v.n;
    break;
  case V_MAP:
    map_set(dest, (const var_p_t)src);
    break;
  case V_PTR:
    dest->v.ap.p = src->v.ap.p;
    dest->v.ap.v = src->v.ap.v;
    break;
  case V_REF:
    dest->v.ref = src->v.ref;
    break;
  case V_FUNC:
    dest->v.fn.cb = src->v.fn.cb;
    dest->v.fn.self = src->v.fn.self;
    break;
  case V_ARRAY:
    if (src->v.a.size) {
      memcpy(&dest->v.a, &src->v.a, sizeof(src->v.a));
      dest->v.a.ptr = malloc(src->v.a.size * sizeof(var_t));

      // copy each element
      int i;
      var_t *dest_vp, *src_vp;
      for (i = 0; i < src->v.a.size; i++) {
        src_vp = (var_t *)(src->v.a.ptr + (sizeof(var_t) * i));
        dest_vp = (var_t *)(dest->v.a.ptr + (sizeof(var_t) * i));
        v_init(dest_vp);
        v_set(dest_vp, src_vp);
      }
    } else {
      dest->v.a.size = 0;
      dest->v.a.ptr = NULL;
      dest->v.a.ubound[0] = dest->v.a.lbound[0] = opt_base;
      dest->v.a.maxdim = 1;
    }
    break;
  }
}
Esempio n. 17
0
File: map.c Progetto: erwinnv/test
scalar bad_map_if_ship( struct map_t *search_map, scalar x, scalar y)
{
    if( is_ship( map_get( search_map, x, y)))
    {
        return Bad_map;
    }
    else
    {
        map_set( search_map, x, y, Search_mark);
        return 0;
    }
}
Esempio n. 18
0
void _set_block(
    Chunk *chunks, int chunk_count,
    int p, int q, int x, int y, int z, int w)
{
    Chunk *chunk = find_chunk(chunks, chunk_count, p, q);
    if (chunk) {
        Map *map = &chunk->map;
        map_set(map, x, y, z, w);
        update_chunk(chunk);
    }
    db_insert_block(p, q, x, y, z, w);
}
Esempio n. 19
0
File: map.c Progetto: erwinnv/test
struct map_t *map_update_enemy_map( struct map_t *dst, struct map_t *src)
{
    for( int i = 0; i < dst->x_size; i++)
    {
        for( int j = 0; j < dst->y_size; j++)
        {
            scalar current = map_get( src, i, j);
            if(    current != Hit 
                && current != Destroyed_ship
                && current != Hit_ship)
            {
                map_set( dst, i, j, Hidden);
            }
            else
            {
                map_set( dst, i, j, current);
            }
        }
    }
    return dst;
}
Esempio n. 20
0
File: map.c Progetto: erwinnv/test
void map_destroy_ship( struct map_t *map, scalar x, scalar y)
{
    scalar current = map_get( map, x, y);
    if( is_ship( current) && current != Destroyed_ship)
    {
        map_set( map, x, y, Destroyed_ship);
    
        map_destroy_ship( map, x+1, y);
        map_destroy_ship( map, x-1, y);
        map_destroy_ship( map, x, y+1);
        map_destroy_ship( map, x, y-1);
    }
}
Esempio n. 21
0
void make_world(Map *map, int p, int q) {
    int pad = 1;
    for (int dx = -pad; dx < CHUNK_SIZE + pad; dx++) {
        for (int dz = -pad; dz < CHUNK_SIZE + pad; dz++) {
            int x = p * CHUNK_SIZE + dx;
            int z = q * CHUNK_SIZE + dz;
            float f = simplex2(x * 0.01, z * 0.01, 4, 0.5, 2);
            float g = simplex2(-x * 0.01, -z * 0.01, 2, 0.9, 2);
            int mh = g * 32 + 16;
            int h = f * mh;
            int w = 1;
            int t = 12;
            if (h <= t) {
                h = t;
                w = 2;
            }
            if (dx < 0 || dz < 0 || dx >= CHUNK_SIZE || dz >= CHUNK_SIZE) {
                w = -1;
            }
            for (int y = 0; y < h; y++) {
                map_set(map, x, y, z, w);
            }
            if (w == 1) {
                if (simplex2(-x * 0.1, z * 0.1, 4, 0.8, 2) > 0.6) {
                    map_set(map, x, h, z, 17);
                }
                if (simplex2(x * 0.05, -z * 0.05, 4, 0.8, 2) > 0.7) {
                    int w = 18 + simplex2(x * 0.1, z * 0.1, 4, 0.8, 2) * 7;
                    map_set(map, x, h, z, w);
                }
            }
            for (int y = 64; y < 72; y++) {
                if (simplex3(x * 0.01, y * 0.1, z * 0.01, 8, 0.5, 2) > 0.75) {
                    map_set(map, x, y, z, 16);
                }
            }
        }
    }
}
Esempio n. 22
0
int main(void)
{
	int i;
	map *m;
	int lastcap;
	stats s;
	stat_list *l1, *l2;
	stat_list_iterator iter;
	double _max_load[] = {0.2, 0.3, 0.5, 0.7, 0.85, 1.0, 1.15, 1.3, 1.5, 1.75, 2.0, 2.5, 3.0, 4.0, 6.0, 9.0, 12.0, 15.0, 20.0, 0.0};
	double *max_load = _max_load;

	l1 = stat_list_new();
	l2 = stat_list_new();
	while (*max_load > 0) {
		m = map_new();
		m->max_load = *max_load;
		++max_load;
		lastcap = m->cap;
		s = map_stats(m);
		srand(0);
		for (i=0; i<=N; ++i) {
			while (m->cap == lastcap) {
				if ((m->len+1.0)/m->cap > m->max_load) {
					s = map_stats(m);
				}
				map_set(m, randt(), randt());
			}
			lastcap = m->cap;
		}
		stat_list_insert(l1, s, -1);
		stat_list_insert(l2, map_stats(m), -1);
		map_free(m);
	}

	print_header();
	print_hr();
	for (iter=stat_list_iterate(l1); stat_list_next(l1, &iter); ) {
		print_stats(stat_list_get_at(l1, iter));
	}
	print_hr();
	print_header();
	print_hr();
	for (iter=stat_list_iterate(l2); stat_list_next(l2, &iter); ) {
		print_stats(stat_list_get_at(l2, iter));
	}

	stat_list_free(l1);
	stat_list_free(l2);

	return 0;
}
Esempio n. 23
0
void _set_block(
    Chunk *chunks, int chunk_count,
    int p, int q, int x, int y, int z, int w)
{
    Chunk *chunk = find_chunk(chunks, chunk_count, p, q);
    if (chunk) {
        Map *map = &chunk->map;
        if (map_get(map, x, y, z) != w) {
            map_set(map, x, y, z, w);
            chunk->dirty = 1;
        }
    }
    db_insert_block(p, q, x, y, z, w);
}
void map_load (char *filename)
{
  	// TODO
  	int file = open(filename, O_RDONLY);
	int height, width, nb_obj = 0;
	char n;
	read(file, &height, sizeof(int));
	read(file, &n, 1);	
	read(file, &width, sizeof(int));
	read(file, &n, 1);	
	read(file, &nb_obj, sizeof(int));
	read(file, &n, 1);
	printf("%d, %d\n", width, nb_obj);
	map_allocate(width, height);
		
	int obj;
	for(int i = 0; i < width; ++i)
	{
		for(int j = 0; j < height; ++j)
		{
			read(file, &obj, sizeof(int));
			map_set(i, j, obj);
		}
	}
	printf("hello\n");
	read(file, &n, 1);

	int len, frames, solidity, destr, collec, gen;
	char name[100];
	map_object_begin(nb_obj);
	printf("map_object_pass\n");
	for(int i = 0; i < nb_obj; ++i)
	{
		read(file, &len, sizeof(int));
		read(file, name, len);
		name[len] = '\0';
		read(file, &frames, sizeof(int));		
		read(file, &solidity, sizeof(int));		
		read(file, &destr, sizeof(int));		
		read(file, &collec, sizeof(int));		
		read(file, &gen, sizeof(int));
		printf("%s\n", name);		
		read(file, &n, 1);
		map_object_add(name, frames, solidity | destr | collec | gen);
	}
	map_object_end();

	close(file);
}
Esempio n. 25
0
File: db.c Progetto: jlsandell/Craft
void db_load_map(Map *map, int p, int q) {
    if (!db_enabled) {
        return;
    }
    sqlite3_reset(load_map_stmt);
    sqlite3_bind_int(load_map_stmt, 1, p);
    sqlite3_bind_int(load_map_stmt, 2, q);
    while (sqlite3_step(load_map_stmt) == SQLITE_ROW) {
        int x = sqlite3_column_int(load_map_stmt, 0);
        int y = sqlite3_column_int(load_map_stmt, 1);
        int z = sqlite3_column_int(load_map_stmt, 2);
        int w = sqlite3_column_int(load_map_stmt, 3);
        map_set(map, x, y, z, w);
    }
}
Esempio n. 26
0
void test_map() {

    map *m = map_make();
    m->hash = sdbmHash;
    m->copyKey = copyKey;
    m->compare = compareKey;

    char *test[] = {
            "asd",
            "bsddj",
            "csdf",
            "dsdf",
            "esdafasd",
            "fasdf",
            "gsadf",
            "gs",
            "f**k",
            "safsd",
            "sadfasd",
            "asddfasdf",
            "asdfasdf",
            "sadfe",
            "asdfasd",
            "erer",
            "rtert",
            "asdf",
            "4erwerw",
            "sawe23",

    };
    int a[] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23};

    int i = 0;
    for (; i < 200; i++) {
        map_set(m, test[i % 17], a + i % 17);
    }

    printf("Over\n");
    for (i = 0; i < 200; i++) {
        bucket* val = map_get(m, test[i % 17]);
        if (val == NULL) {
            printf("not found");
        } else {
//            printf(" %p %s %d\n", val,(char*)val->key, *((int*)(val->val)));
        }
    }
    map_print(m);
}
Esempio n. 27
0
int lrucache_set(LRUCACHE* lrucache, char* key, char* value)
{
    char* k;
    
    while (map_length(lrucache->map) >= lrucache->size) {
        k = queue_peek(lrucache->queue);
        if (k == NULL) {
            break;
        } else {
            map_remove(lrucache->map, k);
        }
    }
    
    queue_insert(lrucache->queue, key);
    
    return map_set(lrucache->map, key, value);
}
Esempio n. 28
0
void
case_map_set(struct bench_ctx *ctx)
{
    struct map *m = map();
    /* keys suite */
    int i;
    char keys[ctx->n][4];
    for (i = 0; i < ctx->n; i++)
        sprintf(keys[i], "%d", i & 999);
    /* bench */
    bench_ctx_reset_start_at(ctx);
    for (i = 0; i < ctx->n; i++) {
        map_set(m, keys[i], "val");
    }
    bench_ctx_reset_end_at(ctx);
    map_free(m);
}
Esempio n. 29
0
/*
 * Update @owner's bmap for radar at @cx,@cy.
 * @eff is the radar's efficiency, @tlev its tech level, @spy its power.
 */
void
rad_map_set(natid owner, int cx, int cy, int eff, double tlev, int spy)
{
    struct nstr_sect ns;
    struct sctstr sect;
    int range = rad_range(eff, tlev, spy);
    int changed = 0;
    char ch;

    snxtsct_dist(&ns, cx, cy, range);
    while (nxtsct(&ns, &sect)) {
	ch = rad_char(&sect, ns.curdist, range, owner);
	changed += map_set(owner, ns.x, ns.y, ch, 0);
    }
    if (changed)
	writemap(owner);
}
Esempio n. 30
0
/**
 * \brief Receives each ini file entry at a time and
 * saves it into the map in the format "section/name" => "value".
 * \param vmap Map to be updated with the ini entry.
 * \param section Ini section.
 * \param name Ini entry name.
 * \param value Ini entry value.
 */
static int handler(void* vmap, const char* section, const char* name,
                   const char* value)
{
    size_t key_len = strlen(section) + strlen(name) + 2; // 2 = \0 + '/'
    char* key = (char*)malloc(key_len * sizeof(char));;
    sprintf(key, "%s/%s", section, name);

    size_t value_len = strlen(value);
    char* val = (char*)malloc(value_len * sizeof(char));
    strncpy(val, value, value_len);

    map_set((struct map_t*)vmap, key, (void*)val);

    free(key);

    return 1;
}