Beispiel #1
0
LXUInteger LXMapCount(LXMapPtr r)
{
    if ( !r) return 0;
    map_t map = (map_t)r;
    
    return hashmap_length(map);
}
Beispiel #2
0
void LXMapCopyEntriesFromMap(LXMapPtr dstMap, LXMapPtr obj)
{
    if ( !dstMap || !obj) return;
    map_t sourceMap = (map_t)obj;
    
    int len = hashmap_length(sourceMap);
    if (len > 0) {
        const char **keys = _lx_malloc(len * sizeof(char *));
        hashmap_get_keys_array(sourceMap, keys, len);
        
        int i;
        for (i = 0; i < len; i++) {
            const char *key = keys[i];
            LXMapValue *srcVal = NULL;
            hashmap_get(sourceMap, key, (any_t *)&srcVal);
            if (srcVal) {
                LXPropertyType propType = LXMapValueTypeGetType(srcVal->type);
                switch (propType) {
                    case kLXBoolProperty: {
                        LXInteger integer = (LXInteger)(srcVal->data);
                        LXMapSetBool(dstMap, key, (integer) ? YES : NO);
                        break;
                    }
                    case kLXFloatProperty:
                        LXMapSetDouble(dstMap, key, *((double *)srcVal->data));
                        break;
                    case kLXIntegerProperty:
                        if (LXMapValueTypeGetFlags(srcVal->type) & kLXMapValueIsInt64) {
                            LXMapSetInt64(dstMap, key, *((int64_t *)srcVal->data));
                        } else {
                            LXMapSetInteger(dstMap, key, (LXInteger)(srcVal->data));
                        }
                        break;
                    case kLXStringProperty:
                        LXMapSetUTF16(dstMap, key, *((LXUnibuffer *)srcVal->data));
                        break;
                    case kLXRefProperty:
                        LXMapSetObjectRef(dstMap, key, (LXRef)srcVal->data);
                        break;
                    case kLXMapProperty:
                        LXMapSetMap(dstMap, key, (LXMapPtr)srcVal->data);
                        break;
                }
            }
        }
        
        _lx_free(keys);
    }
}
Beispiel #3
0
// Unregisters a topic subscription for a peer. Returns -1 on failure, 0 on
// success.
int unsubscribe(struct sn_client* self,uint32_t channel_id)
{
    int err = 0;
    char fd_str[10];
    sprintf(fd_str, "%d", self->fd);
    map_t* subscribers;
    if (hashmap_get(self->thread->pubsub, channel_id, (void**) &subscribers) == MAP_OK)
    {
        hashmap_remove(subscribers, self->fd);
        if(hashmap_length(subscribers)<=0){
            hashmap_free(subscribers);
            hashmap_remove(self->thread->pubsub,channel_id);
        };
    }
    else
    {
        err = -1;
    }
    return err;
    
}
Beispiel #4
0
/*
 * Get a random element from the hashmap
 */
int hashmap_get_one(hashmap_t hashmap, hashmap_item_t *arg, int remove)
{
	int i;

	if (hashmap_length(hashmap) <= 0) 	
		return -1;

	for (i = 0; i< hashmap->table_size; i++)
		if (hashmap->data[i]->in_use != 0)
		{
			*arg = (hashmap_item_t) (hashmap->data[i]->data);
			if (remove) 
			{
				hashmap->data[i]->in_use = 0;
				hashmap->size--;
			}
			return 0;
		}

	return 0;
}
Beispiel #5
0
/*
 * Iterate the function parameter over each element in the hashmap.  The
 * additional any_t argument is passed to the function as its first
 * argument and the hashmap element is the second.
 */
