void RenderQueue_delete(RenderQueue* self) { smug_assert(_invariant(self)); Map_doForEach(self->renderBatches, _deleteRenderBatchInMap); Map_delete(self->renderBatches); free(self); }
void test_map_delete (void* data) { Map* map = Map_new(runtime); Tuple* pair = Map_put(map, hash_for(TRUE), TRUE, FALSE); tt_assert(is_true(Tuple_get(pair, 0))); tt_assert(is_false(Tuple_get(pair, 1))); pair = Map_delete(map, hash_for(TRUE)); tt_assert(is_true(Tuple_get(pair, 0))); tt_assert(is_false(Tuple_get(pair, 1))); tt_assert(!Map_has(map, hash_for(TRUE))); end: Map_destroy(map); }
int main(int argc, char* argv[]) { Map map; Car cars[3] = {NULL, NULL, NULL}; int x, y, i, rounds = 0, needPathfinding = 0, firstLoop = 1; List path; Position position; Vector acc; int fuel; srand(time(NULL)); freopen("pshr4log.txt", "w+", stderr); // freopen("map.txt", "r", stdin); LOGINFO("Starting"); initGC(); map = Map_load(stdin); LOGINFO("Map loaded"); while(!feof(stdin)) { LOGINFO1I("===== Round number %d =====", rounds); for(i = 0; i < 3; i++) { fscanf(stdin, "%d %d", &x, &y); LOGINFO3I("Car number %i, position : %d %d", i, x, y); if(cars[i] == NULL) cars[i] = Car_new(x, y); else Car_updatePosition(cars[i], x, y); if(Car_updateArrivedStatus(cars[i], map)) { recomputeDistances(map, cars); LOGINFO("I see you've arrived, let me see where I can park now..."); needPathfinding = 1; } } if(firstLoop) { firstLoop = 0; path = doPathfinding(map, cars); List_tail(path); List_prev(path); } position = List_getCurrent(path); for(i = 1; i < 3; i++) { if(Position_equal(position, Car_getPosition(cars[i]))) { needPathfinding = 1; LOGINFO("YOU TOOK MY SPOT JERK"); } } if(needPathfinding) { freePath(path); path = doPathfinding(map, cars); List_tail(path); List_prev(path); needPathfinding = 0; position = List_getCurrent(path); } if(position == NULL) { goRandom(); } else { LOGINFO2I("Going to %d %d", position->x, position->y); acc = Car_getAccelerationToReach(cars[0], position); go(acc->x, acc->y); if(Vector_squaredLength(acc) > 2) { Car_useBoost(cars[0]); LOGINFO("Using a boost"); } Vector_delete(acc); } List_prev(path); rounds++; } LOGINFO("End"); freePath(path); for(i = 0; i < 3; i++) { Car_delete(cars[i]); } Map_delete(map); freeGC(); return 0; }