void map_set(map *map, const char *key, void *element) { mapNode *node; if(map_contains_key(map, key)) { node = map_find_node(map->root, key); memcpy(node->value, element, map->elementSize); return; } node = malloc(sizeof(mapNode)); node->left = node->right = NULL; node->key = strdup(key); node->value = malloc(map->elementSize); memcpy(node->value, element, map->elementSize); map->logicalLength++; if(!map->root) { map->root = node; map->root->left = NULL; map->root->right = NULL; } else { map_insert_node(map->root, node); } }
bool _solver_bfs_move(void *data, const maze *m, vec2 *pos) { bfs_data bfs = *((bfs_data *) data); list *neighbors; vec2 neigh; set_insert(bfs.visited, pos); neighbors = maze_get_neighbors(m, *pos); while (!list_is_empty(neighbors)) { list_pop_front(neighbors, &neigh); if (!map_contains_key(bfs.parent, &neigh) && !set_contains(bfs.visited, &neigh)) { map_put(bfs.parent, &neigh, pos); list_push_back(bfs.queue, &neigh); } } list_destroy(neighbors); if (list_is_empty(bfs.queue)) { return false; } list_pop_front(bfs.queue, pos); return true; }
void initial_symbol_dump(int level, const char *symbol) { i32 value; struct expr *expr; expr = map_get(s->initial_symbols, symbol); if(expr != NULL) { value = resolve_expr(expr); LOG(level, ("symbol \"%s\" resolves to %d ($%04X)\n", symbol, value, value)); } else { if(map_contains_key(s->initial_symbols, symbol)) { LOG(level, ("symbol \"%s\" defined but has no value\n", symbol)); } else { LOG(level, ("symbol \"%s\" not found\n", symbol)); } } }