inline void gen_cuckoo_entry(uint8_t* in, cuckoo_entry_ctx* out, hs_t* hs, uint32_t ele_id) { uint32_t i; out->pos = 0; out->eleid = ele_id; #ifndef TEST_UTILIZATION out->val = (uint8_t*) calloc(hs->outbytelen, sizeof(uint8_t)); #endif hashElement(in, out->address, out->val, hs); }
// Find an element based on the hash // For now, do it stupidly: iterate through customs and hash them, // looking for a match. unsigned char findElementFromHash(unsigned long hash) { int i; unsigned long tempHash; for (i = NUM_BASE_ELEMENTS; i < numElements; ++i) { tempHash = hashElement(elements[i]); if (tempHash == hash) { return i; } } }
char saveStateLogic(FILE* fp) { if (fp != NULL) { int i, counterX, counterY; int tempParticle; //First write the version code for this saveload version fprintf(fp, "%s\n\n", SAVELOAD_VERSION_CODE); //Save the max specials (for backward compatibility if needed) fprintf(fp, "%d\n\n", MAX_SPECIALS); //Save the dimensions fprintf(fp, "%d %d\n\n", workWidth, workHeight); //Save the particles /* Save format: * (x y xVel yVel heat element->index) ... * . * . * . */ for (counterY = 0; counterY < workHeight; counterY++) { for (counterX = 0; counterX < workWidth; counterX++) { tempParticle = allCoords[getIndex(counterX, counterY)]; if(tempParticle != -1) { // Normal element if(a_element[tempParticle]->index < NUM_BASE_ELEMENTS) { fprintf(fp, "B(%f %f %d %d %c %d)", a_x[tempParticle], a_y[tempParticle], a_xVel[tempParticle], a_yVel[tempParticle], a_heat[tempParticle], a_element[tempParticle]->index); } // Custom element else { fprintf(fp, "C(%f %f %d %d %c %lu)", a_x[tempParticle], a_y[tempParticle], a_xVel[tempParticle], a_yVel[tempParticle], a_heat[tempParticle], hashElement(a_element[tempParticle])); } fprintf(fp, "["); for (i = 0; i < MAX_SPECIALS; i++) { fprintf(fp, "%d ", a_specialVals[tempParticle][i]); } fprintf(fp, "]"); } else { // E -- empty location fprintf(fp, "E"); } } fprintf(fp, "\n"); } fclose(fp); return TRUE; } if(fp) { fclose(fp); } return FALSE; }