int main() { srand(1337); IntSet s; for(int i = 1; i != 20; i++) { s.insert(rand() % 30); } for(int i = 0; i != 30; i++) { cout << i << ": " << (s.contains(i) ? "Yes" : "No") << endl; if (i % 2 == 0) { s.remove(i); } } cout << endl; for(int i = 0; i != 30; i++) { cout << i << ": " << (s.contains(i) ? "Yes" : "No") << endl; } for(int i = 0; i != 100000; i++) { s.insert(rand() % 55789127); } cout << "Done inserting" << endl; for(int i = 0; i != 1000000; i++) { s.contains(i); } }
int main() { IntSet s; for(int i = 0; i != 10; i++) { s.insert(i * 1337 % 29); } for(int i = 0; i != 30; i++) { cout << i << ": " << (s.contains(i) ? "Yes" : "No") << endl; if (i % 2 == 0) { s.remove(i); } } cout << endl; for(int i = 0; i != 30; i++) { cout << i << ": " << (s.contains(i) ? "Yes" : "No") << endl; } for(int i = 0; i != 100000; i++) { s.insert(i * 1337 % 55789127); } cout << "Done inserting" << endl; for(int i = 0; i != 1000000; i++) { s.contains(i); } }
void MovementModel::move(UnitStack& party, const IntSet& selected_units, const Point& tile_pos) const { for (unsigned int i = 0; i < party.units.size(); i++) { if (selected_units.contains(i)) { Unit& unit = *party.units[i]; int cost = cost_to(unit, tile_pos); unit.properties.increment<int>(Moves, -cost); //TODO if unit is on transport, does it affect the terrain? if (unit.has_property(PathOfLife)) { alter_terrain(tile_pos, PathOfLife); } else if (unit.has_property(PathOfDeath)) { alter_terrain(tile_pos, PathOfDeath); } else if (unit.has_property(PathOfIce)) { alter_terrain(tile_pos, PathOfIce); } Tile& tile = game->level.tiles[tile_pos]; if (tile.structure) { Structure& structure = *tile.structure; if (structure.has_property(Capturable) && structure.owner != party.owner) { structure.owner = party.owner; } } } } }
int main() { srand(137872); IntSet* s = new BsVectorIntSet(); for(int i = 0; i != 20; i++) { s->insert(rand() % 30); } for(int i = 0; i != 30; i++) { cout << i << ": " << (s->contains(i) ? "Yes" : "No") << endl; if (i % 2 == 0) { s->remove(i); } } cout << endl; for(int i = 0; i != 30; i++) { cout << i << ": " << (s->contains(i) ? "Yes" : "No") << endl; } clock_t start = clock(); for(int i = 0; i != 1000000; i++) { s->insert(rand()); } for(int i = 0; i != 1000000; i++) { s->remove(rand()); } cout << "Done inserting" << endl; cout << "Time: " << ((clock()- start) / (double) CLOCKS_PER_SEC) << "s" << endl; cout << "Querying" << endl; start = clock(); for(int i = 0; i != 1000000; i++) { s->contains(i); } cout << "Done querying" << endl; cout << "Time: " << ((clock()- start) / (double) CLOCKS_PER_SEC) << "s" << endl; delete s; }
/********************************************************************************************************* ** Description: Calculates the difference of two or more sets, returning the set that represents ** that difference. **********************************************************************************************************/ IntSet IntSet::getDifference(const IntSet& obj) const { IntSet diffSet = *this; //initialize a new set with the elements of the calling set for (int i = 0; i < obj.size(); i++) //loop through the set given as an argument { if (diffSet.contains(obj.set[i])) //if the current element is in the difference set... { diffSet.remove(obj.set[i]); //then remove that element from the difference set } } return diffSet; //return the difference set }
/********************************************************************************************************* ** Description: Calculates the union of two or more sets, returning the set that represents that union. **********************************************************************************************************/ IntSet IntSet::getUnion(const IntSet& obj) const { IntSet unionSet = *this; //initialize a new set with the elements of the calling set for (int i = 0; i < obj.size(); i++) //loop through the set given as an argument { if (!unionSet.contains(obj.set[i])) //if the current element is not already in the union set... { unionSet.add(obj.set[i]); //add that element to the union set } } return unionSet; //return the union }