void * cpHashSetInsert(cpHashSet *set, cpHashValue hash, void *ptr, void *data, cpHashSetTransFunc trans) { cpHashValue idx = hash%set->size; // Find the bin with the matching element. cpHashSetBin *bin = set->table[idx]; while(bin && !set->eql(ptr, bin->elt)) bin = bin->next; // Create it if necessary. if(!bin){ bin = getUnusedBin(set); bin->hash = hash; bin->elt = (trans ? trans(ptr, data) : data); bin->next = set->table[idx]; set->table[idx] = bin; set->entries++; if(setIsFull(set)) cpHashSetResize(set); } return bin->elt; }
void * cpHashSetInsert(cpHashSet *set, cpHashValue hash, void *ptr, void *data) { int idx = hash%set->size; // Find the bin with the matching element. cpHashSetBin *bin = set->table[idx]; while(bin && !set->eql(ptr, bin->elt)) bin = bin->next; // Create it necessary. if(!bin){ bin = getUnusedBin(set); bin->hash = hash; bin->elt = set->trans(ptr, data); // Transform the pointer. bin->next = set->table[idx]; set->table[idx] = bin; set->entries++; // Resize the set if it's full. if(setIsFull(set)) cpHashSetResize(set); } return bin->elt; }
/********************************************************************* ** Member Function: print ** Description: print the resulting array given for the grid object * and use the loop for other loop actions like resetting flags ** Parameters: none ** Pre-Conditions: xMax and yMax must be >= 0 ** Post-Conditions: xMax and yMax remain >= 0 *********************************************************************/ void Grid::print() { int count = 1; // used to count how many objects exist for (int i = 0; i < yMax; i++){ for (int j = 0; j < xMax; j++) { resetIsMoved(j, i); // reset move flags copyObject(j, i); // check to see if a new object should be created deleteObject(j, i); // check to see if an object should be deleted if (gridArray[i][j] == NULL) // prints a background space when NULL //std::cout << " - "; // fill background std::cout << " "; // no background else if (gridArray[i][j]->getType() == 1) { std::cout << " * "; /* Ant object */ count++; } else if (gridArray[i][j]->getType() == 2) { std::cout << ">X<"; /* Doodlebug object */ count++; } } std::cout << std::endl; } std::cout << std::endl; if (count == xMax * yMax) // check to see if the grid is full setIsFull(); }
/** * Adds the value to the Set; specifically inserts the value at current index and increments index. * @param S the set to add the value to * @param value the value to add * @return 1 if add was successful or the value was already in the Set; or 0 if there's no more room. */ uint8_t addToSet(set* S, uint16_t value) { if ((setContains(S, value)) == 1) // First see if this value is already in the list { return 1; // Stop now; value is already in the list so we don't need to insert it } if (setIsFull(S)) // Check to see if there is room in the Set for a new entry { return 0; // No room at the inn } S->values[S->size] = value; // Add the value to the Set S->size++; // And increment the setSize return 1; }