//-------------------------------------- StringTableEntry _StringTable::lookup(const char* val, const bool caseSens) { Node **walk, *temp; U32 key = hashString(val); walk = &buckets[key % numBuckets]; while((temp = *walk) != NULL) { if(caseSens && !dStrcmp(temp->val, val)) return temp->val; else if(!caseSens && !dStricmp(temp->val, val)) return temp->val; walk = &(temp->next); } return NULL; }
struct hashEl *hashLookup(struct hash *hash, char *name) /* Looks for name in hash table. Returns associated element, * if found, or NULL if not. If there are multiple entries * for name, the last one added is returned (LIFO behavior). */ { struct hashEl *el = hash->table[hashString(name)&hash->mask]; while (el != NULL) { if (strcmp(el->name, name) == 0) break; el = el->next; } return el; }
//------------------------------------------------------------------------- // @brief //------------------------------------------------------------------------- const unsigned int ShaderCache::getPixelShader(const tinyxml2::XMLElement* element, const DeviceManager& deviceManager) { PixelShader shader; shader.deserialise(element); unsigned int resourceName = hashString(getResourceNameFromFileName(shader.getFileName())); if (getPixelShader(resourceName) == nullptr) { if (shader.createShader(deviceManager)) { m_pixelShaders.emplace(PixelShaderHandle(resourceName, shader)); } } return resourceName; }
void * HashTable_update(HashTable *ht, char *key, void *value) { u4 size = ht->size; u4 mask = size - 1; u4 hash = hashString(key) & mask; void *old_value = NULL; HashEntry *p; for (p = ht->table[hash]; p != NULL; p = p->next) { if (strcmp(p->key, key) == 0) { old_value = p->value; p->value = value; } } return old_value; }
bool FileSystem::detectLeave( Node leaveNode ) { int positionClock = deleteFromVirtualRing( leaveNode ); virtualRingLock.lock(); int positionAntiClock = virtualRing.size() + 1 - positionClock; // cout<<"node "<< leaveNode.ip_str<<" leaving "<<positionAntiClock<<" before me."<<endl; bool success = false; int minKey, maxKey; if( positionAntiClock == 3 ){ VirtualNode target = nNodeBefore(1, myPosition); minKey = nNodeBefore(3, myPosition).key; maxKey = hashString(leaveNode.ip_str); success = pullFileFromRange( target.ip_str, minKey, maxKey, false); // cout<<success<<" pull key from "<<minKey<<" to "<<maxKey<<" from "<<target.ip_str<<" "<<target.key<<endl; logFile<<success<<" detectLeave pull key from "<<minKey<<" to "<<maxKey<<" from "<<target.ip_str<<" "<<target.key<<endl; } else if( positionAntiClock == 2 ){ VirtualNode target = nNodeBefore(1, myPosition); minKey = nNodeBefore(3, myPosition).key; maxKey = nNodeBefore(2, myPosition).key; success = pullFileFromRange( target.ip_str, minKey, maxKey, false); // cout<<success<<" pull key from "<<minKey<<" to "<<maxKey<<" from "<<target.ip_str<<" "<<target.key<<endl; logFile<<success<<" detectLeave pull key from "<<minKey<<" to "<<maxKey<<" from "<<target.ip_str<<" "<<target.key<<endl; } else if( positionAntiClock == 1 ){ VirtualNode target = nNodeBefore(1, myPosition); minKey = nNodeBefore(3, myPosition).key; maxKey = nNodeBefore(2, myPosition).key; success = pullFileFromRange( target.ip_str, minKey, maxKey, false); // cout<<success<<" pull key from "<<minKey<<" to "<<maxKey<<" from "<<target.ip_str<<" "<<target.key<<endl; logFile<<success<<" detectLeave pull key from "<<minKey<<" to "<<maxKey<<" from "<<target.ip_str<<" "<<target.key<<endl; } if(!success){ VirtualNode target = nNodeBefore(2, myPosition); success = pullFileFromRange( target.ip_str, minKey, maxKey, false); // cout<<success<<" pull key second from "<<minKey<<" to "<<maxKey<<" from "<<target.ip_str<<" "<<target.key<<endl; logFile<<success<<" detectLeave pull key from "<<minKey<<" to "<<maxKey<<" from "<<target.ip_str<<" "<<target.key<<endl; } virtualRingLock.unlock(); return success; }
/* ** Echo virtual table module xFilter method. */ static int echoFilter( sqlite3_vtab_cursor *pVtabCursor, int idxNum, const char *idxStr, int argc, sqlite3_value **argv ){ int rc; int i; echo_cursor *pCur = (echo_cursor *)pVtabCursor; echo_vtab *pVtab = (echo_vtab *)pVtabCursor->pVtab; sqlite3 *db = pVtab->db; if( simulateVtabError(pVtab, "xFilter") ){ return SQLITE_ERROR; } /* Check that idxNum matches idxStr */ assert( idxNum==hashString(idxStr) ); /* Log arguments to the ::echo_module Tcl variable */ appendToEchoModule(pVtab->interp, "xFilter"); appendToEchoModule(pVtab->interp, idxStr); for(i=0; i<argc; i++){ appendToEchoModule(pVtab->interp, (const char*)sqlite3_value_text(argv[i])); } sqlite3_finalize(pCur->pStmt); pCur->pStmt = 0; /* Prepare the SQL statement created by echoBestIndex and bind the ** runtime parameters passed to this function to it. */ rc = sqlite3_prepare(db, idxStr, -1, &pCur->pStmt, 0); assert( pCur->pStmt || rc!=SQLITE_OK ); for(i=0; rc==SQLITE_OK && i<argc; i++){ rc = sqlite3_bind_value(pCur->pStmt, i+1, argv[i]); } /* If everything was successful, advance to the first row of the scan */ if( rc==SQLITE_OK ){ rc = echoNext(pVtabCursor); } return rc; }
/*Big O: O(n) * Returns the index of the element. Returns -1 if element is not found */ int findElement(SET *sp, char *elt, bool* found) { assert(elt != NULL); if(elt == NULL) return false; *found = false; unsigned home = hashString(elt) % sp->maxElements; int hash = home; int available = -1; int flag; do { flag = sp->flags[hash];//gets the value at hash if(flag == FLAG_EMPTY) { if(available != -1) //if there is a tombstone, return index of tomb return available; return hash;//Return the index to insert the data element to if the data slot is empty } if(flag == FLAG_TOMB) { if(available == -1)//If the flag is a tomb and available has not been changed { //Ensures that it gets the first tombstone after the home location if home location is occupied. available = hash; } } if(flag == FLAG_FULL) { if(strcmp(sp->elts[hash], elt) == 0)//if the flag is full and the strings match { *found = true;//set the found bool to true return hash;//return the index it was found at } } hash = (hash+1) % sp->maxElements;//Increments the hash by 1 each time. Linear probing } while(hash != home );//will loop through entire array until it returns back to home location or finds a matching index/empty index if(available == -1)//if the element was not found. available = hash;//returns the home location of the string return available; }
//----------------------------------------------------------------------------- //! @brief TODO enter a description //! @remark //----------------------------------------------------------------------------- ControllerType InputSystem::stringToControllerType( const std::string& controllerName ) { size_t controllerNameHash = hashString(controllerName); if (controllerNameHash == XInputDevice::m_hash) { return Gamepad; } else if (controllerNameHash == KeyboardInputDevice::m_hash) { return Keyboard; } else if (controllerNameHash == MouseController::m_hash) { return Mouse; } return Gamepad; }
void sortAnagrams(vector<string> &array) { vector<StringWithTag> arrayWithTag; unsigned long radix = 0; for (auto i = array.begin(); i != array.end(); i++) { StringWithTag aStringWithTag; aStringWithTag.value = *i; if ((*i).length() > radix) { radix = (*i).length(); } hashString(aStringWithTag); arrayWithTag.push_back(aStringWithTag); } myRadixSort(arrayWithTag, HASH_TAG_SIZE, radix); for (int i = 0; i < arrayWithTag.size(); i++) { array[i] = arrayWithTag[i].value; } }
UniformState* IProgramObject::GetNewUniformState(const std::string name) { const size_t hash = hashString(name.c_str()); const auto it = uniformStates.emplace(hash, name); UniformState* us = &(it.first->second); us->SetLocation(GetUniformLoc(name)); #if DEBUG if (us->IsLocationValid()) us->SetType(GetUniformType(us->GetLocation())); // make sure hash is unique for (const auto us2: uniformStates) assert(us2.first != hash || us2.second.GetName() == name); #endif return us; }
// Find element passed in paramater // If found return true // If not found return false static int findElement (SET *sp, char *elt, bool *found) { int hash = hashString(elt) % sp->len; // Holds value of first previously filled int store; // Whether previously filled value encountered bool foundStore = false; while(hash <= sp->len) { // If value is empty then return index if (sp->status[hash] == 'E') { // If previously dleted is true then if (foundStore == true) // return first perviously dleted value return store; *found = false; return hash; } // If value is continue probe else if(sp->status[hash] == 'F') { // If filled value is value searching for return if(strcmp(elt,sp->words[hash]) == 0) { // set found to true *found = true; return hash; } // increment hash by linear probing hash++; } // If value is previously filled then continue probe else if(sp->status[hash] == 'P') { // if first previously delted value if (foundStore == false) { // Store index of first previously delted value store = hash; // set found to true foundStore = true; } hash++; } } // set found to false *found = false; return 0; };
void GLSLProgramObject::Validate() { GLint validated = 0; glValidateProgram(objID); glGetProgramiv(objID, GL_VALIDATE_STATUS, &validated); valid = bool(validated); // append the validation-log log += glslGetLog(objID); #ifdef DEBUG // check if there are unset uniforms left GLsizei numUniforms, maxUniformNameLength; glGetProgramiv(objID, GL_ACTIVE_UNIFORMS, &numUniforms); glGetProgramiv(objID, GL_ACTIVE_UNIFORM_MAX_LENGTH, &maxUniformNameLength); if (maxUniformNameLength <= 0) return; std::string bufname(maxUniformNameLength, 0); for (int i = 0; i < numUniforms; ++i) { GLsizei nameLength = 0; GLint size = 0; GLenum type = 0; glGetActiveUniform(objID, i, maxUniformNameLength, &nameLength, &size, &type, &bufname[0]); bufname[nameLength] = 0; if (nameLength == 0) continue; if (strncmp(&bufname[0], "gl_", 3) == 0) continue; const auto hash = hashString(&bufname[0]); if (uniformStates.find(hash) != uniformStates.end()) continue; LOG_L(L_WARNING, "[GLSL-PO::%s] program-object name: %s, unset uniform: %s", __FUNCTION__, name.c_str(), &bufname[0]); //assert(false); } #endif }
static int echoFilter( sqlite3_vtab_cursor *pVtabCursor, int idxNum, const char *idxStr, int argc, sqlite3_value **argv ){ int rc; int i; echo_cursor *pCur = (echo_cursor *)pVtabCursor; echo_vtab *pVtab = (echo_vtab *)pVtabCursor->pVtab; sqlite3 *db = pVtab->db; if( simulateVtabError(pVtab, "xFilter") ){ return SQLITE_ERROR; } assert( idxNum==hashString(idxStr) ); appendToEchoModule(pVtab->interp, "xFilter"); appendToEchoModule(pVtab->interp, idxStr); for(i=0; i<argc; i++){ appendToEchoModule(pVtab->interp, (const char*)sqlite3_value_text(argv[i])); } sqlite3_finalize(pCur->pStmt); pCur->pStmt = 0; rc = sqlite3_prepare(db, idxStr, -1, &pCur->pStmt, 0); assert( pCur->pStmt || rc!=SQLITE_OK ); for(i=0; rc==SQLITE_OK && i<argc; i++){ rc = sqlite3_bind_value(pCur->pStmt, i+1, argv[i]); } if( rc==SQLITE_OK ){ rc = echoNext(pVtabCursor); } return rc; }
//add new joining node&hash to virtual ring, update myPosition. return the relative position to new node int FileSystem::addToVirtualRing( Node n ){ VirtualNode newNode; newNode.ip_str = n.ip_str; newNode.key = hashString(newNode.ip_str); virtualRingLock.lock(); virtualRing.push_back(newNode); std::sort(virtualRing.begin(), virtualRing.end()); myPosition = find( virtualRing.begin(), virtualRing.end(), myself ) - virtualRing.begin(); int joinPosition = find( virtualRing.begin(), virtualRing.end(), newNode ) - virtualRing.begin(); virtualRingLock.unlock(); int positionClock = joinPosition - myPosition; if(positionClock < 0) positionClock += virtualRing.size() + 1; return positionClock; }
int lexIdentifier(char c) { int hashValue; snarfAlphanumericString(c, nameBuffer); hashValue = hashString(nameBuffer); if (yylval = lookupOpcode(nameBuffer, hashValue)) return(Opcode); else if (yylval = lookupKeyword(nameBuffer, hashValue)) return(yylval); else if ((yylval = lookupConditionCode(nameBuffer, hashValue)) != (int)NOT_FOUND_COND) return(ConditionCode); else if (yylval = lookupMacroName(nameBuffer, hashValue)) return(MacroName); else { yylval = (int) saveString(nameBuffer); return(Identifier); } }
void FileSystem::checkFiles() { // hashing function to find the machine/s where to store the file; std::vector<std::string> toremove; filesLock.lock(); for ( auto &file : files) { int flag = false; for (int i = 0; i < 3; ++i) { int position = findPositionByKey( hashString(file.filename) ) + i; int nodePosition = ( position + virtualRing.size() ) % virtualRing.size(); if (virtualRing[nodePosition].key == myself.key) { flag = true; } } if (!flag) { toremove.push_back(file.filename); } } for (int i = 0; i < toremove.size(); ++i) { if ( deleteFile( toremove.at(i) ) ) { logFile << toremove.at(i) << "deleted" << std::endl; } files.remove(toremove.at(i)); } filesLock.unlock(); }
///------------------------------------------------------------------------- // @brief ///------------------------------------------------------------------------- const ShaderInstance RotatingBlades::deserialise( const tinyxml2::XMLElement* element) { ShaderInstance shaderInstance; const tinyxml2::XMLAttribute* attribute = element->FindAttribute("name"); if (attribute != nullptr) { m_name = attribute->Value(); } for (element = element->FirstChildElement(); element != 0; element = element->NextSiblingElement()) { unsigned int typeHash = hashString(element->Value()); if (Material::m_hash == typeHash) { //This all needs to be a message to the renderer to create a render object MSG_TRACE_CHANNEL("REFACTOR", "CREATE RENDER RESOURCE HERE THROUGH A MESSAGE"); //shaderInstance.getMaterial().deserialise(m_resource, getResource().getDeviceManager(), getResource().getTextureManager(), getResource().getLightManager(), element); //shaderInstance.getMaterial().setBlendState(true); m_materialParameters = Material::GetMaterialParameters(element); } else if (Vector3::m_hash == typeHash) { //m_position.deserialise(element); //translate(m_world, m_position.x(), m_position.y(), m_position.z()); //Matrix44 transform; //translate(transform, 0.0f, 0.0f, -25.0f); //Matrix44 world = m_world; //shaderInstance.setWorld(m_world * transform); //Matrix44 transform2; //rotate(transform2, Vector3::yAxis(), 90); //Matrix44 translateX; //translate(translateX, 25.0f, 0.0f, 0.0f); //Matrix44 temp = transform2 * translateX * m_world; //m_rotatingblades2.setWorld(temp); } } return shaderInstance; }
void FileSystem::put(std::string localFile, std::string remoteFile) { // hashing function to find the machine/s where to store the file; ChronoCpu chrono("cpu"); chrono.tic(); int fileKey = hashString(remoteFile); int position = findPositionByKey(fileKey); // cout<<"put "<<localFile<<" "<<fileKey<<" to "<<position<<" "<<virtualRing[position].ip_str<<" "<<virtualRing[position].key<<endl; bool attempt = putToNode( position, localFile, remoteFile ); attempt = putToNode( position+1, localFile, remoteFile ); attempt = putToNode( position+2, localFile, remoteFile ); chrono.tac(); std::cout << "File " << remoteFile << " added in " << chrono.getElapsedStats().lastTime_ms << " ms" << std::endl; }
//-------------------------------------- void _StringTable::resize(const U32 _newSize) { /// avoid a possible 0 division const U32 newSize = _newSize ? _newSize : 1; Node *head = NULL, *walk, *temp; U32 i; // reverse individual bucket lists // we do this because new strings are added at the end of bucket // lists so that case sens strings are always after their // corresponding case insens strings for(i = 0; i < numBuckets; i++) { walk = buckets[i]; while(walk) { temp = walk->next; walk->next = head; head = walk; walk = temp; } } buckets = (Node **) dRealloc(buckets, newSize * sizeof(Node)); for(i = 0; i < newSize; i++) { buckets[i] = 0; } numBuckets = newSize; walk = head; while(walk) { U32 key; Node *temp = walk; walk = walk->next; key = hashString(temp->val); temp->next = buckets[key % newSize]; buckets[key % newSize] = temp; } }
//Returns the index of the element, otherwise //Based on a linear probe: Best case o(1) worst o(n) int findElement(SET *sp, char *elt, bool *found) { *found=false; assert(sp!=NULL && elt!=NULL); unsigned int hash = hashString(elt); int i; int loc; int posDeleted=-1; //loop until through sp->length; string found; or empty location found for(i = 0; i<sp->length; i++) { loc = (hash+i)%sp->length; //remember the first deleted if(posDeleted==-1 && sp->flags[loc]==DELETED) posDeleted=loc; //If you found an empty, stop probing since you've past where the element would be if(sp->flags[loc]==EMPTY) { //return location of a deleted is possible, otherwise you can use an unused slot if(posDeleted!=-1) return posDeleted; else return loc; } //return location of element when it's found if(sp->flags[loc]==FILLED && strcmp(elt, sp->elts[loc])==0) { *found=true; return loc; } } //only occurs if not found at all, so look at bool found first return posDeleted; }
void * HashTable_insert(HashTable *ht, const char *key, void *value) { u4 size, mask, hash; HashEntry *entry; if ((ht->entries * 100) / ht->size >= ht->threshold) { HashTable_rebuild(ht); } size = ht->size; mask = size - 1; hash = hashString(key) & mask; entry = xmalloc(sizeof(HashEntry)); entry->key = key; entry->value = value; entry->next = ht->table[hash]; ht->table[hash] = entry; ++ht->entries; return value; }
void TextureManager::addLoad(const DeviceManager& deviceManager, const std::string& filename) { assert (!filename.empty()); //Extract filename if file name contains a path as well, this is not always true need to deal with relative paths here too std::string texureName = getTextureNameFromFileName(filename); if (find(texureName)) { //MSG_TRACE_CHANNEL("", "Texture: " << filename << " was already loaded. Skipping the loading of the second instance of this texture" << std::endl; return; } MSG_TRACE_CHANNEL("TEXTUREMANAGER", "Attempting to read in texture: %s", filename.c_str()); Texture tex; if (!tex.loadTextureFromFile(deviceManager, filename)) { MSG_TRACE_CHANNEL("ERROR", "Texture cannot be loaded: %s", filename.c_str()); } unsigned int textureFileNameHash = hashString(texureName); m_textures.insert(std::make_pair(textureFileNameHash, tex)); }
void FileSystem::get(std::string localFile, std::string remoteFile) { //https://gitlab-beta.engr.illinois.edu/remis2/MP3-FileSystem.git // hashing function to find the machine where to ask for the file; ChronoCpu chrono("cpu"); chrono.tic(); int fileKey = hashString(remoteFile); int position = findPositionByKey(fileKey); // cout<<"get "<<localFile<<" "<<fileKey<<" from "<<position<<" "<<virtualRing[position].ip_str<<" "<<virtualRing[position].key<<endl; bool attempt = getFromNode( position, localFile, remoteFile ); if(!attempt) { std::cout << "Retrying... " << std::endl; attempt = getFromNode( position+1, localFile, remoteFile ); } if(!attempt) { std::cout << "Retrying... " << std::endl; attempt = getFromNode( position+2, localFile, remoteFile ); } if (!attempt) { std::cout << "Error retrieving " << remoteFile << std::endl; } chrono.tac(); if(attempt) std::cout << "File " << remoteFile << " received in " << chrono.getElapsedStats().lastTime_ms << " ms" << std::endl; else std::cout << "File " << remoteFile << " cannot be found. returning in " << chrono.getElapsedStats().lastTime_ms << " ms" << std::endl; }
char *lumpName(char *name) /* Look for integer part of name (or hash it), then do mod operation * on it to assign to lump. */ { char *s = name, c; static char buf[32]; for (;;) { c = *s; if (c == 0) { safef(buf, sizeof(buf), "%03d", hashString(name) % lump); return buf; } if (isdigit(c)) { int lumpIx = atoi(s) % lump; lumpIx %= lump; safef(buf, sizeof(buf), "%03d", lumpIx); return buf; } ++s; } }
void addword(char *s, stringHashtable *h, int nodeNumber) { hashNumberType position = hashString(s, h->tableSize); stringEntry *p = h->table[position]; for(; p!= NULL; p = p->next) { if(strcmp(s, p->word) == 0) return; } p = (stringEntry *)malloc(sizeof(stringEntry)); assert(p); p->nodeNumber = nodeNumber; p->word = (char *)malloc((strlen(s) + 1) * sizeof(char)); strcpy(p->word, s); p->next = h->table[position]; h->table[position] = p; }
void *hashRemove(struct hash *hash, char *name) /* Remove item of the given name from hash table. * Returns value of removed item, or NULL if not in the table. * If their are multiple entries for name, the last one added * is removed (LIFO behavior). */ { struct hashEl *hel; void *ret; struct hashEl **pBucket = &hash->table[hashString(name)&hash->mask]; for (hel = *pBucket; hel != NULL; hel = hel->next) if (sameString(hel->name, name)) break; if (hel == NULL) return NULL; ret = hel->val; if (slRemoveEl(pBucket, hel)) { hash->elCount -= 1; if (!hash->lm) freeHashEl(hel); } return ret; }
static int echoBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){ int ii; char *zQuery = 0; char *zNew; int nArg = 0; const char *zSep = "WHERE"; echo_vtab *pVtab = (echo_vtab *)tab; sqlite3_stmt *pStmt = 0; Tcl_Interp *interp = pVtab->interp; int nRow; int useIdx = 0; int rc = SQLITE_OK; int useCost = 0; double cost; int isIgnoreUsable = 0; if( Tcl_GetVar(interp, "echo_module_ignore_usable", TCL_GLOBAL_ONLY) ){ isIgnoreUsable = 1; } if( simulateVtabError(pVtab, "xBestIndex") ){ return SQLITE_ERROR; } if( Tcl_GetVar(interp, "echo_module_cost", TCL_GLOBAL_ONLY) ){ cost = atof(Tcl_GetVar(interp, "echo_module_cost", TCL_GLOBAL_ONLY)); useCost = 1; } else { zQuery = sqlite3_mprintf("SELECT count(*) FROM %Q", pVtab->zTableName); if( !zQuery ){ return SQLITE_NOMEM; } rc = sqlite3_prepare(pVtab->db, zQuery, -1, &pStmt, 0); sqlite3_free(zQuery); if( rc!=SQLITE_OK ){ return rc; } sqlite3_step(pStmt); nRow = sqlite3_column_int(pStmt, 0); rc = sqlite3_finalize(pStmt); if( rc!=SQLITE_OK ){ return rc; } } zQuery = sqlite3_mprintf("SELECT rowid, * FROM %Q", pVtab->zTableName); if( !zQuery ){ return SQLITE_NOMEM; } for(ii=0; ii<pIdxInfo->nConstraint; ii++){ const struct sqlite3_index_constraint *pConstraint; struct sqlite3_index_constraint_usage *pUsage; int iCol; pConstraint = &pIdxInfo->aConstraint[ii]; pUsage = &pIdxInfo->aConstraintUsage[ii]; if( !isIgnoreUsable && !pConstraint->usable ) continue; iCol = pConstraint->iColumn; if( pVtab->aIndex[iCol] || iCol<0 ){ char *zCol = pVtab->aCol[iCol]; char *zOp = 0; useIdx = 1; if( iCol<0 ){ zCol = "rowid"; } switch( pConstraint->op ){ case SQLITE_INDEX_CONSTRAINT_EQ: zOp = "="; break; case SQLITE_INDEX_CONSTRAINT_LT: zOp = "<"; break; case SQLITE_INDEX_CONSTRAINT_GT: zOp = ">"; break; case SQLITE_INDEX_CONSTRAINT_LE: zOp = "<="; break; case SQLITE_INDEX_CONSTRAINT_GE: zOp = ">="; break; case SQLITE_INDEX_CONSTRAINT_MATCH: zOp = "LIKE"; break; } if( zOp[0]=='L' ){ zNew = sqlite3_mprintf(" %s %s LIKE (SELECT '%%'||?||'%%')", zSep, zCol); } else { zNew = sqlite3_mprintf(" %s %s %s ?", zSep, zCol, zOp); } string_concat(&zQuery, zNew, 1, &rc); zSep = "AND"; pUsage->argvIndex = ++nArg; pUsage->omit = 1; } } if( pIdxInfo->nOrderBy==1 && pVtab->aIndex[pIdxInfo->aOrderBy->iColumn] ){ int iCol = pIdxInfo->aOrderBy->iColumn; char *zCol = pVtab->aCol[iCol]; char *zDir = pIdxInfo->aOrderBy->desc?"DESC":"ASC"; if( iCol<0 ){ zCol = "rowid"; } zNew = sqlite3_mprintf(" ORDER BY %s %s", zCol, zDir); string_concat(&zQuery, zNew, 1, &rc); pIdxInfo->orderByConsumed = 1; } appendToEchoModule(pVtab->interp, "xBestIndex");; appendToEchoModule(pVtab->interp, zQuery); if( !zQuery ){ return rc; } pIdxInfo->idxNum = hashString(zQuery); pIdxInfo->idxStr = zQuery; pIdxInfo->needToFreeIdxStr = 1; if( useCost ){ pIdxInfo->estimatedCost = cost; }else if( useIdx ){ for( ii=0; ii<(sizeof(int)*8); ii++ ){ if( nRow & (1<<ii) ){ pIdxInfo->estimatedCost = (double)ii; } } }else{ pIdxInfo->estimatedCost = (double)nRow; } return rc; }
/* ============================================================================= * sequencer_run * ============================================================================= */ void sequencer_run (void* argPtr) { TM_THREAD_ENTER(); long threadId = thread_getId(); sequencer_t* sequencerPtr = (sequencer_t*)argPtr; hashtable_t* uniqueSegmentsPtr; endInfoEntry_t* endInfoEntries; table_t** startHashToConstructEntryTables; constructEntry_t* constructEntries; table_t* hashToConstructEntryTable; uniqueSegmentsPtr = sequencerPtr->uniqueSegmentsPtr; endInfoEntries = sequencerPtr->endInfoEntries; startHashToConstructEntryTables = sequencerPtr->startHashToConstructEntryTables; constructEntries = sequencerPtr->constructEntries; hashToConstructEntryTable = sequencerPtr->hashToConstructEntryTable; segments_t* segmentsPtr = sequencerPtr->segmentsPtr; assert(segmentsPtr); vector_t* segmentsContentsPtr = segmentsPtr->contentsPtr; long numSegment = vector_getSize(segmentsContentsPtr); long segmentLength = segmentsPtr->length; long i; long j; long i_start; long i_stop; long numUniqueSegment; long substringLength; long entryIndex; /* * Step 1: Remove duplicate segments */ // #if defined(HTM) || defined(STM) long numThread = thread_getNumThread(); { /* Choose disjoint segments [i_start,i_stop) for each thread */ long partitionSize = (numSegment + numThread/2) / numThread; /* with rounding */ i_start = threadId * partitionSize; if (threadId == (numThread - 1)) { i_stop = numSegment; } else { i_stop = i_start + partitionSize; } } // #else /* !(HTM || STM) */ // i_start = 0; // i_stop = numSegment; // #endif /* !(HTM || STM) */ for (i = i_start; i < i_stop; i+=CHUNK_STEP1) { TM_BEGIN(); { long ii; long ii_stop = MIN(i_stop, (i+CHUNK_STEP1)); for (ii = i; ii < ii_stop; ii++) { void* segment = vector_at(segmentsContentsPtr, ii); TMHASHTABLE_INSERT(uniqueSegmentsPtr, segment, segment); } /* ii */ } TM_END(); } thread_barrier_wait(); /* * Step 2a: Iterate over unique segments and compute hashes. * * For the gene "atcg", the hashes for the end would be: * * "t", "tc", and "tcg" * * And for the gene "tcgg", the hashes for the start would be: * * "t", "tc", and "tcg" * * The names are "end" and "start" because if a matching pair is found, * they are the substring of the end part of the pair and the start * part of the pair respectively. In the above example, "tcg" is the * matching substring so: * * (end) (start) * a[tcg] + [tcg]g = a[tcg]g (overlap = "tcg") */ /* uniqueSegmentsPtr is constant now */ numUniqueSegment = hashtable_getSize(uniqueSegmentsPtr); entryIndex = 0; // #if defined(HTM) || defined(STM) { /* Choose disjoint segments [i_start,i_stop) for each thread */ long num = uniqueSegmentsPtr->numBucket; long partitionSize = (num + numThread/2) / numThread; /* with rounding */ i_start = threadId * partitionSize; if (threadId == (numThread - 1)) { i_stop = num; } else { i_stop = i_start + partitionSize; } } { /* Approximate disjoint segments of element allocation in constructEntries */ long partitionSize = (numUniqueSegment + numThread/2) / numThread; /* with rounding */ entryIndex = threadId * partitionSize; } // #else /* !(HTM || STM) */ // i_start = 0; // i_stop = uniqueSegmentsPtr->numBucket; // entryIndex = 0; //#endif /* !(HTM || STM) */ for (i = i_start; i < i_stop; i++) { list_t* chainPtr = uniqueSegmentsPtr->buckets[i]; list_iter_t it; list_iter_reset(&it, chainPtr); while (list_iter_hasNext(&it, chainPtr)) { char* segment = (char*)((pair_t*)list_iter_next(&it, chainPtr))->firstPtr; constructEntry_t* constructEntryPtr; long j; ulong_t startHash; bool_t status; /* Find an empty constructEntries entry */ TM_BEGIN(); while (((void*)TM_SHARED_READ_P(constructEntries[entryIndex].segment)) != NULL) { entryIndex = (entryIndex + 1) % numUniqueSegment; /* look for empty */ } constructEntryPtr = &constructEntries[entryIndex]; TM_SHARED_WRITE_P(constructEntryPtr->segment, segment); TM_END(); entryIndex = (entryIndex + 1) % numUniqueSegment; /* * Save hashes (sdbm algorithm) of segment substrings * * endHashes will be computed for shorter substrings after matches * have been made (in the next phase of the code). This will reduce * the number of substrings for which hashes need to be computed. * * Since we can compute startHashes incrementally, we go ahead * and compute all of them here. */ /* constructEntryPtr is local now */ constructEntryPtr->endHash = (ulong_t)hashString(&segment[1]); startHash = 0; for (j = 1; j < segmentLength; j++) { startHash = (ulong_t)segment[j-1] + (startHash << 6) + (startHash << 16) - startHash; TM_BEGIN(); status = TMTABLE_INSERT(startHashToConstructEntryTables[j], (ulong_t)startHash, (void*)constructEntryPtr ); TM_END(); assert(status); } /* * For looking up construct entries quickly */ startHash = (ulong_t)segment[j-1] + (startHash << 6) + (startHash << 16) - startHash; TM_BEGIN(); status = TMTABLE_INSERT(hashToConstructEntryTable, (ulong_t)startHash, (void*)constructEntryPtr); TM_END(); assert(status); } } thread_barrier_wait(); /* * Step 2b: Match ends to starts by using hash-based string comparison. */ for (substringLength = segmentLength-1; substringLength > 0; substringLength--) { table_t* startHashToConstructEntryTablePtr = startHashToConstructEntryTables[substringLength]; list_t** buckets = startHashToConstructEntryTablePtr->buckets; long numBucket = startHashToConstructEntryTablePtr->numBucket; long index_start; long index_stop; // #if defined(HTM) || defined(STM) { /* Choose disjoint segments [index_start,index_stop) for each thread */ long partitionSize = (numUniqueSegment + numThread/2) / numThread; /* with rounding */ index_start = threadId * partitionSize; if (threadId == (numThread - 1)) { index_stop = numUniqueSegment; } else { index_stop = index_start + partitionSize; } } // #else /* !(HTM || STM) */ // index_start = 0; // index_stop = numUniqueSegment; //#endif /* !(HTM || STM) */ /* Iterating over disjoint itervals in the range [0, numUniqueSegment) */ for (entryIndex = index_start; entryIndex < index_stop; entryIndex += endInfoEntries[entryIndex].jumpToNext) { if (!endInfoEntries[entryIndex].isEnd) { continue; } /* ConstructEntries[entryIndex] is local data */ constructEntry_t* endConstructEntryPtr = &constructEntries[entryIndex]; char* endSegment = endConstructEntryPtr->segment; ulong_t endHash = endConstructEntryPtr->endHash; list_t* chainPtr = buckets[endHash % numBucket]; /* buckets: constant data */ list_iter_t it; list_iter_reset(&it, chainPtr); /* Linked list at chainPtr is constant */ while (list_iter_hasNext(&it, chainPtr)) { constructEntry_t* startConstructEntryPtr = (constructEntry_t*)list_iter_next(&it, chainPtr); char* startSegment = startConstructEntryPtr->segment; long newLength = 0; /* endConstructEntryPtr is local except for properties startPtr/endPtr/length */ TM_BEGIN(); /* Check if matches */ if (TM_SHARED_READ(startConstructEntryPtr->isStart) && (TM_SHARED_READ_P(endConstructEntryPtr->startPtr) != startConstructEntryPtr) && (strncmp(startSegment, &endSegment[segmentLength - substringLength], substringLength) == 0)) { TM_SHARED_WRITE(startConstructEntryPtr->isStart, FALSE); constructEntry_t* startConstructEntry_endPtr; constructEntry_t* endConstructEntry_startPtr; /* Update endInfo (appended something so no longer end) */ TM_LOCAL_WRITE(endInfoEntries[entryIndex].isEnd, FALSE); /* Update segment chain construct info */ startConstructEntry_endPtr = (constructEntry_t*)TM_SHARED_READ_P(startConstructEntryPtr->endPtr); endConstructEntry_startPtr = (constructEntry_t*)TM_SHARED_READ_P(endConstructEntryPtr->startPtr); assert(startConstructEntry_endPtr); assert(endConstructEntry_startPtr); TM_SHARED_WRITE_P(startConstructEntry_endPtr->startPtr, endConstructEntry_startPtr); TM_LOCAL_WRITE_P(endConstructEntryPtr->nextPtr, startConstructEntryPtr); TM_SHARED_WRITE_P(endConstructEntry_startPtr->endPtr, startConstructEntry_endPtr); TM_SHARED_WRITE(endConstructEntryPtr->overlap, substringLength); newLength = (long)TM_SHARED_READ(endConstructEntry_startPtr->length) + (long)TM_SHARED_READ(startConstructEntryPtr->length) - substringLength; TM_SHARED_WRITE(endConstructEntry_startPtr->length, newLength); } /* if (matched) */ TM_END(); if (!endInfoEntries[entryIndex].isEnd) { /* if there was a match */ break; } } /* iterate over chain */ } /* for (endIndex < numUniqueSegment) */ thread_barrier_wait(); /* * Step 2c: Update jump values and hashes * * endHash entries of all remaining ends are updated to the next * substringLength. Additionally jumpToNext entries are updated such * that they allow to skip non-end entries. Currently this is sequential * because parallelization did not perform better. . */ if (threadId == 0) { if (substringLength > 1) { long index = segmentLength - substringLength + 1; /* initialization if j and i: with i being the next end after j=0 */ for (i = 1; !endInfoEntries[i].isEnd; i+=endInfoEntries[i].jumpToNext) { /* find first non-null */ } /* entry 0 is handled seperately from the loop below */ endInfoEntries[0].jumpToNext = i; if (endInfoEntries[0].isEnd) { constructEntry_t* constructEntryPtr = &constructEntries[0]; char* segment = constructEntryPtr->segment; constructEntryPtr->endHash = (ulong_t)hashString(&segment[index]); } /* Continue scanning (do not reset i) */ for (j = 0; i < numUniqueSegment; i+=endInfoEntries[i].jumpToNext) { if (endInfoEntries[i].isEnd) { constructEntry_t* constructEntryPtr = &constructEntries[i]; char* segment = constructEntryPtr->segment; constructEntryPtr->endHash = (ulong_t)hashString(&segment[index]); endInfoEntries[j].jumpToNext = MAX(1, (i - j)); j = i; } } endInfoEntries[j].jumpToNext = i - j; } } thread_barrier_wait(); } /* for (substringLength > 0) */ thread_barrier_wait(); /* * Step 3: Build sequence string */ if (threadId == 0) { long totalLength = 0; for (i = 0; i < numUniqueSegment; i++) { constructEntry_t* constructEntryPtr = &constructEntries[i]; if (constructEntryPtr->isStart) { totalLength += constructEntryPtr->length; } } sequencerPtr->sequence = (char*)P_MALLOC((totalLength+1) * sizeof(char)); char* sequence = sequencerPtr->sequence; assert(sequence); char* copyPtr = sequence; long sequenceLength = 0; for (i = 0; i < numUniqueSegment; i++) { constructEntry_t* constructEntryPtr = &constructEntries[i]; /* If there are several start segments, we append in arbitrary order */ if (constructEntryPtr->isStart) { long newSequenceLength = sequenceLength + constructEntryPtr->length; assert( newSequenceLength <= totalLength ); copyPtr = sequence + sequenceLength; sequenceLength = newSequenceLength; do { long numChar = segmentLength - constructEntryPtr->overlap; if ((copyPtr + numChar) > (sequence + newSequenceLength)) { TM_PRINT0("ERROR: sequence length != actual length\n"); break; } memcpy(copyPtr, constructEntryPtr->segment, (numChar * sizeof(char))); copyPtr += numChar; } while ((constructEntryPtr = constructEntryPtr->nextPtr) != NULL); assert(copyPtr <= (sequence + sequenceLength)); } } assert(sequence != NULL); sequence[sequenceLength] = '\0'; } TM_THREAD_EXIT(); }
N_NIMCALL(NIM_BOOL, isdefined_191010)(NimStringDesc* symbol) { NIM_BOOL result; result = 0; { NIM_BOOL LOC3; NimStringDesc** LOC6; LOC3 = 0; LOC3 = nsthasKey(gsymbols_191001, symbol); if (!LOC3) goto LA4; LOC6 = 0; LOC6 = nstTake(gsymbols_191001, symbol); result = !(eqStrings((*LOC6), ((NimStringDesc*) &TMP1591))); } goto LA1; LA4: ; { NI LOC8; LOC8 = 0; LOC8 = nsuCmpIgnoreStyle(symbol, Cpu_168476[(targetcpu_168601)- 1].Field0); if (!(LOC8 == ((NI) 0))) goto LA9; result = NIM_TRUE; } goto LA1; LA9: ; { NI LOC12; LOC12 = 0; LOC12 = nsuCmpIgnoreStyle(symbol, Os_168055[(targetos_168603)- 1].Field0); if (!(LOC12 == ((NI) 0))) goto LA13; result = NIM_TRUE; } goto LA1; LA13: ; { NimStringDesc* LOC16; LOC16 = 0; LOC16 = nsuNormalize(symbol); switch (hashString(LOC16) & 31) { case 2: if (eqStrings(LOC16, ((NimStringDesc*) &TMP1602))) goto LA25; if (eqStrings(LOC16, ((NimStringDesc*) &TMP1608))) goto LA31; break; case 6: if (eqStrings(LOC16, ((NimStringDesc*) &TMP1597))) goto LA21; if (eqStrings(LOC16, ((NimStringDesc*) &TMP1605))) goto LA28; break; case 7: if (eqStrings(LOC16, ((NimStringDesc*) &TMP1594))) goto LA19; if (eqStrings(LOC16, ((NimStringDesc*) &TMP1604))) goto LA27; break; case 8: if (eqStrings(LOC16, ((NimStringDesc*) &TMP1601))) goto LA24; break; case 11: if (eqStrings(LOC16, ((NimStringDesc*) &TMP1599))) goto LA23; break; case 13: if (eqStrings(LOC16, ((NimStringDesc*) &TMP1603))) goto LA26; break; case 15: if (eqStrings(LOC16, ((NimStringDesc*) &TMP1592))) goto LA17; break; case 17: if (eqStrings(LOC16, ((NimStringDesc*) &TMP1598))) goto LA22; break; case 19: if (eqStrings(LOC16, ((NimStringDesc*) &TMP1596))) goto LA20; break; case 20: if (eqStrings(LOC16, ((NimStringDesc*) &TMP1610))) goto LA33; break; case 22: if (eqStrings(LOC16, ((NimStringDesc*) &TMP1606))) goto LA29; if (eqStrings(LOC16, ((NimStringDesc*) &TMP1607))) goto LA30; break; case 25: if (eqStrings(LOC16, ((NimStringDesc*) &TMP1609))) goto LA32; break; case 27: if (eqStrings(LOC16, ((NimStringDesc*) &TMP1593))) goto LA18; if (eqStrings(LOC16, ((NimStringDesc*) &TMP1600))) goto LA24; break; case 30: if (eqStrings(LOC16, ((NimStringDesc*) &TMP1595))) goto LA20; break; } goto LA34; LA17: ; { result = (targetcpu_168601 == ((NU8) 1)); } goto LA35; LA18: ; { result = (targetcpu_168601 == ((NU8) 9)); } goto LA35; LA19: ; { result = (targetcpu_168601 == ((NU8) 10)); } goto LA35; LA20: ; { result = ((3768304 &(1U<<((NU)(targetos_168603)&31U)))!=0); } goto LA35; LA21: ; { result = ((3584 &(1U<<((NU)(targetos_168603)&31U)))!=0); } goto LA35; LA22: ; { result = ((Os_168055[(targetos_168603)- 1].Field12 &(1U<<((NU)(((NU8) 3))&7U)))!=0); } goto LA35; LA23: ; { result = (targetos_168603 == ((NU8) 1)); } goto LA35; LA24: ; { result = (targetos_168603 == ((NU8) 2)); } goto LA35; LA25: ; { result = ((786432 &(1U<<((NU)(targetos_168603)&31U)))!=0); } goto LA35; LA26: ; { result = (targetos_168603 == ((NU8) 7)); } goto LA35; LA27: ; { result = (Cpu_168476[(targetcpu_168601)- 1].Field2 == ((NU8) 0)); } goto LA35; LA28: ; { result = (Cpu_168476[(targetcpu_168601)- 1].Field2 == ((NU8) 1)); } goto LA35; LA29: ; { result = (Cpu_168476[(targetcpu_168601)- 1].Field4 == ((NI) 8)); } goto LA35; LA30: ; { result = (Cpu_168476[(targetcpu_168601)- 1].Field4 == ((NI) 16)); } goto LA35; LA31: ; { result = (Cpu_168476[(targetcpu_168601)- 1].Field4 == ((NI) 32)); } goto LA35; LA32: ; { result = (Cpu_168476[(targetcpu_168601)- 1].Field4 == ((NI) 64)); } goto LA35; LA33: ; { result = ((528000 &(1U<<((NU)(targetos_168603)&31U)))!=0); } goto LA35; LA34: ; { } LA35: ; } LA1: ; return result; }
FileSystem::FileEntry::FileEntry(std::string name){ this->filename = name; this->key = hashString(this->filename); }