void hash_map_insert(hash_map_t * hash_map, int type, const char *data) { hash_node_t * hash_node; int hash; hash_node = hash_map_search(hash_map, data); if (hash_node != NULL) { return; } hash_node = malloc(sizeof(hash_node_t)); hash_node->data = calloc(strlen(data), sizeof(char)); hash_node->type = type; if(type == 3) hash_node->dataType = DATATYPE_INT; else if(type == 6) hash_node->dataType = DATATYPE_CHAR; else if(type == 4 || type == 5) hash_node->dataType = DATATYPE_BOOL; strcpy(hash_node->data, data); hash_node->next = NULL; hash = get_hash(data); if (hash_map->nodes[hash] == NULL) { hash_map->nodes[hash] = hash_node; } else { hash_node_t * hash_node_aux = hash_map->nodes[hash]; while(hash_node_aux->next != NULL) hash_node_aux = hash_node_aux->next; hash_node_aux->next = hash_node; } hash_map->size++; }
static inline iterator_t * __container_hash_map_search(container_t *ct, void *key,iterator_t *it) { it->container_p = ct; hash_map_search(ct->priv.hmap, key,&it->pos.hash_pos); return it; }
hash_node_t * hash_map_makelabel(hash_map_t * hash_map) { static int label_num = 1000000; char label_name[128]; sprintf(label_name, "_label_n%d", label_num++); hash_map_insert(hash_map, SYMBOL_LABEL, label_name); return hash_map_search(hash_map, label_name); }
hash_node_t * hash_map_maketemp(hash_map_t * hash_map) { static int temp_num = 1000; char temp_name[128]; sprintf(temp_name, "_temp_n%d", temp_num++); hash_map_insert(hash_map, SYMBOL_VARIABLE, temp_name); return hash_map_search(hash_map, temp_name); }
hash_node_t * hash_map_insert(hash_map_t * hash_map, int type, const char *data) { hash_node_t * hash_node; int hash; hash_node = hash_map_search(hash_map, data); if (hash_node != NULL) { //return; } hash_node = calloc(1, sizeof(hash_node_t)); hash_node->data = calloc(strlen(data), sizeof(char)); hash_node->type = type; strcpy(hash_node->data, data); hash = get_hash(data); hash_node->next = hash_map->nodes[hash]; hash_map->nodes[hash] = hash_node; hash_map->size++; return hash_node; }