long getIntId(char *s) { long res = (long)hashTableGet(idToIntMap, s); if (!res) { void *key = copyStr(s); void *value = (void *)(idToIntMap->size + 1L); hashTablePut(idToIntMap, key, value); hashTablePut(intToIdMap, value, key); res = idToIntMap->size; } return res; }
int main(int argc, const char * argv[]) { HashTableNode nodes[2] = {{"Pantera",234}, {"Pantera2",223}}; HashTable * hashTable = newHashMap(nodes, 2); hashTableSet(hashTable, "key2", 666); hashTableSet(hashTable, "key3", 666); printHashTable(hashTable); int key2 = hashTableGet(hashTable, "key2"); printf("\nkey2 %i\n", key2); return 0; }
static RetCode mpeg2PmtActivate(Mpeg2Pmt mpeg2Pmt, MmpContextObject *cop, Mpeg2PmtTsProgramMapSection * pmsp) { Mpeg2PmtStream *streamp; Mpeg2PmtTsProgramMapSection *curPmsp; Mpeg2PmtCurrentNextIndicator cni; unsigned pn; cni = Mpeg2PmtCurrentNextIndicator(pmsp->psiExtension.currentNextIndicator); pn = MPEG2_PMT_PROGRAM_NUMBER(&pmsp->psiExtension); curPmsp = (Mpeg2PmtTsProgramMapSection*)hashTableGet(mpeg2Pmt->pmtTable[cni], pn); if (curPmsp == NULL || curPmsp->psiExtension.versionNumber != pmsp->psiExtension.versionNumber) { mpeg2PmtDeactivate(mpeg2Pmt, pn, cni); (void) hashTablePut(mpeg2Pmt->pmtTable[cni], pn, DUP(Mpeg2PmtTsProgramMapSection, pmsp)); if (mpeg2Pmt->shouldPmtStop) { return RETCODE_CONS(retCodeId, MPEG2_PMT_ERROR_STOP); } for (streamp = pmsp->streamList; streamp != NULL; streamp = streamp->next) { unsigned streamType = streamp->streamHeader.streamType; unsigned ePid = MPEG2_PMT_STREAM_HEADER_ELEMENTARY_PID( &streamp->streamHeader); Pipe pidPipe; if (MMP_CONTEXT_PIDTOPIPE(cop, ePid) == NULL) { MmpParserObject *pop = mpeg2Pmt->streamTypeToPop[streamType]; RetCode retCode; streamp->cop = cop; pidPipe = MMP_PARSER_NEWPIPE(pop, cop); retCode = MMP_CONTEXT_ADDPIPE(cop, ePid, pidPipe); ABORT_IF_FALSE(retCode == RETCODE_SUCCESS); } else if (streamp->cop != cop) { return RETCODE_CONS(retCodeId, MPEG2_PMT_ERROR_PID_USE); } } } else { mpeg2PmtDescListFree(pmsp->descList); mpeg2PmtStreamListFree(pmsp->streamList); } return RETCODE_SUCCESS; }
bool hasUniqueCharacters(char * str) { HashTable * table = newHashMap(NULL, 0); char * ptr = &str[0]; while (ptr != NULL && *ptr != '\0') { char temp[2] = {*ptr,'\0'}; if(hashTableGet(table, temp) == HashTableNotFound){ hashTableSet(table, temp, 1); printHashTable(table); ptr++; }else{ printHashTable(table); printf("string does not have unique characters, found at least two %c\n", *ptr); ptr = NULL; } } return false; }
/// The unloadBuffer function for a halo exchange of atom data. /// Iterates the receive buffer and places each atom that was received /// into the link cell that corresponds to the atom coordinate. Note /// that this naturally accomplishes transfer of ownership of atoms that /// have moved from one spatial domain to another. Atoms with /// coordinates in local link cells automatically become local /// particles. Atoms that are owned by other ranks are automatically /// placed in halo kink cells. /// \see HaloExchangeSt::unloadBuffer for an explanation of the /// unloadBuffer parameters. /// @param face Not used for this function. The only reason we keep it is to match the unloadForcesBuffer declaration void unloadAtomsBuffer(void* vparms, void* data, int face, int bufSize, char* charBuf) { AtomExchangeParms* parms = (AtomExchangeParms*) vparms; SimFlat* sim = (SimFlat*) data; assert(bufSize % sizeof(AtomMsg) == 0); int nBuf = bufSize / sizeof(AtomMsg); if(sim->method == CPU_NL) { AtomMsg* buf = (AtomMsg*) charBuf; // const int nlUpdateRequired = neighborListUpdateRequired(s->atoms->neighborList,s->boxes,s->atoms); const int nlUpdateRequired = neighborListUpdateRequired(sim); for (int ii=0; ii<nBuf; ++ii) { int gid = buf[ii].gid; int type = buf[ii].type; real_t rx = buf[ii].rx; real_t ry = buf[ii].ry; real_t rz = buf[ii].rz; real_t px = buf[ii].px; real_t py = buf[ii].py; real_t pz = buf[ii].pz; if(nlUpdateRequired){ int iOff = putAtomInBox(sim->boxes, sim->atoms, gid, type, rx, ry, rz, px, py, pz); if(iOff >= (MAXATOMS*sim->boxes->nLocalBoxes)) hashTablePut(sim->atomExchange->hashTable, iOff); //remember iOff only for particles which are mapped to haloCells else //putting particle to local sim->atoms->neighborList->updateLinkCellsRequired = 1; }else{ int iOff = hashTableGet(sim->atomExchange->hashTable); updateAtomInBoxAt(sim->boxes, sim->atoms, gid, type, rx, ry, rz, px, py, pz,iOff); } } }else{ unloadAtomsBufferToGpu(charBuf, nBuf, sim, sim->gpu_atoms_buf, sim->boundary_stream); } }
Mesh *meshObjIndex(Mesh *mesh) { Mesh *indexed = malloc(sizeof(Mesh)); indexed->vertices.data = malloc(mesh->indices.length * sizeof(Vec3)); indexed->uvs.data = malloc(mesh->indices.length * sizeof(Vec2)); indexed->normals.data = malloc(mesh->indices.length * sizeof(Vec3)); indexed->indices.data = malloc(mesh->indices.length * sizeof(unsigned)); indexed->vertices.length = 0; indexed->uvs.length = 0; indexed->normals.length = 0; indexed->indices.length = mesh->indices.length; HashTable *indexTable = hashTableNew(); unsigned index = 0; unsigned *duplicate = NULL; for (unsigned i = 0; i < mesh->indices.length; i++) { unsigned x = i * 3; /** * Create a unique key from all 3 index * variables. */ int keyLength = snprintf(NULL, 0, "%i/%i/%i", (int)mesh->indices.data[x], (int)mesh->indices.data[x + 1], (int)mesh->indices.data[x + 2]); if (keyLength > 0) { char key[keyLength + 1]; sprintf(key, "%i/%i/%i", (int)mesh->indices.data[x], (int)mesh->indices.data[x + 1], (int)mesh->indices.data[x + 2]); if ((duplicate = (unsigned*)hashTableGet(indexTable, hashMurmur3(key))) == NULL) { if ((int)mesh->indices.data[x] > 0) { indexed->vertices.data[index] = mesh->vertices.data[(int)mesh->indices.data[x] - 1]; indexed->vertices.length++; } else if ((int)mesh->indices.data[x] < 0) { indexed->vertices.data[index] = mesh->vertices.data[mesh->vertices.length + (int)mesh->indices.data[x]]; indexed->vertices.length++; } else { /** * If vertex data is missing nullify * the mesh and break out. */ indexed = meshObjEmpty(indexed); break; } if ((int)mesh->indices.data[x + 1] > 0) { indexed->uvs.data[index] = mesh->uvs.data[(int)mesh->indices.data[x + 1] - 1]; indexed->uvs.length++; } else if ((int)mesh->indices.data[x + 1] < 0) { indexed->uvs.data[index] = mesh->uvs.data[mesh->uvs.length + (int)mesh->indices.data[x + 1]]; indexed->uvs.length++; } if ((int)mesh->indices.data[x + 2] > 0) { indexed->normals.data[index] = mesh->normals.data[(int)mesh->indices.data[x + 2] - 1]; indexed->normals.length++; } else if ((int)mesh->indices.data[x + 2] < 0) { indexed->normals.data[index] = mesh->normals.data[mesh->normals.length + (int)mesh->indices.data[x + 2]]; indexed->normals.length++; } indexed->indices.data[i] = index; index++; hashTableSet(indexTable, hashMurmur3(key), &indexed->indices.data[i]); } else { indexed->indices.data[i] = *duplicate; } } } hashTableFree(indexTable); /** * Resize buffers to match data. */ if (indexed->uvs.length != indexed->vertices.length) { indexed->uvs.length = 0; } if (indexed->normals.length != indexed->vertices.length) { indexed->normals.length = 0; } indexed->vertices.data = realloc(indexed->vertices.data, indexed->vertices.length * sizeof(Vec3)); indexed->uvs.data = realloc(indexed->uvs.data, indexed->uvs.length * sizeof(Vec2)); indexed->normals.data = realloc(indexed->normals.data, indexed->normals.length * sizeof(Vec3)); return indexed; }
char *getStrId(long id) { return hashTableGet(intToIdMap, (void *)id); }