int hashmap_iterate(map_t in, PFany f, any_t item) {
	int i;

	/* Cast the hashmap */
	hashmap_map* m = (hashmap_map*) in;

	/* On empty hashmap, return immediately */
	if (hashmap_length(m) <= 0)
		return MAP_MISSING;	

	/* Linear probing */
	for(i = 0; i< m->table_size; i++)
		if(m->data[i].in_use != 0) {
                        any_t data = m->data[i].data;
                        int status = f(item, m->data[i].key, data);
			if (status != MAP_OK) {
				return status;
			}
		}

    return MAP_OK;
}
Beispiel #6
0
void load_domainlist(const char *path) {
    char line[MAX_LINE];
    char trimmed[MAX_LINE];

    domainlist = hashmap_new();

    // parse all files in directory
    logerr("Parsing domain-list: %s\n", path);
    listdir = opendir(path);
    if(!listdir) {
        perror(path);
        exit(1); }

    // read file by file
    dp = readdir (listdir);
    while (dp) {
        char fullpath[MAX_LINE];
        snprintf(fullpath,MAX_LINE,"%s/%s",path,dp->d_name);
        // open and read line by line
        fp = fopen(fullpath,"r");
        if(!fp) {
            perror(fullpath);
            continue; }
        while(fgets(line,MAX_LINE, fp)) {
            // save lines in hashmap with filename as value
            if(line[0]=='#') continue; // skip comments
            trim(trimmed, strlen(line), line);
            if(trimmed[0]=='\0') continue; // skip blank lines
            // logerr("(%u) %s\t%s", trimmed[0], trimmed, dp->d_name);
            hashmap_put(domainlist, strdup(trimmed), strdup(dp->d_name));
        }
        fclose(fp);
        dp = readdir (listdir);
    }
    closedir(listdir);
    logerr("Size of parsed domain-list: %u\n", hashmap_length(domainlist));
}
void Arena::Finish()
{
	m_ended = true;
	ArenaTeam * teams[2] = {NULL, NULL};
	if(rated_match)
	{
		teams[0] = objmgr.GetArenaTeamById(m_teams[0]);
		teams[1] = objmgr.GetArenaTeamById(m_teams[1]);
	}
	/* update arena team stats */
	if(rated_match && teams[0] && teams[1])
	{
		for (uint32 i = 0; i < 2; ++i) {
			uint32 j = i ? 0 : 1; // opposing side
			bool outcome = (i != m_losingteam);
			if (outcome) {
				teams[i]->m_stat_gameswonseason++;
				teams[i]->m_stat_gameswonweek++;
			}

			m_deltaRating[i] = CalcDeltaRating(teams[i]->m_stat_rating, teams[j]->m_stat_rating, outcome);
			teams[i]->m_stat_rating += m_deltaRating[i];
			if ((int32)teams[i]->m_stat_rating < 0) teams[i]->m_stat_rating = 0;

			for (int x=0; x<hashmap_length(m_players2[i]); x++) {
				uint32 key;
				if (MAP_OK == hashmap_get_index(m_players2[i], x, (int*)&key, (any_t*) NULL)) {
					PlayerInfo * info = objmgr.GetPlayerInfo(key);
					if (info) {
						ArenaTeamMember * tp = teams[i]->GetMember(info);

						if(tp != NULL) {
							tp->PersonalRating += CalcDeltaRating(tp->PersonalRating, teams[j]->m_stat_rating, outcome);
							if ((int32)tp->PersonalRating < 0) tp->PersonalRating = 0;

							if(outcome) {
								tp->Won_ThisWeek++;
								tp->Won_ThisSeason++;
							}
						}
					}
				}
			}
			
			teams[i]->SaveToDB();
			// send arena team stats update
			WorldPacket data(256);
			teams[i]->Stat(data);
			teams[i]->SendPacket(&data);
		}
		objmgr.UpdateArenaTeamRankings();
	}

	m_nextPvPUpdateTime = 0;
	UpdatePvPData();
	PlaySoundToAll(m_losingteam ? SOUND_ALLIANCEWINS : SOUND_HORDEWINS);

	sEventMgr.RemoveEvents(shared_from_this(), EVENT_BATTLEGROUND_CLOSE);
	sEventMgr.RemoveEvents(shared_from_this(), EVENT_ARENA_SHADOW_SIGHT);
	sEventMgr.AddEvent(TO_CBATTLEGROUND(shared_from_this()), &CBattleground::Close, EVENT_BATTLEGROUND_CLOSE, 120000, 1,0);

	for(int i = 0; i < 2; i++)
	{
		bool victorious = (i != m_losingteam);
		set<PlayerPointer  >::iterator itr = m_players[i].begin();
		for(; itr != m_players[i].end(); itr++)
		{
			PlayerPointer plr = (PlayerPointer )(*itr);
			plr->Root();

			if( plr->m_bgScore.DamageDone == 0 && plr->m_bgScore.HealingDone == 0 )
				continue;

			sHookInterface.OnArenaFinish(plr, m_arenateamtype, plr->m_playerInfo->arenaTeam[m_arenateamtype], victorious, rated_match);
		}
	}
}
static void generate_exp_models2(char *baseName, int maxComp, int numbOfComp)
{
	int i;
	int j;
	ContainerRoot *expModel;
	ComponentInstance *comp;
	TypeDefinition *compType;
	hashmap_map *typDefs;
	ContainerNode *node;
	hashmap_map *nodes;
	Dictionary *dico;
	DictionaryValue *dicVal;
	char compName[32];
	int k = 0;
	int mapPos;

	expModel = open_model("../models/BaseModel.json");


	for (i = 1; i <= numbOfComp; i++) {
		ContainerNode *node = new_ContainerNode();
		node->name = malloc(4);
		sprintf(node->name, "n%d", i);
		node->typeDefinition = expModel->VT->findTypeDefsByID(expModel, "ContikiNode/0.0.1");
		node->metaData = strdup("");
		node->started = true;
		printf("Groupd %s at address %\n", expModel->VT->findGroupsByID(expModel, "group0"));
		if (expModel->VT->findGroupsByID(expModel, "group0") == 0){
			fprintf(stderr, "ERROR: The group was not found\n");	
			exit(1);
		}
		if (node->typeDefinition == 0) {
			fprintf(stderr, "Error locating typedefinition\n");
			exit(1);
		}
		node->VT->addGroups(node, expModel->VT->findGroupsByID(expModel, "group0"));

		NetworkInfo *netInfo = new_NetworkInfo();
		netInfo->name = strdup("ip");

		NetworkProperty *netProp = new_NetworkProperty();
		netProp->name = strdup("local");
		netProp->value = (char*) malloc(32);
		sprintf(netProp->value, "fe80::212:74%02x:%x:%x%02x", (unsigned int)i,(unsigned int)i, (unsigned int)i, (unsigned int)i);

		netInfo->VT->addValues(netInfo, netProp);

		node->VT->addNetworkInformation(node, netInfo);

		expModel->VT->addNodes(expModel, node);
	}
		/*
		 * Add random components to model
		 */

		for (int count = 0 ; count < 50 ; count++) {

			printf("Iteration %d\n", count);
			nodes = (hashmap_map*)expModel->nodes;
			bool found = false;
			while(!found) {
				node = (ContainerNode*)nodes->data[get_map_num(50)].data;
				printf("INFO: Looking for ContainerNode %s\n", node->VT->internalGetKey(node));
				int t = 50 / 9;
				if ( 50 % 9 != 0) {
					t++;
				}
				if (hashmap_length(node->components) < t) {
					found = true;
				}
			}

			found = false;
			int randNumb;
			int z;
			hashmap_map *n;
			n = (hashmap_map*)node->components;
			typDefs = (hashmap_map*)expModel->typeDefinitions;
			while (!found) {
				bool tmp = false;
				randNumb = get_map_num(4);
				compType = (TypeDefinition*)typDefs->data[randNumb + 2].data;
				for (z = 0; n != NULL && z < n->table_size; z++) {
					ComponentInstance *ci;
					ci = (ComponentInstance*)n->data[z].data;
					if (ci->typeDefinition == compType) {
						tmp = true;
					}
				}
				found = !tmp;
			}


			printf("INFO: Looking for TypeDefinition %s\n", compType->VT->internalGetKey(compType));

			comp = new_ComponentInstance();
			sprintf(compName, "c%d", k++);
			comp->name = strdup(compName);
			comp->started = true;
			comp->metaData = strdup("");
			comp->VT->addTypeDefinition(comp, compType);

			dico = new_Dictionary();
			dicVal = new_DictionaryValue();
			switch (randNumb) {
			case 2:
				dicVal->name = strdup("name");
				dicVal->value = strdup("Paco");
				break;
			case 3:
				dicVal->name = strdup("count");
				dicVal->value = strdup("10");
				dico->VT->addValues(dico, dicVal);
				dicVal = new_DictionaryValue();
				dicVal->name = strdup("interval");
				dicVal->value = strdup("1000");
				break;
			case 0:
			case 1:
				dicVal->name = strdup("interval");
				dicVal->value = strdup("1000");
				break;

			default:
				break;
			}
			dico->VT->addValues(dico, dicVal);
			comp->VT->addDictionary(comp, dico);

			node->VT->addComponents(node, comp);

		}

		/*
		 * Serialize model to JSON file
		 */
		sprintf(modelName, "%s_%d.json", baseName, 0);
		expModel->VT->visit(expModel, "", actionstore, NULL, false);
		delete((KMFContainer*)expModel);
		printf("INFO: %s created!\n", modelName);
}
static void generate_exp_models(char *baseName, int maxComp)
{
	int i;
	int j;
	ContainerRoot *expModel;
	ComponentInstance *comp;
	TypeDefinition *compType;
	hashmap_map *typDefs;
	ContainerNode *node;
	hashmap_map *nodes;
	Dictionary *dico;
	DictionaryValue *dicVal;
	char compName[32];
	int k = 0;
	int mapPos;


	for (i = 1; i <= NUM_OF_EXP; i++) {
		for (j = 0; j < NUM_OF_IT; j++) {
			expModel = open_model("../models/9nodes0component-compactLille.json");
			/*
			 * Add random components to model
			 */

			for (int count = 0 ; count < i ; count++) {
				nodes = (hashmap_map*)expModel->nodes;
				bool found = false;
				while(!found) {
					node = (ContainerNode*)nodes->data[get_map_num(9)].data;
					printf("INFO: Looking for ContainerNode %s\n", node->VT->internalGetKey(node));
					int t = i / 9;
					if ( i % 9 != 0) {
						t++;
					}
					if (hashmap_length(node->components) < t) {
						found = true;
					}
				}

				found = false;
				int randNumb;
				int z;
				hashmap_map *n;
				n = (hashmap_map*)node->components;
				typDefs = (hashmap_map*)expModel->typeDefinitions;
				while (!found) {
					bool tmp = false;
					randNumb = get_map_num(4);
					compType = (TypeDefinition*)typDefs->data[randNumb + 2].data;
					for (z = 0; n != NULL && z < n->table_size; z++) {
						ComponentInstance *ci;
						ci = (ComponentInstance*)n->data[z].data;
						if (ci->typeDefinition == compType) {
							tmp = true;
						}
					}
					found = !tmp;
				}


				printf("INFO: Looking for TypeDefinition %s\n", compType->VT->internalGetKey(compType));

				comp = new_ComponentInstance();
				sprintf(compName, "c%d", k++);
				comp->name = strdup(compName);
				comp->started = true;
				comp->metaData = strdup("");
				comp->VT->addTypeDefinition(comp, compType);

				dico = new_Dictionary();
				dicVal = new_DictionaryValue();
				switch (randNumb) {
				case 2:
					dicVal->name = strdup("name");
					dicVal->value = strdup("Paco");
					break;
				case 3:
					dicVal->name = strdup("count");
					dicVal->value = strdup("10");
					dico->VT->addValues(dico, dicVal);
					dicVal = new_DictionaryValue();
					dicVal->name = strdup("interval");
					dicVal->value = strdup("1000");
					break;
				case 0:
				case 1:
					dicVal->name = strdup("interval");
					dicVal->value = strdup("1000");
					break;

				default:
					break;
				}
				dico->VT->addValues(dico, dicVal);
				comp->VT->addDictionary(comp, dico);

				node->VT->addComponents(node, comp);

			}

			/*
			 * Serialize model to JSON file
			 */
			sprintf(modelName, "%s_%d_%d.json", baseName, i, j);
			expModel->VT->visit(expModel, "", actionstore, NULL, false);
			delete((KMFContainer*)expModel);
			printf("INFO: %s created!\n", modelName);
		}
	}
}
/* Agent_OnUnload: This is called immediately before the shared library is
 * unloaded. This is the last code executed.
 */
JNIEXPORT void JNICALL
Agent_OnUnload(JavaVM * const vm)
{
    (void) vm;

    /* Make sure all malloc/calloc/strdup space is freed */
#ifdef DETAILED_RESULTS
    printf("%llu bytecode instructions in %i methods executed.\n", num_instructions_proccessed, hashmap_length(map));
    hashmap_free(map);
#else
    fprintf(stderr, "%llu\n", num_instructions_proccessed);
#endif
}