Exemplo n.º 1
0
int
printNodes(any_t extraData, any_t item)
{
	struct NodeItem* nodeItem = (struct NodeItem*)malloc(sizeof(struct NodeItem));
	ContainerNode *node = (ContainerNode*)item;
	nodeItem->nodeName = node->name;
	hashmap_iterate(node->networkInformation, fillAddress, &nodeItem->nodeIp);

	struct SuperData* data = (struct SuperData*)extraData;

	nodeItem->requiredDeployUnit = data->requiredDU;
	nodeItem->requiresDeployUnit = 0;

	// print components and their type
	printf("Node %s\n", node->name);
	hashmap_iterate(node->components, printComponents, nodeItem);

	if (nodeItem->requiresDeployUnit) {
		// add element to list
		list_t l = *data->l;
		list_add(l, nodeItem);
	}


	return MAP_OK;
}
Exemplo n.º 2
0
int
fillAddress(any_t extra, any_t item)
{
	NetworkInfo *nInfo = (NetworkInfo*)item;
	hashmap_iterate(nInfo->values, fillLocalAddress, extra);
	return MAP_OK;
}
Exemplo n.º 3
0
int
symcopy(struct sym *from, struct sym *to, struct allocator *al)
{
	iter_t iter;
	void *key, *data;

	to->flags = from->flags & 0xFFFF;
	to->idl_type = dupstr(from->idl_type, al);
	to->ndr_type = dupstr(from->ndr_type, al);
	to->interface = from->interface;

	hashmap_iterate(&from->attrs, &iter);
	while ((key = hashmap_next(&from->attrs, &iter))) {
		if ((data = hashmap_get(&from->attrs, key)) == NULL ||
				hashmap_put(&to->attrs, key, data) == -1) {
			AMSG("");
			return -1;
		}
	}
	linkedlist_iterate(&from->mems, &iter);
	while ((data = linkedlist_next(&from->mems, &iter))) {
		if (linkedlist_add(&to->mems, data) == -1) {
			AMSG("");
			return -1;
		}
	}

	to->name = dupstr(from->name, al);
	to->value = dupstr(from->value, al);
	to->ptr = from->ptr;
	to->align = from->align;

	return 0;
}
Exemplo n.º 4
0
void
filter_nodes(ContainerRoot* model, int children_count, char* childrenIP[], const char* deployUnitType, list_t* r)
{
	struct SuperData superData = { .l = r, .requiredDU=deployUnitType };
	// print address of each node
	hashmap_iterate(model->nodes, printNodes , &superData);

	// filter out elements if they are not in the list of children results
	list_t nodes = *r;
	LIST(tmp);
	list_init(tmp);
	for (int i = 0 ; i < children_count ; i++) {
		struct NodeItem * found = NULL;
		for (struct NodeItem* p =list_head(nodes); p != NULL ; p = list_item_next(p)) {
			if (compare_ips(childrenIP[i], p->nodeIp)) {
				found = p;
			}
		}
		if (found) { 
			list_remove(nodes, found);
			list_push(tmp, found);
		}
	}
	// now just empty the previous list
	while (list_length(nodes) > 0) {
		void* item = list_pop(nodes);
		free(item);
	}

	// now add elements to the empty list
	while (list_length(tmp) > 0) {
		void* item = list_pop(tmp);
		list_push(nodes, item);
	}
}
Exemplo n.º 5
0
// Grabs a string from a buffered queue and counts it
void *reduce(void* rArgs){
    struct reducerArgs *args = (struct reducerArgs*) rArgs;
    int mappersFinished = 0;
    int error;
    int count;
    map_t map = *(args->map);

    struct buffered_queue *conn = (args->conns)[args->reducerId]; // Corresponding buffered queue

    while (1){ // continually attempt to read until signal received all mappers done
        char *str = (char*)buffered_queue_pop(conn); // Word to reduce from buffered queue
        
        if (str == NULL) {
            // Received mappers finished signal
            break;
        } else {
            printf("Reducer %d is counting \"%s\"\n", args->reducerId, str);
            error = hashmap_get(map, str, &count);
            if (error == MAP_OK){
                hashmap_put(map, str, count + 1);
                printf("Reducer %d counted \"%s\" %d times\n", args->reducerId, str, count + 1);
            } else {
                hashmap_put(map, str, 1);
                printf("Reducer %d counted \"%s\" 1 time\n",args->reducerId, str);
            } 
        }
    }

    hashmap_iterate(map, print_result); 
    
    return NULL;
}
Exemplo n.º 6
0
void LXMapDestroy(LXMapPtr r)
{
    if ( !r) return;
    map_t map = (map_t)r;
    
    hashmap_iterate(map, destroyMapValue, NULL);
    hashmap_free(map);
}
Exemplo n.º 7
0
void help_action(vector_t *arguments) {
    // basically I did a little hack where the hashmap
    // is the first argument on here
    map_t *commands = get_vector_item(arguments, 0);

    printf("%s\n", help_template);
    hashmap_iterate(commands, print_command, NULL);
    printf("\n");
}
Exemplo n.º 8
0
// Publishes the given message to all peers subscribing to the message topic.
// Returns -1 on failure, 0 on success.
int publish(struct sn_client* self,uint32_t channel_id, msg_t* msg)
{
    map_t* subscribers;
    if (hashmap_get(self->thread->pubsub, channel_id, (void**) &subscribers) == MAP_OK)
    {
        hashmap_iterate(subscribers, send_msg ,msg);
    }else
        return -1;
  
    return 0;
}
Exemplo n.º 9
0
_public_ const char* sd_bus_track_next(sd_bus_track *track) {
        const char *n = NULL;

        if (!track)
                return NULL;

        if (track->modified)
                return NULL;

        hashmap_iterate(track->names, &track->iterator, (const void**) &n);
        return n;
}
Exemplo n.º 10
0
_public_ const char* sd_bus_track_first(sd_bus_track *track) {
        const char *n = NULL;

        if (!track)
                return NULL;

        track->modified = false;
        track->iterator = ITERATOR_FIRST;

        hashmap_iterate(track->names, &track->iterator, (const void**) &n);
        return n;
}
Exemplo n.º 11
0
void fetch_action(vector_t *arguments) {
	load_t *project_config_loader = load_project_config();
	if (!project_config_loader) {
		printf("error: are you sure the current directory contains an Ark project?\n");
        return;
	}
    table_t *deps = get_table(project_config_loader, "dependencies");
    if (!deps) {
 		printf("error: [dependencies] was not found in the config file!\n");
 		return;
    }
    hashmap_iterate(deps->nodes, dependencies_iterate, false);
}
Exemplo n.º 12
0
// Exception callback
// VM Death callback
static void JNICALL
callbackVMDeath(jvmtiEnv * const jvmti_env, JNIEnv * const jni_env)
{
    (void) jvmti_env;
    (void) jni_env;

#ifdef DETAILED_RESULTS
    enter_critical_section(jvmti);

    hashmap_iterate(map, &print_method_info, NULL);

    exit_critical_section(jvmti);
#endif
}
Exemplo n.º 13
0
Arquivo: cvcl.c Projeto: MohsinN/jpf
void freeStuff()
{
  iter_t iter; char* varname;
  hashmap_iterate(&vars, &iter);
  while ((varname = (char*) hashmap_next(&vars, &iter)))
    free(varname);
  hashmap_clear(&vars, NULL, NULL, NULL);
  Expr el;
  linkedlist_iterate(&exprPool, &iter);
  while ((el = linkedlist_next(&exprPool, &iter))){
    vc_deleteExpr(el);
  }
  linkedlist_clear(&exprPool, NULL, NULL);
}
Exemplo n.º 14
0
int
print_values(struct hashmap *words)
{
	iter_t iter;
	char *word;
	int val;

	hashmap_iterate(words, &iter);
	while ((word = hashmap_next(words, &iter))) {
		val = (int)hashmap_get(words, word);
		fprintf(stderr, "%d %s\n", val, word);
	}

	return 0;
}
Exemplo n.º 15
0
int
sprint_sym(char *buf, struct sym *sym, int indent, int spacer)
{
	char *bp = buf, *key;
	int i, fill = spacer * 2;
	iter_t iter;

	bp += sprintf(bp, "%3d ", sym->id);

	for (i = 0; i < 15; i++) {
		if ((sym->flags & (1 << i))) {
			*bp++ = FLAGS[i];
		}
	}
	FILL(buf, bp, 9 + indent);
	bp += sprintf(bp, "%s", NN(sym->idl_type));
	FILL(buf, bp, fill); fill += spacer;
	bp += sprintf(bp, "%d ", sym->ptr);
	bp += sprintf(bp, "%c ", PTR_TYPES[sym->ptr_type]);
	bp += sprintf(bp, "%s", NN(sym->name));
	FILL(buf, bp, fill); fill += spacer;
	bp += sprintf(bp, "%s", NN(sym->out_type));
	FILL(buf, bp, fill); fill += spacer / 2;
	bp += sprintf(bp, "%s", NN(sym->ndr_type));
	FILL(buf, bp, fill); fill += spacer;
	bp += sprintf(bp, "%3d %3d %3d ", sym->ndr_size, sym->align, sym->offset);
	bp += sprintf(bp, "(%s) %d ", NN(sym->interface), IS_IMPORTED(sym));

	i = 0;
	hashmap_iterate(&sym->attrs, &iter);
	while ((key = hashmap_next(&sym->attrs, &iter))) {
		const char *val = hashmap_get(&sym->attrs, key);
		if (i++) {
			*bp++ = ',';
		}
		if (key == val) {
			bp += sprintf(bp, "%s", key);
		} else {
			bp += sprintf(bp, "%s=%s", key, val);
		}
	}

	return bp - buf;
}
Exemplo n.º 16
0
void dowse_stop() {
    /*
     * The "start" function is called once, when the program
     * is exiting normally.  It might be used to clean up state,
     * free memory, etc.
     */

    if(fileout) fclose(fileout);

    if(listdir) {
        hashmap_iterate(domainlist, free_domainlist_f, NULL);
        hashmap_free(domainlist);
    }

    // free the map
    hashmap_free(visited);

    redisFree(redis);
}
void   minpf_cleanup_plugin_manager(void)
{
    if (managerInstance) {
        size_t i = 0;

        for (i = 0; i < managerInstance->num_exit_functions; ++i)
			managerInstance->exit_functions[i]();

        for (i = 0; i < managerInstance->num_libraries; ++i) {
            if (managerInstance->dynamic_libraries[i])
                free(managerInstance->dynamic_libraries[i]);
        }

        hashmap_iterate(managerInstance->plugins, minpf_free_hash_value, NULL);
        hashmap_free(managerInstance->plugins);
        free(managerInstance);
    }
	managerInstance = NULL;
}
Exemplo n.º 18
0
int main(char * argv,int argc)
{
#if defined(DEBUG)
    atexit(report_mem_leak);
#endif
    _fileNameNode *pFiles = getFileNameByDir(INFILEPATH);
    _fileNameNode *pCur = pFiles;
    map_t mymap;
    mymap = hashmap_new(2000000ul);
    while(pCur) {
        /*
         * 对每个文件操作
         */
        //doFilter(mymap,pCur->fileName);
        doWork(mymap,pCur->fileName);
        pCur=pCur->next;
    }
    hashmap_iterate(mymap,freeVale,(void *)NULL);
    hashmap_free(mymap);
    freefileNameList(pFiles);
    pFiles = pCur = NULL;
    return 0;
}
Exemplo n.º 19
0
int main(int argc, char **argv)
{
	hashmap_t * map;

	if (argc != 2) {
		fprintf(stderr, "Usage: %s string\n",argv[0]);
		exit(EXIT_FAILURE);
	}

	map = (hashmap_t *)malloc(sizeof(hashmap_t));

	hashmap_init(map);

	decode(argv[1], map);

	hashmap_iterate(map,print_hashmap);

	hashmap_delete_all(map);

	hashmap_free(map);
	free(map);

	exit(0);
}
Exemplo n.º 20
0
void *set_iterate(Set *s, Iterator *i) {
        return hashmap_iterate(MAKE_HASHMAP(s), i, NULL);
}
Exemplo n.º 21
0
int
HashmapExercise(int verbose, struct cfg *cfg, char *args[])
{
	struct hashmap *h;
    int rate = 0, i, n = 0;
	int count = atoi(args[0]);
	int interval = atoi(args[1]);
	iter_t riter;
	iter_t iter;
	char *str;
	struct allocator *al = NULL;
	char *mem;
	clock_t t0;
	int chkpnt = 0;
	struct allocator *hal;

	if ((mem = malloc(0xFFFFFF)) == NULL ||
			(al = suba_init(mem, 0xFFFFFF, 1, 0)) == NULL ||
			(h = hashmap_new(hash_str, cmp_str, NULL, al)) == NULL) {
		AMSG("");
		return -1;
	}
	hal = AL(h);

/*
	if ((h = hashmap_new(hash_str, cmp_str, NULL, al)) == NULL) {
		AMSG("");
		return -1;
	}
*/
srand(0);

	t0 = clock();
if (verbose)
fprintf(stderr, "\n       time    count     size      mem\n");

	hashmap_iterate(h, &iter);
	rate_iterate(&riter);
	for (i = 0; i < count; i++) {
		if ((i % interval) == 0) {
if (verbose)
fprintf(stderr, "%2d %8ld %8d %8d %8d\n", chkpnt++, (clock() - t0) / 1000, hashmap_size(h), table_sizes[h->table_size_index], hal->alloc_total - hal->free_total);
			rate = rate_next(&riter);
		}

		if (rand() % 10 < rate) {
	        str = allocator_alloc(NULL, 8, 0);
	        sprintf(str, "%07d", n++);
	        if (hashmap_put(h, str, str) == -1) {
				AMSG("");
				return -1;
			} else {
/*fputc('+', stderr);
*/
	 	      	tcase_printf(verbose, "put %s %d\r", str, hashmap_size(h));
			}
		} else {
			if (hashmap_is_empty(h)) {
/*fputc('0', stderr);
*/
				tcase_printf(verbose, "hashmap empty\r");
			} else {
		        str = hashmap_next(h, &iter);
				if (str) {
					char *data;

	    	    	tcase_printf(verbose, "get %s %d\r", str, hashmap_size(h));
					if (hashmap_remove(h, (void **)&str, (void **)&data) == -1) {
						AMSG("");
						return -1;
					}
/*fputc('-', stderr);
*/
					tcase_printf(verbose, "rem %s %d\r", str, hashmap_size(h));
					allocator_free(NULL, str);
				} else {
/*fputc('x', stderr);
*/
					tcase_printf(verbose, "nothing left to iterate over\r");
					hashmap_iterate(h, &iter);
				}
			}
		}
    }

if (verbose)
fprintf(stderr, "%2d %8ld %8d %8d %8d\n", chkpnt++, (clock() - t0) / 1000, hashmap_size(h), table_sizes[h->table_size_index], hal->alloc_total - hal->free_total);
	hashmap_del(h, allocator_free, NULL, NULL);
/*
	free(mem);
*/
if (verbose)
fprintf(stderr, "bytes outstanding from allocator: %d\n", hal->alloc_total - hal->free_total);

	cfg = NULL;
    return 0;
}
Exemplo n.º 22
0
int main(int argc, char* argv[])
{
  hmap_t map;
  userdata  *dat;
  userelem  *el;
  int ret, i, j;

  /* 创建 hashmap */
  map = hashmap_create();

  /* 插入 hashmap 元素 */
  for (i=0; i<100; i++) {
    dat = (userdata *)malloc(sizeof(userdata));

    /* 创建子 hashmap */
    dat->map = hashmap_create();

    /* 插入子 hashmap 元素 */
    for (j=0; j<10; j++) {
      el = (userelem *)malloc(sizeof(userelem));
      sprintf(el->key, "%d", j);

      el->value = (char*) malloc(30);
      sprintf(el->value, "%d", j+1000);
      ret = hashmap_put(dat->map, el->key, el);
      assert(ret==HMAP_S_OK);
    }

    sprintf(dat->name, "%d", i);
    ret = hashmap_put(map, dat->name, dat);
    assert(ret==HMAP_S_OK);
  }

  printf("hashmap_size: %d\n", hashmap_size(map));

  /* 删除指定元素: key="10" */
  ret = hashmap_remove(map, "10", &dat);
  assert(ret==HMAP_S_OK);
  printf("hashmap_remove: name=%s. size=%d\n", dat->name, hashmap_size(map));
  hashmap_iterate(dat->map, iter_elem, 0);
  free_data(dat, 0);

  /* 删除指定元素: key="11" */
  ret = hashmap_remove(map, "11", &dat);
  assert(ret==HMAP_S_OK);
  printf("hashmap_remove: name=%s. size=%d\n", dat->name, hashmap_size(map));
  hashmap_iterate(dat->map, iter_elem, 0);
  free_data(dat, 0);

  /* 查询元素: key="99" */
  ret = hashmap_get(map, "99", &dat);
  assert(ret==HMAP_S_OK);
  printf("hashmap_get: name=%s. size=%d\n", dat->name, hashmap_size(map));
  hashmap_iterate(dat->map, iter_elem, 0);

  /* 删除整个 map */
  hashmap_destroy(map, free_data, 0);

  _CrtDumpMemoryLeaks();
  return 0;
}
Exemplo n.º 23
0
int
symresolve(struct idl *idl, struct sym *sym)
{
	struct sym *s;
	char *key;
	iter_t iter;
	int align;
	size_t size;

 	s = symlook(idl, sym->idl_type);
	if (s) {

                                                      /* merge stuff */
		sym->flags |= s->flags & 0xFFFF;

		sym->ndr_type = s->ndr_type;
		if (sym->ptr && (!IS_PRIMATIVE(sym) || hashmap_get(&sym->attrs, "string"))) {
			sym->ndr_size = 4;
		} else {
			sym->ndr_size = s->ndr_size;
		}

		sym->align = sym->ptr ? 4 : sym->ndr_size;

                                               /* inherit attributes */
		hashmap_iterate(&s->attrs, &iter);
		while ((key = hashmap_next(&s->attrs, &iter))) {
			/* Only add attributes that the symbol does not have already
			 */
			if (hashmap_get(&sym->attrs, key) == NULL) {
				char *data;
				data = hashmap_get(&s->attrs, key);
				hashmap_put(&sym->attrs, key, data);
			}
		}

		if (sym->out_type == NULL) {
			if (s->out_type) {
				sym->out_type = s->out_type;
			} else if (IS_TYPEDEFD(sym)) {
				sym->out_type = sym->idl_type = sym->name;
			} else if (strncmp(sym->idl_type, "struct ", 7) == 0 ||
						strncmp(sym->idl_type, "union ", 6) == 0) {
					char buf[255];
					if (*sym->idl_type == 's') {
						sprintf(buf, "struct_%s", sym->idl_type + 7);
					} else {
						sprintf(buf, "union_%s", sym->idl_type + 7);
					}
					sym->out_type = dupstr(buf, idl->al);
			}
			if ((strcmp(idl->type, "java") == 0 || strcmp(idl->type, "jcifs") == 0) && IS_IMPORTED(sym)) {
				char buf[255];
				sprintf(buf, "%s.%s", sym->interface, sym->out_type);
				sym->out_type = dupstr(buf, idl->al);
			}
		}
	}

	align = 0;
	size = 0;

	linkedlist_iterate(&sym->mems, &iter);
	while ((s = linkedlist_next(&sym->mems, &iter))) {
		size_t msiz, mali, m;

		symresolve(idl, s);

		if (s->align > align) {
			align = s->align;
		}

		if (s->ptr) {
			msiz = mali = 4;
		} else {
			msiz = s->ndr_size;
			mali = s->align;
		}
		m = mali - 1;
		size = (size + m) & ~m;                                 /* align the type */
		s->offset = size;

		if (IS_ENUM(sym)) {
			size = msiz;   /* size only size of member not sum of mems */
		} else if (IS_UNION(sym)) {
                /* size is largest of mems (not really used for any logic so far) */
			if (msiz > size) {
				size = msiz;
			}
		} else {
			size += msiz;                                     /* and size of type */
		}
	}

	if (align) {
		sym->align = align;
	}
	if (size) {
		sym->ndr_size = size;
	}

                                                       /* check array conformance */
	hashmap_iterate(&sym->attrs, &iter);
	while ((key = hashmap_next(&sym->attrs, &iter))) {
		if (!IS_FIXED(sym) && (strcmp(key, "size_is") == 0 || strcmp(key, "max_is") == 0)) {
			sym->flags |= FLAGS_CONFORMANT;
			break;
		}
	}

	if (IS_PRIMATIVE(sym)) {
		if (!IS_OPERATION(sym)) {
			sym->interface = NULL;
		}
		sym->flags &= ~FLAGS_IMPORTED;
	}

	return 0;
}
Exemplo n.º 24
0
Arquivo: repl.c Projeto: ohnx/leo
int main() {
    char *o, *p, *line;
    queue *q;
    double *r, *s;
    double *pi = malloc(sizeof(double));
    double *e  = malloc(sizeof(double));
    double *ans = malloc(sizeof(double));

    *pi = 3.1415926535;
    *e  = 2.7182818285;
    *ans = 0;

    hm = hashmap_new();
    hashmap_put(hm, "pi", pi);
    hashmap_put(hm, "e", e);
    hashmap_put(hm, "ans", ans);

    /* read input using linenoise */
    while((line = linenoise("> ")) != NULL) {
        /* add the line to history */
        linenoiseHistoryAdd(line);

        /* check if there is an equals sign */
        for (p = line; (*p != '\0') && (*p != '='); p++);
        if (*p == '\0') p = line;
        else { /* equals sign present */
            /* check for spaces */
            for (o = line; (*o != ' ') && (*o != '='); o++);
            *o = '\0';

            p++; /* skip equals sign when parsing equation */
        }

        q = syard_run(p);
        if (q == NULL) continue;
#ifdef __DEBUG
        queue_foreach(q, testfunc, NULL);
        printf("\n");
#endif

        r = rpn_calc(q, variable_resolver, func_wl);
        if (r == NULL) continue;

        printf("= %g\n", *r);

        /* store ans */
        *ans = *r;

        if (p != line) {
            /* equals sign present */
            if ((s = hashmap_get(hm, line)) != NULL) {
                /* existing value, just overwrite it */
                *s = *r;
                free(r);
            } else {
                /* new value */
                hashmap_put(hm, line, r);
            }
        } else {
            /* no equals sign, so we're done with the number now */
            free(r);
        }

        /* free storage and stuff */
        linenoiseFree(line);
    }

    hashmap_iterate(hm, hm_cleaner, NULL);
    hashmap_destroy(hm);
    return 0;
}