Exemple #1
0
void struct_maps()
{
    // here we have a custom type which has a LIST_HEADER and a string key
    // `true` indicates that we should use string ordering.
    Map *map = map_new_node(true);

    // since the key is part of the data we don't use `map_put`. `map_put_struct` is used
    // for inserting single values.
    map_put_structs(map,
        Data_new("bob",22,1),
        Data_new("alice",21,0),
        Data_new("roger",40,1),
        Data_new("liz",16,0),
        NULL
    );
    printf("size was %d\n",map_size(map));

    // you can now look up data using the key
    dump(D map_get(map,"alice"));
    dump(D map_get(map,"roger"));

    Data *rog = (Data*)map_remove(map,"roger");
    printf("size was %d\n",map_size(map));

    FOR_MAP(iter,map) {
        printf("[%s]=%d,",(char*)iter->key,((Data*)(iter->value))->age );
    }
Exemple #2
0
// validate block size control for 512 and max count of 1
void test_block_size_512_and_count_1() {
  // clean up from any previous run
  rm_hashdb_dir(temp_dir1);
  rm_hashdb_dir(temp_dir2);
  remove(temp_dfxml_file);

  // create new hashdb
  hashdb_settings_t settings;
  settings.hash_block_size = 512;
  settings.maximum_hash_duplicates  = 1;
  commands_t::create(settings, temp_dir1);
  commands_t::create(settings, temp_dir2);

  // import
  commands_t::import(temp_dir1, sample_dfxml512, "test_repository_name");
  commands_t::import(temp_dir1, sample_dfxml512, "test_repository_name2");
  BOOST_TEST_EQ(map_size(temp_dir1), 24);

  // export
  commands_t::do_export(temp_dir1, "temp_dfxml_out.xml");

  // import
  commands_t::import(temp_dir2, "temp_dfxml_out.xml", "test_repository_name");
  BOOST_TEST_EQ(map_size(temp_dir1), 24);
}
Exemple #3
0
void sensor_push_stimulus(Sensor s, Stimulus stim) {
  mapVec pt, sz;
  perception *newVis;
  perception *snewVis = s->vistiles;
  perception newPerception;
  bool litAndVisible;
  Object o;
  Map m = s->map;
  mapVec borig=s->borig, bsz=s->bsz;
  switch(stimulus_type(stim)) {
    case StimTileLitChange:
    case StimTileVisChange:
      newVis = stimulus_tile_sight_change_get_new_perceptmap(stim);
      pt = stimulus_tile_sight_change_get_position(stim);
      sz = stimulus_tile_sight_change_get_size(stim);
      for(int z = pt.z; z < pt.z+sz.z; z++) {
        for(int y = pt.y; y < pt.y+sz.y; y++) {
          for(int x = pt.x; x < pt.x+sz.x; x++) {
            int stimIndex = tile_index(x, y, z, map_size(m), pt, sz);
            int visIndex = tile_index(x, y, z, map_size(m), borig, bsz);
            snewVis[visIndex] = newVis[stimIndex];
          }
        }
      }
      break;
    case StimObjLitChange:
    case StimObjVisChange:
    case StimObjMoved:
      //is the object in newVis? if so, put it into oldVis; if not, make sure it isn't in oldVis.
      //do this search by _ID_, not by identity
      //are the new flags good? if so, be sure the object is in vis. otherwise, be sure it's not in vis.
      if(sensor_visobjs_contains(s->visObjects, o)) {
        sensor_visobjs_push(s->oldVisObjects, o);
      } else {
        sensor_visobjs_remove(s->oldVisObjects, o);
      }
      newPerception = stimulus_obj_sight_change_get_new_perception(stim);
      litAndVisible = map_item_visible(newPerception);
      
      if(litAndVisible) {
        if(!sensor_visobjs_contains(s->visObjects, o)) {
          sensor_visobjs_push(s->visObjects, o);
        }
      } else {
        if(sensor_visobjs_contains(s->visObjects, o)) {
          sensor_visobjs_remove(s->visObjects, o);
        }
      }
      break;
    case StimGeneric:
    default:
      break;
  }
  TCOD_list_push(s->stimuli, stim);
}
Exemple #4
0
TEST(UniqueMap, MapSize)
{
  struct UniqueMap* map = create_unique_map(0, 10);
  int value = 0xFF;
    
  TEST_ASSERT_EQUAL_INT(0, map_size(map));
  map_put_unique(map, &value);
  TEST_ASSERT_EQUAL_INT(1, map_size(map));
  map_put_unique(map, &value);
  TEST_ASSERT_EQUAL_INT(2, map_size(map));
  map_put_unique(map, &value);
  TEST_ASSERT_EQUAL_INT(3, map_size(map));

  destroy_unique_map(map);
}
Exemple #5
0
// validate use of multiple repository names
void test_multiple_repository_names() {
  
  // clean up from any previous run
  rm_hashdb_dir(temp_dir);

  // create new hashdb
  hashdb_settings_t settings;
  commands_t::create(settings, temp_dir);

  // test ability to manage multiple repository names
  for (int i=0; i<12; i++) {
    // generate unique repository name
    std::ostringstream ss;
    ss << "test_repository_name_" << i;

    // import
    commands_t::import(temp_dir, sample_dfxml4096, ss.str());
  }

  // duplicate import should not add elements
  commands_t::import(temp_dir, sample_dfxml4096, "test_repository_name_0");

  // validate correct size
  BOOST_TEST_EQ(map_size(temp_dir), 74*12);
}
Exemple #6
0
// maps:update/3 [18]
term_t cbif_update3(proc_t *proc, term_t *regs)
{
	term_t Key   = regs[0];
	term_t Value = regs[1];
	term_t Map   = regs[2];

	if (!is_boxed_map(Map))
		badarg(Map);

	t_map_t *m0 = (t_map_t *)peel_boxed(Map);
	int index = map_key_index(Key, m0->keys);
	if (index < 0)
		badarg(Key);
	int size = map_size(m0);
	int needed = WSIZE(t_map_t) +size;
	uint32_t *p = heap_alloc(&proc->hp, needed);
	t_map_t *m1 = (t_map_t *)p;
	box_map(p, size, m0->keys);
	heap_set_top(&proc->hp, p);

	memcpy(m1->values, m0->values, size *sizeof(term_t));
	m1->values[index] = Value;

	return tag_boxed(m1);
}
Exemple #7
0
    result test(std::string const & name, mapnik::Map const & map, double scale_factor) const
    {
        typename Renderer::image_type image(ren.render(map, scale_factor));
        boost::filesystem::path reference = reference_dir / image_file_name(name, map.width(), map.height(), scale_factor, true, Renderer::ext);
        bool reference_exists = boost::filesystem::exists(reference);
        result res;

        res.state = reference_exists ? STATE_OK : STATE_OVERWRITE;
        res.name = name;
        res.renderer_name = Renderer::name;
        res.scale_factor = scale_factor;
        res.size = map_size(map.width(), map.height());
        res.reference_image_path = reference;
        res.diff = reference_exists ? ren.compare(image, reference) : 0;

        if (res.diff)
        {
            boost::filesystem::create_directories(output_dir);
            boost::filesystem::path path = output_dir / image_file_name(name, map.width(), map.height(), scale_factor, false, Renderer::ext);
            res.actual_image_path = path;
            res.state = STATE_FAIL;
            ren.save(image, path);
        }

        if ((res.diff && overwrite) || !reference_exists)
        {
            ren.save(image, reference);
            res.state = STATE_OVERWRITE;
        }

        return res;
    }
Exemple #8
0
static void _json_write_object(FILE * file, map_t map, unsigned int depth)
{
    if (map_size(map) == 0) {
        fputs("{}", file);
    } else {
        bool first = true;

        fputs("{\n", file);

        for_each_map(it, map) {
            if (first) first = false;
            else fputs(",\n");

            for (int i = 0; i < depth + 1; i++)
                fputs("    ", file);
            _json_write_string(file, map_key(it));
            fputs(": ");
            _json_write(file, map_value(it), depth + 1);
        }

        fputs("\n", file);
        for (int i = 0; i < depth; i++)
            fputs("    ", file);
        fputs("}", file);
    }
}
Exemple #9
0
str store_serialize(map_t _store)
{
	cJSON *flat_map;
	str ret = STR_NULL;

	if (map_size(_store) == 0)
		return ret;

	cJSON_InitHooks(&shm_hooks);

	flat_map = cJSON_CreateObject();
	if (!flat_map) {
		LM_ERR("oom\n");
		return ret;
	}

	if (map_for_each(_store, push_kv_to_json, flat_map) != 0)
		LM_ERR("oom - serialized map is incomplete!\n");

	ret.s = cJSON_PrintUnformatted(flat_map);
	if (!ret.s) {
		LM_ERR("oom\n");
		goto out;
	}
	ret.len = strlen(ret.s);

out:
	cJSON_Delete(flat_map);
	cJSON_InitHooks(NULL);
	return ret;
}
Exemple #10
0
static obj_ptr _map_size(obj_ptr arg, obj_ptr env)
{
    if (NMAPP(arg))
        return MKERROR(MKSTRING("Expected a map in map-clear"), arg);

    return MKINT(map_size(&MAP(arg)));
}
Exemple #11
0
void SceneStart::resume(){
	std::cout<<"SceneStart::resume() 1"<<std::endl;
	music_player.play();
	draw->Enable3D=true;
	draw->set_camera(camera);
	draw->set_lightControl(lightControl);

	if(UI){
		delete UI;
		UI=0;
	}
	UI = new UI::UI("files/AgeOfCube/scenes/startScene/UI/startSceneUI.txt");
	p_control=(UI::PageControl*)UI->get_child("pageControl");
	auto_p_control=(UI::AutoPageControl*)UI->get_child("newGame_autoPageControl");
	//if(UI)delete UI;

	if(!p_control){
		std::cerr<<"SceneStart::scene_initialize ,can't find child page control"<<std::endl;
	}else{
		p_control->switch_page("startPage");
	}
	field=new StaticField();

	std::string map_name = "title";
	glm::ivec3 map_size(200,50,200);
	if(Tim::File::check_if_file_exist(map_folder_path+map_name)){
		std::cout<<"find map"<<std::endl;
		field->load(map_folder_path+map_name);
	}else{
		//std::cout<<"not find map"<<std::endl;
		field->map->gen_map(map_size,time(NULL));
	}
	std::cout<<"SceneStart::resume() END"<<std::endl;
}
Exemple #12
0
void drawtiles(Map m, unsigned char *buf, Sensor s, mapVec pos, mapVec size) {
  int index=0;
  unsigned char tileIndex;
  unsigned char flags;
  int drawX, drawY;
  Volume vol = sensor_volume(s);
  mapVec borig, bsz;
  volume_swept_bounds(vol, &borig, &bsz);
  mapVec msz = map_size(m);
  float ystart = CLIP(pos.y, 0, msz.y);
  float xstart = CLIP(pos.x, 0, msz.x);
  float yend = CLIP(pos.y+size.y, 0, msz.y);
  float xend = CLIP(pos.x+size.x, 0, msz.x);
  int z = CLIP(pos.z, 0, msz.z); //note: different from test.c version
  for(int y = ystart; y < yend; y++) {
    for(int x = xstart; x < xend; x++) {
      index = tile_index(x, y, z, msz, borig, bsz);
      flags = buf[index];
      TCOD_console_print_left(NULL, 0, 18, TCOD_BKGND_NONE, "%i, %i, %i", map_item_lit(flags), map_item_in_volume(flags), map_item_los(flags));
      tileIndex = map_tile_at(m, x, y, z);
      drawX = x*2+z*((msz.x*2)+1);
      drawY = y;
      //TCOD_console_print_left(NULL, drawX, drawY, TCOD_BKGND_NONE, "%i", index);
      if(map_item_visible(flags)) {
         //visible and lit and in volume
         TCOD_console_print_left(NULL, drawX, drawY, TCOD_BKGND_NONE, "%i", tileIndex);
      }
      // else if(!map_item_lit(flags) && map_item_in_volume(flags) && map_item_los(flags)) {
      //   //not lit and viewable
      //   TCOD_console_print_left(NULL, drawX, drawY, TCOD_BKGND_NONE, "_");
      // }
      // else if(!map_item_lit(flags) && map_item_in_volume(flags) && !map_item_los(flags)) {
      //   //not lit and not los
      //   TCOD_console_print_left(NULL, drawX, drawY, TCOD_BKGND_NONE, ",");
      // }
      // else if(!map_item_lit(flags) && !map_item_in_volume(flags) && map_item_los(flags)) {
      //   //not lit and not in vol
      //   TCOD_console_print_left(NULL, drawX, drawY, TCOD_BKGND_NONE, "d");
      // }
      // else if(map_item_lit(flags) && !map_item_in_volume(flags) && map_item_los(flags)) {
      //   //lit and in los, but not in vol
      //   TCOD_console_print_left(NULL, drawX, drawY, TCOD_BKGND_NONE, "a");
      // }
      // else if(map_item_lit(flags) && map_item_in_volume(flags) && !map_item_los(flags)) {
      //   //lit and in vol, but not in los
      //   TCOD_console_print_left(NULL, drawX, drawY, TCOD_BKGND_NONE, "b");
      // }
      // else if(map_item_lit(flags) && !map_item_in_volume(flags) && !map_item_los(flags)) {
      //   //lit and not in vol or los (or los wasn't checked)
      //   TCOD_console_print_left(NULL, drawX, drawY, TCOD_BKGND_NONE, ".");
      // }
      // else if(!map_item_lit(flags) && !map_item_in_volume(flags) && !map_item_los(flags)) { 
      //   //not lit, in vol, or in los
      //   TCOD_console_print_left(NULL, drawX, drawY, TCOD_BKGND_NONE, "x");
      // }
    }
  }
}
Exemple #13
0
static Iterator* iterator_map_init(const void *o) {
    MapIterator *iter = obj_new(MapIterator,MapIterator_dispose);
    iter->mi = map_iter_new((Map*)o,NULL,NULL);
    iter->next = iterator_map_next;
    iter->nextpair = iterator_map_nextpair;
    iter->len = map_size((Map*)o);
    iter->finis = false;
    return (Iterator*)iter;
}
Exemple #14
0
/// Get the key/value pairs of a map as an array.
MapKeyValue *map_to_array(Map *m)
{
    MapKeyValue *res = array_new(MapKeyValue,map_size(m));
    struct ArrayMapIter *ami = obj_new(struct ArrayMapIter,NULL);
    ami->kp = res;
    ami->m = m;
    map_visit(ami,(PEntry)root(m),(MapCallback)add_keypair,0);
    obj_unref(ami);
    return res;
}
Exemple #15
0
void malloc_statistics() {
	is_debug = false;
	
	printf("Caller                      Count             Size\n");
	MapIterator iter;
	map_iterator_init(&iter, statistics);
	while(map_iterator_has_next(&iter)) {
		MapEntry* entry = map_iterator_next(&iter);
		Stat* s = entry->data;
		if(s->count >= 2 || s->size > 2048)
			printf("%p %16ld %16ld\n", entry->key, s->count, s->size);
	}
	
	printf("usage: %ld/%ld\n", malloc_used(), malloc_total());
	printf("tracing: class: %ld total: %ld\n", map_size(statistics), map_size(tracing));
	printf("malloc/free count: %d - %d = %d\n", debug_malloc_count, debug_free_count, debug_malloc_count - debug_free_count);
	debug_malloc_count = debug_free_count = 0;
	
	is_debug = true;
}
Exemple #16
0
// validate block size control for 4096
void test_block_size_4096() {
  // clean up from any previous run
  rm_hashdb_dir(temp_dir1);
  rm_hashdb_dir(temp_dir2);
  remove(temp_dfxml_file);

  // create new hashdb
  hashdb_settings_t settings;
  commands_t::create(settings, temp_dir1);
  commands_t::create(settings, temp_dir2);

  // import
  commands_t::import(temp_dir1, sample_dfxml4096, "test_repository_name");
  BOOST_TEST_EQ(map_size(temp_dir1), 74);

  // export
  commands_t::do_export(temp_dir1, "temp_dfxml_out.xml");

  // import
  commands_t::import(temp_dir2, "temp_dfxml_out.xml", "test_repository_name");
  BOOST_TEST_EQ(map_size(temp_dir2), 74);
}
Exemple #17
0
// maps:put/3 [21]
term_t cbif_put3(proc_t *proc, term_t *regs)
{
	term_t Key   = regs[0];
	term_t Value = regs[1];
	term_t Map   = regs[2];

	if (!is_boxed_map(Map))
		badarg(Map);

	t_map_t *m0 = (t_map_t *)peel_boxed(Map);
	int index = map_key_index(Key, m0->keys);
	if (index >= 0)
	{
		// same as update/3
		int size = map_size(m0);
		int needed = WSIZE(t_map_t) +size;
		uint32_t *p = heap_alloc(&proc->hp, needed);
		t_map_t *m1 = (t_map_t *)p;
		box_map(p, size, m0->keys);
		heap_set_top(&proc->hp, p);

		memcpy(m1->values, m0->values, size *sizeof(term_t));
		m1->values[index] = Value;

		return tag_boxed(m1);
	}
	else
	{
		uint32_t *q = peel_tuple(m0->keys);
		int size = *q++;
		term_t *ks = q;
	
		term_t kvs[] = {Key,Value};

		int needed = 1 +size+1 +2 +size+1;
		uint32_t *p = heap_alloc(&proc->hp, needed);
		term_t keys = tag_tuple(p);
		*p++ = size+1;
		term_t *ks1 = p;
		p += size+1;
		term_t out = tag_boxed(p);
		term_t *vs1 = p +WSIZE(t_map_t);
		box_map(p, size+1, keys);
		heap_set_top(&proc->hp, p);

		int size1 = map_merge(ks, m0->values, size, kvs, 1, ks1, vs1);
		assert(size1 == size+1);
		
		return out;
	}
}
Exemple #18
0
// import/export: import1, export, import2 should retain size of 74
void test_import_export() {
  hashdb_settings_t settings;
  rm_hashdb_dir(temp_dir1);
  rm_hashdb_dir(temp_dir2);
  remove(temp_dfxml_file);

  // import
  commands_t::create(settings, temp_dir1);
  commands_t::import(temp_dir1, sample_dfxml4096, "repository1");
  commands_t::do_export(temp_dir1, "temp_dfxml_out.xml");
  commands_t::create(settings, temp_dir2);
  commands_t::import(temp_dir2, temp_dfxml_file, "repository2");
  BOOST_TEST_EQ(map_size(temp_dir2), 74);
}
/* a function that prints out the contents of the map */
void print_map(map *m)
{
	/* an iterator for iterating through all map entries */
	map_iterator i;

	/* the method `int map_size(map *) returns the current number of entries */
	printf("map (size: %d) {", map_size(m));

	/* just like lists, map is iterated with _iterate and _next */
	for (i=map_iterate(m); map_next(m, &i); ) {
		/* map_key_at and map_value_at return the key and value, respectively */
		printf(" %s:%d,", map_key_at(m, i), map_value_at(m, i));
	}
	printf("\b }\n");
}
Exemple #20
0
/*
>> INITALIZING MAP ...
>> ADDING ENTRIES       PASSED
>> ***---DUPLICATE KEY        FAILED ****
>> GETTING VALID KEY    PASSED
>> GETTING INVALID KEY  PASSED
>> ***CHECKING SIZE (4)    FAILED ****
>> REMOVING KEY         PASSED
>> ***GETTING INVALID KEY  FAILED ****
>> GETTING VALID KEY    PASSED
>> ***REMOVING INVALID KEY FAILED ****
>> REMOVING KEY         PASSED
>> REMOVING KEY         PASSED
>> SERIALIZING          PASSED
*/
int main(int argc,char *argv[])
{
	map_t cool_map;
	printf("INITIALIZING MAP ...\r\n");
	map_init(&cool_map);
	printf("ADDING ENTRIES\t");
	map_put(&cool_map,"bom","bom");
	map_put(&cool_map,"bam","bam");
	printf("PASSED\r\nDUPLICATE KEY\t");
	printf("%d\r\n",map_put(&cool_map,"bom","bom"));
	printf("%d\r\n",map_size(&cool_map));
	printf("%d\r\n",map_remove(&cool_map,"fkkka"));
	printf("%s\r\n",map_get(&cool_map,"f**k"));

}
Exemple #21
0
// test check for valid hash block size
void test_block_size_0() {
  // clean up from any previous run
  rm_hashdb_dir(temp_dir1);

  // create new hashdb
  hashdb_settings_t settings;
  settings.hash_block_size = 0;
  commands_t::create(settings, temp_dir1);

  // import
  commands_t::import(temp_dir1, sample_dfxml4096, "test_repository_name");

  // with hash_block_size=0, total should be every hash, including remainder
  BOOST_TEST_EQ(map_size(temp_dir1), 75);
}
Exemple #22
0
int main() {
    map *m = map_create(&demo_type);
    assert(m != NULL);
    char *key = NULL;
    char *val = NULL;
    srand(time(NULL));
    int i = 0, j = 0;
    //key = malloc()
//    map_insert(m, "hellofjwoefjoewjfo", "world");
    for (i = 0; i < 100; i++) {
        key = malloc(sizeof(char) * 16);
        val = malloc(sizeof(char) * 16);
        for (j = 0; j < 15; j ++) {
            key[j] = 'a' + rand_range(0, 25);
        }   
        for (j = 0; j < 15; j++) {
            val[j] = 'a' + rand_range(0, 25);
        }   
        key[15] = '\0';
        val[15] = '\0';
        map_insert(m, key, val);
    }
    printf("map_size: %d\n", map_size(m));
    struct timeval start, end;
    gettimeofday(&start, NULL);
    void *n = map_find(m, "hellofjwoefjoewjfo");
    gettimeofday(&end, NULL);
    assert(n == NULL);
//    printf("%s\n", (char *)n);
    int waist = (end.tv_sec - start.tv_sec) * 100000 + (end.tv_usec - start.tv_usec);
    printf("waist time: %d, start:(sec: %d, usec: %d), end(sec: %d, usec: %d)\n", waist,
            start.tv_sec, start.tv_usec, end.tv_sec, end.tv_usec);

    map_iterator *mi = map_get_iterator(m);
    assert(mi != NULL);
    pair *data;
    while ((data = map_next(mi))) {
        printf("key: %s => val: %s\n", (char *)(((pair *)data)->first), (char *)(((pair*)data)->second));
    }
    map_release_iterator(mi);
    map_release(m);
}
Exemple #23
0
// maps:values/1 [17]
term_t cbif_values1(proc_t *proc, term_t *regs)
{
	term_t Map = regs[0];
	if (!is_boxed_map(Map))
		badarg();

	term_t out = nil;
	t_map_t *m = (t_map_t *)peel_boxed(Map);
	int n = map_size(m);
	term_t *v = m->values;

	v += n;
	while (n-- > 0)
	{
		v--;
		out = heap_cons(&proc->hp, *v, out);
	}
	
	return out;
}
Exemple #24
0
void sensor_sense(Sensor s) {
  Map m = s->map;
  
  mapVec pos=s->borig, sz=s->bsz;
  memset(s->vistiles, 0, sz.x*sz.y*sz.z*sizeof(perception));
  map_get_visible_tiles(m, s->vistiles, s->volume, pos, sz);
  Stimulus vistiles = stimulus_init_tile_vis_change(stimulus_new(), s->vistiles, pos, sz);
  // TCOD_console_print_left(NULL, 0, 20, "p {%f, %f, %f}, s {%f, %f, %f}", pos.x, pos.y, pos.z, sz.x, sz.y, sz.z);
  
  TCOD_list_push(s->stimuli, vistiles);
  
  TCOD_list_t oldObjList = s->visObjects; //one ago
  s->visObjects = s->oldVisObjects; //two ago
  TCOD_list_clear(s->visObjects);
  s->oldVisObjects = oldObjList;
  
  map_get_visible_objects(m, s->visObjects, s->vistiles, pos, sz);
  //remove the old objects
  Object o;
  mapVec pt;
  int index;
  Stimulus visobj;
  for(int i = 0; i < TCOD_list_size(s->oldVisObjects); i++) {
    o = TCOD_list_get(s->oldVisObjects, i);
    if(!TCOD_list_contains(s->visObjects, o)) { //not visible anymore
      //this isn't quite right, really, using percept_none here
      visobj = stimulus_init_obj_vis_change(stimulus_new(), o, percept_none, object_context(o));
      TCOD_list_push(s->stimuli, visobj);
    }
  }
  //add the new objects
  for(int i = 0; i < TCOD_list_size(s->visObjects); i++) {
    o = TCOD_list_get(s->visObjects, i);
    if(!TCOD_list_contains(s->oldVisObjects, o)) { //not visible before
      pt = object_position(o);
      index = tile_index(pt.x, pt.y, pt.z, map_size(m), pos, sz);
      visobj = stimulus_init_obj_vis_change(stimulus_new(), o, s->vistiles[index], object_context(o));
      TCOD_list_push(s->stimuli, visobj);
    }
  }
}
Exemple #25
0
// database manipulation commands
void test_database_manipulation() {
  hashdb_settings_t settings;
  rm_hashdb_dir(temp_dir1);
  rm_hashdb_dir(temp_dir2);
  rm_hashdb_dir(temp_dir3);
  rm_hashdb_dir(temp_dir4);
  rm_hashdb_dir(temp_dir5);
  rm_hashdb_dir(temp_dir6);
  rm_hashdb_dir(temp_dir7);
  rm_hashdb_dir(temp_dir8);
  commands_t::create(settings, temp_dir1);
  commands_t::import(temp_dir1, sample_dfxml4096, "repository1");
  commands_t::create(settings, temp_dir2);
  commands_t::import(temp_dir2, sample_dfxml4096, "repository2");
  commands_t::add_multiple(temp_dir1, temp_dir2, temp_dir3);

  // add
  commands_t::add(temp_dir1, temp_dir4);
  BOOST_TEST_EQ(map_size(temp_dir4), 74);
  commands_t::add(temp_dir1, temp_dir4);
  BOOST_TEST_EQ(map_size(temp_dir4), 74);
  commands_t::add(temp_dir2, temp_dir4);
  BOOST_TEST_EQ(map_size(temp_dir4), 2*74);
  rm_hashdb_dir(temp_dir4);

  // add_multiple
  std::cout << "add_multiple\n";
  commands_t::add_multiple(temp_dir1, temp_dir2, temp_dir4);
  BOOST_TEST_EQ(map_size(temp_dir3), 2*74);
  commands_t::add_multiple(temp_dir1, temp_dir2, temp_dir4);
  BOOST_TEST_EQ(map_size(temp_dir3), 2*74);
  rm_hashdb_dir(temp_dir4);

  // add_repository
  std::cout << "add_repository\n";
  commands_t::add_repository(temp_dir1, temp_dir4, "invalid_repository");
  BOOST_TEST_EQ(map_size(temp_dir4), 0);
  commands_t::add_repository(temp_dir1, temp_dir4, "repository1");
  BOOST_TEST_EQ(map_size(temp_dir4), 74);
  commands_t::add_repository(temp_dir1, temp_dir4, "repository1");
  BOOST_TEST_EQ(map_size(temp_dir4), 74);
  commands_t::add_repository(temp_dir2, temp_dir4, "repository1");
  BOOST_TEST_EQ(map_size(temp_dir4), 74);
  commands_t::add_repository(temp_dir2, temp_dir4, "repository2");
  BOOST_TEST_EQ(map_size(temp_dir4), 2*74);
  rm_hashdb_dir(temp_dir4);

  // intersect
  std::cout << "intersect\n";
  commands_t::intersect(temp_dir1, temp_dir2, temp_dir4);
  BOOST_TEST_EQ(map_size(temp_dir4), 0);
  commands_t::intersect(temp_dir1, temp_dir3, temp_dir4);
  BOOST_TEST_EQ(map_size(temp_dir4), 74);
  rm_hashdb_dir(temp_dir4);

  // intersect hash
  std::cout << "intersect_hash\n";
  commands_t::intersect_hash(temp_dir1, temp_dir2, temp_dir4);
  BOOST_TEST_EQ(map_size(temp_dir4), 2*74);
  commands_t::intersect_hash(temp_dir1, temp_dir2, temp_dir4);
  BOOST_TEST_EQ(map_size(temp_dir4), 2*74);
  rm_hashdb_dir(temp_dir4);

  // subtract
  std::cout << "subtract\n";
  commands_t::subtract(temp_dir3, temp_dir1, temp_dir4);
  BOOST_TEST_EQ(map_size(temp_dir4), 74);
  commands_t::subtract(temp_dir3, temp_dir1, temp_dir4);
  BOOST_TEST_EQ(map_size(temp_dir4), 74);
  commands_t::add(temp_dir2, temp_dir4);
  BOOST_TEST_EQ(map_size(temp_dir4), 74);
  commands_t::add(temp_dir1, temp_dir4);
  BOOST_TEST_EQ(map_size(temp_dir4), 2*74);
  commands_t::subtract(temp_dir3, temp_dir2, temp_dir4);
  BOOST_TEST_EQ(map_size(temp_dir4), 2*74);
  commands_t::subtract(temp_dir3, temp_dir4, temp_dir5);
  BOOST_TEST_EQ(map_size(temp_dir5), 0);
  rm_hashdb_dir(temp_dir4);
  rm_hashdb_dir(temp_dir5);

  // subtract_hash
  std::cout << "subtract_hash\n";
  commands_t::subtract_hash(temp_dir3, temp_dir1, temp_dir4);
  BOOST_TEST_EQ(map_size(temp_dir4), 0);
  rm_hashdb_dir(temp_dir4);

  // deduplicate
  std::cout << "deduplicate1\n";
  commands_t::create(settings, temp_dir6);
  commands_t::import(temp_dir6, sample_dfxml4096, "repository1");
  commands_t::deduplicate(temp_dir6, temp_dir7);
  BOOST_TEST_EQ(map_size(temp_dir7), 74);
  std::cout << "deduplicate2\n";
  commands_t::import(temp_dir6, sample_dfxml4096, "repository2");
  commands_t::deduplicate(temp_dir6, temp_dir8);
  // check ability to open existing target
  commands_t::deduplicate(temp_dir6, temp_dir8);
  BOOST_TEST_EQ(map_size(temp_dir8), 0);
}
Exemple #26
0
bool map_empty(map *m) {
    return map_size(m) == 0;
}
Exemple #27
0
void gs_flatmap_setup_acc(const sint *handle, int n, struct gs_data **fgs_info)
{
  struct pw_data *pwd;
  uint    m_size,fp_m_size,snd_m_size,rcv_m_size,t_m_size;
  uint    i,j,k;
  int     m_nt,fp_m_nt,snd_m_nt,rcv_m_nt,t_m_nt;
  int    *map,*t_map,*fp_map,*snd_map,*rcv_map;
  int    *mapf,*t_mapf,*fp_mapf,*snd_mapf,*rcv_mapf;

  pwd     = fgs_info[*handle]->r.data;
  // Flatten...
  map        = (int*)(fgs_info[*handle]->map_local[0]);
  t_map      = (int*)(fgs_info[*handle]->map_local[1]);
  fp_map     = (int*)(fgs_info[*handle]->flagged_primaries);
  snd_map    = (int*)(pwd->map[1]);
  rcv_map    = (int*)(pwd->map[0]);

  fp_m_size  = map_size(fp_map,&fp_m_nt);
  m_size     = map_size(map,&m_nt);  
  snd_m_size = map_size(snd_map,&snd_m_nt);
  rcv_m_size = map_size(rcv_map,&rcv_m_nt);
  t_m_size   = map_size(t_map,&t_m_nt);

  fgs_info[*handle]->u_size        = n;
  fgs_info[*handle]->fp_m_size     = fp_m_size;
  fgs_info[*handle]->m_size[0]     = m_size;
  fgs_info[*handle]->snd_m_size[1] = snd_m_size;
  fgs_info[*handle]->snd_m_size[0] = rcv_m_size;
  fgs_info[*handle]->m_size[1]     = t_m_size;
  fgs_info[*handle]->m_nt[0]       = m_nt;
  fgs_info[*handle]->fp_m_nt       = fp_m_nt;
  fgs_info[*handle]->snd_m_nt[1]   = snd_m_nt;
  fgs_info[*handle]->snd_m_nt[0]   = rcv_m_nt;
  fgs_info[*handle]->m_nt[1]       = t_m_nt;
  

  mapf = (int*)malloc(m_nt*2*sizeof(int));
  for(i=0,k=0;map[i]!=-1;i=j+1,k++){
      // Record i
    mapf[k*2] = i;
      for(j=i+1;map[j]!=-1;j++);
      // Record j-i
      mapf[k*2+1] = j-i-1;
  }

  t_mapf = (int*)malloc(t_m_nt*2*sizeof(int));
  for(i=0,k=0;t_map[i]!=-1;i=j+1,k++){
      // Record i
      t_mapf[k*2] = i;
      for(j=i+1;t_map[j]!=-1;j++);
      // Record j-i
      t_mapf[k*2+1] = j-i-1;
  }

  fp_mapf = (int*)malloc(fp_m_nt*2*sizeof(int));
  for(k=0;k<fp_m_nt;k++){
    // Record i
    fp_mapf[k*2] = 0;
    for(i=0;fp_map[i]!=-1;i++);
    // Record j-i
    fp_mapf[k*2+1] = i;
  }

  snd_mapf = (int*)malloc(snd_m_nt*2*sizeof(int));
  for(i=0,k=0;snd_map[i]!=-1;i=j+1,k++){
    // Record i
    snd_mapf[k*2] = i;
    for(j=i+1;snd_map[j]!=-1;j++);
    // Record j-i
    snd_mapf[k*2+1] = j-i-1;
  }

  rcv_mapf = (int*)malloc(rcv_m_nt*2*sizeof(int));
  for(i=0,k=0;rcv_map[i]!=-1;i=j+1,k++){
    // Record i
    rcv_mapf[k*2] = i;
    for(j=i+1;rcv_map[j]!=-1;j++);
    // Record j-i
    rcv_mapf[k*2+1] = j-i-1;
  }

  //Store flattened maps
  fgs_info[*handle]->mapf[0]  = mapf;
  fgs_info[*handle]->mapf[1]  = t_mapf;
  fgs_info[*handle]->fp_mapf  = fp_mapf;
  fgs_info[*handle]->snd_mapf[1] = snd_mapf;
  fgs_info[*handle]->snd_mapf[0] = rcv_mapf;

#if 0
  fprintf(stderr,"%d map[0:%d]     -> %lX : %lX\n",m_nt,m_size,map,map+m_size);
  fprintf(stderr,"%d t_map[0:%d]   -> %lX : %lX\n",t_m_nt,t_m_size,t_map,t_map+t_m_size);
  fprintf(stderr,"%d fp_map[0:%d]  -> %lX : %lX\n",fp_m_nt,fp_m_size,fp_map,fp_map+fp_m_size);
  fprintf(stderr,"%d snd_map[0:%d] -> %lX : %lX\n",snd_m_nt,snd_m_size,snd_map,snd_map+snd_m_size);
  fprintf(stderr,"%d rcv_map[0:%d] -> %lX : %lX\n",rcv_m_nt,rcv_m_size,rcv_map,rcv_map+rcv_m_size);
  fprintf(stderr,"mapf[0:%d]     -> %lX : %lX\n",m_nt,mapf,mapf+2*m_nt);
  fprintf(stderr,"t_mapf[0:%d]   -> %lX : %lX\n",t_m_nt,t_mapf,t_mapf+2*t_m_nt);
  fprintf(stderr,"fp_mapf[0:%d]  -> %lX : %lX\n",fp_m_nt,fp_mapf,fp_mapf+2*fp_m_nt);
  fprintf(stderr,"snd_mapf[0:%d] -> %lX : %lX\n",snd_m_nt,snd_mapf,snd_mapf+2*snd_m_nt);
  fprintf(stderr,"rcv_mapf[0:%d] -> %lX : %lX\n",rcv_m_nt,rcv_mapf,rcv_mapf+2*rcv_m_nt);
#endif

  #pragma acc enter data copyin(t_mapf[0:t_m_nt*2],mapf[0:m_nt*2],snd_mapf[0:snd_m_nt*2],rcv_mapf[0:rcv_m_nt*2],fp_mapf[0:fp_m_nt*2], t_map[0:t_m_size],map[0:m_size],fp_map[0:fp_m_size],snd_map[0:snd_m_size],rcv_map[0:rcv_m_size])

  return;
}
struct _attr_ret_ _attribute_add_children_(container *attributes, container *attr_query, container *hide, container *A, int container_id)
{
    int		i, j;
    container	*list_items = vector_container( ptr_container() );
    iterator	it_m1 = map_begin(attributes);
    int		has_selected_child = 0;

    for (; it_m1.valid; it_m1=map_next(it_m1))
	{
	    vector_pushback(attr_query, (char*)map_key(it_m1).ptr);

	    int		is_hidden = 0;
	    for (i=0; i<vector_size(hide) && !is_hidden; i++)
		{
		    container	*hide_elem = vector_get(hide, i).C;

		    for (j=0; j<vector_size(hide_elem); j++)
			{
			    if (strcasecmp(vector_get(attr_query,j).ptr, vector_get(hide_elem,j).ptr)) break;
			}

		    if (j>=vector_size(hide_elem)) is_hidden = 1;
		}

	    if (is_hidden)
		{
		    vector_remove_last(attr_query);
		    continue;
		}

	    struct _attr_tree_	*this_item = _attribute_tree_malloc_();
	    int val = _attribute_is_selected_(A, attr_query, container_id);
	    if (val>=0) this_item->selected = val;

	    if (map_size(pair(map_val(it_m1)).first.ptr) > 0)
		{
		    struct _attr_ret_ ret = _attribute_add_children_(pair(map_val(it_m1)).first.ptr, attr_query, hide, A, container_id);
		    if (ret.selected_descendant)
			{
			    this_item->selected_descendant = 1;
			    has_selected_child = 1;
			}
		    this_item->children = ret.C;
		    this_item->query_param = vector_container( string_container() );
		    for (j=0; j<vector_size(attr_query); j++)
			vector_pushback(this_item->query_param, vector_get(attr_query, j).ptr);
		    //this_item->name = ;
		    this_item->count = pair(map_val(it_m1)).second.ptr;
		}
	    else
		{
		    this_item->query_param = vector_container( string_container() );
		    for (j=0; j<vector_size(attr_query); j++)
			vector_pushback(this_item->query_param, vector_get(attr_query, j).ptr);
		    //this_item->name = ;
		    this_item->count = pair(map_val(it_m1)).second.ptr;
		}

	    vector_remove_last(attr_query);

	    if (this_item->name == NULL && this_item->query_param == NULL && this_item->count == NULL && this_item->children == NULL)
		{
		    free(this_item);
		}
	    else
		{
		    vector_pushback(list_items, this_item);
		    if (this_item->selected >= 0) has_selected_child = 1;
		}
	}

    struct _attr_ret_	ret;
    ret.C = list_items;
    ret.selected_descendant = has_selected_child;
    return ret;
}
struct _attr_ret_ _attribute_build_tree_(container *attributes, struct attr_group *parent, container *A, int *container_id)
{
    int		i, j;
    container	*list_items = vector_container( ptr_container() );
    int		has_selected_child = 0;

    for (i=0; i<vector_size(parent->child); i++)
	{
	    struct _attr_tree_	*this_item = _attribute_tree_malloc_();

	    switch (pair(vector_get(parent->child,i)).first.i)
	        {
		    case item_select:
		        {
			    struct attr_select	*S = pair(vector_get(parent->child,i)).second.ptr;

			    container	*subattrp = attributes;
			    container	*attr_query = vector_container( string_container() );
			    iterator	it_m1;
			    it_m1.valid = 0;

			    //printf("Select ");
			    for (j=0; j<S->size; j++)
				{
				    //if (j>0) printf("/");
				    //printf("%s", S->select[j]);
				    it_m1 = map_find(subattrp, S->select[j]);
				    if (it_m1.valid) subattrp = pair(map_val(it_m1)).first.ptr;
				    else break;
				    vector_pushback(attr_query, S->select[j]);
				}
			    //printf("\n");

			    if (it_m1.valid)
				{
				    this_item->query_param = attr_query;
				    this_item->count = pair(map_val(it_m1)).second.ptr;
				    this_item->sort = parent->sort;
				    this_item->sort_reverse = parent->flags & sort_reverse;
				    int val = _attribute_is_selected_(A, attr_query, *container_id);
				    if (val>=0) this_item->selected = val;

				    if (map_size(subattrp) > 0)
					{
					    //printf("  Generate subpattern children\n");
					    struct _attr_ret_ ret = _attribute_add_children_(subattrp, attr_query, parent->hide, A, *container_id);
					    if (ret.selected_descendant)
						{
						    this_item->selected_descendant = 1;
						    has_selected_child = 1;
						}

					    if (S->flags & build_groups)
						{
						    this_item->children = ret.C;
						}
					    else
						{
						    for (j=0; j<vector_size(ret.C); j++)
							vector_pushback(list_items, vector_get(ret.C,j).ptr);
						    this_item->query_param = NULL;
						    this_item->count = NULL;
						    this_item->children = NULL;
						    this_item->name = NULL;
						}

					    if (this_item->children == NULL) destroy(ret.C);
					}
				    //else
					//{
					//    printf("  No children\n");
					//}

				}
			    else	// Zero hits:
				{
				    //printf("  Zero hits\n");
				    /*
				    if (parent->flags & show_empty)
					{
					    this_item->query_param = attr_query;
					    int val = _attribute_is_selected_(A, attr_query, *container_id);
					    if (val>=0) this_item->selected = val;
					    this_item->show_empty = 1;
					    //printf("    (show anyway)\n");
					}
				    */
				}

			    if (this_item->query_param == NULL) destroy(attr_query);
			    break;
			}
		    case item_group:
			{
			    //printf("Creating new container {\n");
			    struct attr_group		*G = pair(vector_get(parent->child,i)).second.ptr;
			    this_item->name = strdup(G->name);
			    this_item->free_name = 1;
			    this_item->expanded = G->flags & is_expanded;
			    this_item->sort = G->sort;
			    this_item->sort_reverse = G->flags & sort_reverse;
			    this_item->show_empty = G->flags & show_empty;
			    this_item->max_items = G->max_items;

			    (*container_id)++; // NB! Will fail miserably for recursive container-groups.
			    this_item->container_id = *container_id;
			    //printf("  Container #id: %i\n", this_item->container_id);
			    struct _attr_ret_ ret = _attribute_build_tree_(attributes, G, A, container_id);
			    if (ret.selected_descendant)
				{
				    this_item->selected_descendant = 1;
				    has_selected_child = 1;
				}

			    this_item->children = ret.C;

			    //printf("}\n");
			    break;
			}
		    case item_import:
			{
			    struct attr_import	*I = pair(vector_get(parent->child,i)).second.ptr;
			    break;
			}
		}

	    if (this_item->name == NULL && this_item->query_param == NULL && this_item->count == NULL && this_item->children == NULL)
		{
		    free(this_item);
		}
	    else
		{
		    vector_pushback(list_items, this_item);
		    if (this_item->selected >= 0) has_selected_child = 1;
		}
	}

    struct _attr_ret_	ret;
    ret.C = list_items;
    ret.selected_descendant = has_selected_child;
    return ret;
}
Exemple #30
0
int main(int argc, char **argv)
{
    llist_t *paths,*src,*todo;
    set_t *incl;
    map_t *deps;

    if (argc < 2) {
        fprintf(stderr,"FastDep v%s for LAMMPS\n"
                "Usage: %s [-I <path> ...] -- <src1> [<src2> ...]\n",
                version,argv[0]);
        fprintf(stderr,"Supported extensions: %s, %s, %s\n",
                extensions[0], extensions[1], extensions[2]);
        return 1;
    }

    /* hash tables for all known included files and dependencies
     * we guesstimate a little over 2x as many entries as sources. */
    incl = set_init(2*argc);
    deps = map_init(2*argc);

    /* list of include search paths. prefixed by "." and "..". */
    paths = llist_init();
    llist_append(paths,".");
    llist_append(paths,"..");

    while (++argv, --argc > 0) {
        if (strncmp(*argv, "-I", 2) == 0) {
            if ((*argv)[2] != '\0') {
                llist_append(paths,trim_path(*argv+2));
            } else {
                ++argv;
                --argc;
                if (argc > 0) {
                    if (strcmp(*argv,"--") == 0) {
                        break;
                    } else {
                        llist_append(paths,trim_path(*argv));
                    }
                }
            }
        } else if (strcmp(*argv,"--") == 0) {
            break;
        } /* ignore all unrecognized arguments before '--'. */
    }

    src = llist_init();
    while (++argv, --argc > 0) {
        llist_append(src,*argv);
    }

    /* process files to look for includes */
    todo = llist_init();
    find_includes(src->head,todo,paths,incl,deps);
    find_includes(todo->head,todo,paths,incl,deps);
    llist_free(todo);

    fprintf(stdout,"# FastDep v%s for LAMMPS\n",version);
    fputs("# Search path: ",stdout);
    llist_print(paths);
    fprintf(stdout,"# % 5d sources\n# % 5d includes\n# % 5d depfiles\n",
            llist_size(src),set_size(incl),map_size(deps));

    set_free(incl);
    do_depend(src->head,deps);

    llist_free(src);
    llist_free(paths);
    map_free(deps);
    return 0;
}