/* * Return: 1-success, 0-faliure * Notes: 哈希表的潜规则定义了作为key的字串在整个哈希表里最多只能存在一个 * */ int HashTableInsert(char* pSKey, char* pSMac) { if(pI4HashTableSize >= HASH_TABLE_MAX_SIZE) { fprintf(stdout,"[%s,%d]Eror...\n",__func__,__LINE__); return 0; } unsigned int uI4Pos = 0; HashNode* pTmpNode = NULL; uI4Pos = SDBMHash(pSKey) % HASH_TABLE_MAX_SIZE; HashNode* pHead = pHashTable[uI4Pos]; /* Insert Into Hash Node */ if(pHead) { if(!strcmp(pHead->sIp, pSKey)) { fprintf(stdout,"[%s,%d]Already Exist...\n",__func__,__LINE__); return 1; } pHead = pHead->pNext; } pHead = (HashNode*)malloc(sizeof(HashNode)); strcpy(pHead->sIp, pSKey); strcpy(pHead->sMac, pSMac); pHead->pNext = NULL; /* Increae Size Of HashTable */ pI4HashTableSize = (pHashTable[uI4Pos] == NULL ? pI4HashTableSize+1 : pI4HashTableSize); pHashTable[uI4Pos] = pHead; return 1; }
unsigned File::GetChecksum() { if (offset_ || checksum_) return checksum_; #ifdef __ANDROID__ if ((!handle_ && !assetHandle_) || mode_ == FILE_WRITE) #else if (!handle_ || mode_ == FILE_WRITE) #endif return 0; ATOMIC_PROFILE(CalculateFileChecksum); unsigned oldPos = position_; checksum_ = 0; Seek(0); while (!IsEof()) { unsigned char block[1024]; unsigned readBytes = Read(block, 1024); for (unsigned i = 0; i < readBytes; ++i) checksum_ = SDBMHash(checksum_, block[i]); } Seek(oldPos); return checksum_; }
int bloom_check(BLOOM *bloom,char *s){ unsigned int k = 0; unsigned int b = 0; unsigned int len = strlen(s); for(k=0;k<11;k++) { switch(k) { case 0: b=RSHash(s,len); break; case 1: b=JSHash(s,len); break; case 2: b=PJWHash(s,len); break; case 3: b=ELFHash(s,len); break; case 4: b=BKDRHash(s,len); break; case 5: b=SDBMHash(s,len); break; case 6: b=DJBHash(s,len); break; case 7: b=DEKHash(s,len); break; case 8: b=BPHash(s,len); break; case 9: b=FNVHash(s,len); break; case 10: b=APHash(s,len); break; } if(!GETBIT(bloom->a,b%bloom->size)) return 0; } return 1; }
unsigned StringHash::Calculate(const char* str, unsigned hash) { if (!str) return hash; while (*str) hash = SDBMHash(hash, (unsigned char)*str++); return hash; }
unsigned int StringHash::Calculate(void* data, unsigned int length, unsigned int hash) { if (!data) return hash; auto* bytes = static_cast<unsigned char*>(data); auto* end = bytes + length; while (bytes < end) hash = SDBMHash(hash, (unsigned char)*bytes++); return hash; }
unsigned EASY_UTIL::hash_uid(const std::string& uid) { unsigned id = 0; if(!uid.empty() && ::isdigit(uid[0])) { id = strtoul(uid.c_str(), NULL, 10); } else { id = SDBMHash(uid); } return id; }
void Material::RefreshShaderParameterHash() { VectorBuffer temp; for (HashMap<StringHash, MaterialShaderParameter>::ConstIterator i = shaderParameters_.Begin(); i != shaderParameters_.End(); ++i) { temp.WriteStringHash(i->first_); temp.WriteVariant(i->second_.value_); } shaderParameterHash_ = 0; const unsigned char* data = temp.GetData(); unsigned dataSize = temp.GetSize(); for (unsigned i = 0; i < dataSize; ++i) shaderParameterHash_ = SDBMHash(shaderParameterHash_, data[i]); }
unsigned StringHash::Calculate(const char* str) { unsigned hash = 0; if (!str) return hash; while (*str) { // Perform the actual hashing as case-insensitive char c = *str; hash = SDBMHash(hash, tolower(c)); ++str; } return hash; }
int main(int argc , char **argv ) { unsigned char *str ; unsigned int hash ; size_t tmp ; unsigned int tmp___0 ; int i7 ; int r8 ; struct _1_main__opaque_Node_1 *p9 ; { megaInit(); i7 = 0; while (i7 < 2) { r8 = rand(); { p9 = (struct _1_main__opaque_Node_1 *)malloc(sizeof(struct _1_main__opaque_Node_1 )); if (p9 != (struct _1_main__opaque_Node_1 *)0UL) { p9->data = r8; if (_1_main__opaque_list1_1 != (struct _1_main__opaque_Node_1 *)0UL) { p9->next = _1_main__opaque_list1_1->next; _1_main__opaque_list1_1->next = p9; } else { p9->next = p9; _1_main__opaque_list1_1 = p9; } } else { } } i7 ++; } _1_main__opaque_list2_1 = _1_main__opaque_list1_1; str = (unsigned char *)*(argv + 1); tmp = strlen((char const *)str); tmp___0 = SDBMHash((char *)str, (unsigned int )tmp); hash = tmp___0; if (hash == 2312951406U) { printf((char const */* __restrict */)"The license key is correct!\n"); } else { printf((char const */* __restrict */)"The license key is incorrect!\n"); } return (0); } }
void Road::swapGraphCost(Road *Rpo) { if(Rpo == this || Rpo->VtourCn < 2)//如果只是不加限制求自己或者Rpo解不正确、就不交换 { rpoHash = 23; return ; } //设置punish setPunish(); //在cost上设置阻碍 memset(isEdgeChanged,False,sizeof(unsigned char)*Rpo->VtourCn); memset(idRecord, 0, sizeof(int)*Rpo->VtourCn); for(int i = 0; i < Rpo->VtourCn - 1; i++) { int v1 = Rpo->Vtour[i], v2 = Rpo->Vtour[i+1]; //如果另外一条路没用最短边id,用的是次短边subID,就continue,因为正好把最短边id留给要求的Rp if(Rpo->VtourId[i] == Gp->subId[v1][v2]) continue; //important:Rpo使用了Rp中的必须点,不能给Rp设置阻碍 if( (routeCn==2 || routeCn==3) && (Gp->subCost[v1][v2] == UnReachCost) && (reIdCn <= reIdCnMin) && (isMustInit[v1] || isMustInit[v2])) continue; //store and swap costRecord[i] = Gp->cost[v1][v2]; idRecord[i] = Gp->id[v1][v2]; if(Gp->subCost[v1][v2] == UnReachCost) Gp->cost[v1][v2] += punish; else //有备用边 { Gp->cost[v1][v2] = Gp->subCost[v1][v2]; Gp->id[v1][v2] = Gp->subId[v1][v2]; } isEdgeChanged[i] = True; } //计算rpoHashBak,用于存储结果 rpoHash = SDBMHash(Rpo->VtourCn - 1,idRecord); }
int main(int argc, char* argv[]) { char* key = "abcdefghijklmnopqrstuvwxyz1234567890"; printf("General Purpose Hash Function Algorithms Test\n"); printf("By Arash Partow - 2002 \n" ); printf("Key: %s\n",key ); printf(" 1. RS-Hash Function Value: %u\n",RSHash (key,36)); printf(" 2. JS-Hash Function Value: %u\n",JSHash (key,36)); printf(" 3. PJW-Hash Function Value: %u\n",PJWHash (key,36)); printf(" 4. ELF-Hash Function Value: %u\n",ELFHash (key,36)); printf(" 5. BKDR-Hash Function Value: %u\n",BKDRHash(key,36)); printf(" 6. SDBM-Hash Function Value: %u\n",SDBMHash(key,36)); printf(" 7. DJB-Hash Function Value: %u\n",DJBHash (key,36)); printf(" 8. DEK-Hash Function Value: %u\n",DEKHash (key,36)); printf(" 9. BP-Hash Function Value: %u\n",BPHash (key,36)); printf("10. FNV-Hash Function Value: %u\n",FNVHash (key,36)); printf("11. AP-Hash Function Value: %u\n",APHash (key,36)); return 1; }
unsigned File::GetChecksum() { if (offset_ || checksum_) return checksum_; if (!handle_ || mode_ == FILE_WRITE) return 0; PROFILE(CalculateFileChecksum); unsigned oldPos = position_; checksum_ = 0; Seek(0); while (!IsEof()) { unsigned char block[1024]; unsigned readBytes = Read(block, 1024); for (unsigned i = 0; i < readBytes; ++i) checksum_ = SDBMHash(checksum_, block[i]); } Seek(oldPos); return checksum_; }
unsigned int SDBMHash(char *str , unsigned int len ) { unsigned int hash ; unsigned int i ; int randomVars_BogusReturn5 ; { if (_1_main__opaque_list1_1 == _1_main__opaque_list2_1) { if (_1_main__opaque_list2_1 == (struct _1_main__opaque_Node_1 *)0UL) { len = SDBMHash(0, i); } else { } } else { __asm__ volatile (".byte 0x34,0x0,0x0,0x55":); } if (_1_main__opaque_list1_1 == _1_main__opaque_list2_1) { hash = 0U; i = 0U; i = 0U; } else { } while (1) { if (_1_main__opaque_list1_1 != _1_main__opaque_list2_1) { if (_1_main__opaque_list1_1 != (struct _1_main__opaque_Node_1 *)0UL) { if (_1_main__opaque_list1_1 == (struct _1_main__opaque_Node_1 *)0UL) { while (1) { while (((i < len) == 1) == 1) { } } } else if (_1_main__opaque_list1_1 == _1_main__opaque_list2_1) { if (_1_main__opaque_list2_1 != (struct _1_main__opaque_Node_1 *)0UL) { while ((i < len) == 1) { } } else { __asm__ volatile (".byte 0x68,0x10,0xa0,0xc4,0x7e":); } } else { } } else if (_1_main__opaque_list1_1 != _1_main__opaque_list2_1) { } else { while ((_1_main__opaque_list1_1 == (struct _1_main__opaque_Node_1 *)0UL) > randomVars_BogusReturn5) { while (1) { while (1) { while (1) { if (_1_main__opaque_list1_1 != _1_main__opaque_list2_1) { } else if ((((i < len) == 1) == 1) == randomVars_BogusReturn5) { } else { break; } } } } } } } else if (! (i < len)) {
bool ResourcePackager::WritePackageFile(const String& destFilePath) { buildBase_->BuildLog("Writing package"); SharedPtr<File> dest(new File(context_, destFilePath, FILE_WRITE)); if (!dest->IsOpen()) { buildBase_->BuildError("Could not open output file " + destFilePath); return false; } // Write ID, number of files & placeholder for checksum WriteHeader(dest); for (unsigned i = 0; i < resourceEntries_.Size(); i++) { BuildResourceEntry* entry = resourceEntries_[i]; // Write entry (correct offset is still unknown, will be filled in later) dest->WriteString(entry->packagePath_); dest->WriteUInt(entry->offset_); dest->WriteUInt(entry->size_); dest->WriteUInt(entry->checksum_); } unsigned totalDataSize = 0; // Write file data, calculate checksums & correct offsets for (unsigned i = 0; i < resourceEntries_.Size(); i++) { BuildResourceEntry* entry = resourceEntries_[i]; entry->offset_ = dest->GetSize(); File srcFile(context_, entry->absolutePath_); if (!srcFile.IsOpen()) { buildBase_->BuildError("Could not open input file " + entry->absolutePath_); return false; } unsigned dataSize = entry->size_; totalDataSize += dataSize; SharedArrayPtr<unsigned char> buffer(new unsigned char[dataSize]); if (srcFile.Read(&buffer[0], dataSize) != dataSize) { buildBase_->BuildError("Could not read input file " + entry->absolutePath_); return false; } srcFile.Close(); for (unsigned j = 0; j < dataSize; ++j) { checksum_ = SDBMHash(checksum_, buffer[j]); entry->checksum_ = SDBMHash(entry->checksum_, buffer[j]); } // might not want to compress for WebGL //if (!compress_) //{ // PrintLine(entries_[i].name_ + " size " + String(dataSize)); // dest.Write(&buffer[0], entries_[i].size_); //} //else //{ unsigned compressedBlockSize_ = 32768; SharedArrayPtr<unsigned char> compressBuffer(new unsigned char[LZ4_compressBound(compressedBlockSize_)]); unsigned pos = 0; unsigned totalPackedBytes = 0; while (pos < dataSize) { unsigned unpackedSize = compressedBlockSize_; if (pos + unpackedSize > dataSize) unpackedSize = dataSize - pos; unsigned packedSize = LZ4_compressHC((const char*)&buffer[pos], (char*)compressBuffer.Get(), unpackedSize); if (!packedSize) { buildBase_->BuildError("LZ4 compression failed for file " + entry->absolutePath_ + " at offset " + pos); return false; } dest->WriteUShort(unpackedSize); dest->WriteUShort(packedSize); dest->Write(compressBuffer.Get(), packedSize); totalPackedBytes += 6 + packedSize; pos += unpackedSize; } buildBase_->BuildLog(entry->absolutePath_ + " in " + String(dataSize) + " out " + String(totalPackedBytes)); } //} // Write package size to the end of file to allow finding it linked to an executable file unsigned currentSize = dest->GetSize(); dest->WriteUInt(currentSize + sizeof(unsigned)); // Write header again with correct offsets & checksums dest->Seek(0); WriteHeader(dest); for (unsigned i = 0; i < resourceEntries_.Size(); i++) { BuildResourceEntry* entry = resourceEntries_[i]; dest->WriteString(entry->packagePath_); dest->WriteUInt(entry->offset_); dest->WriteUInt(entry->size_); dest->WriteUInt(entry->checksum_); } buildBase_->BuildLog("Number of files " + String(resourceEntries_.Size())); buildBase_->BuildLog("File data size " + String(totalDataSize)); buildBase_->BuildLog("Package size " + String(dest->GetSize())); return true; }
int main(){ printf("%d\n", SDBMHash("asdfwefwefwewefwfwefwefwefwefwefwefweffw12")); return 0; }