Cache::i_Point CGALCache::hashPoint(const CGAL::Point3& pt) { i_Point ip; ip.append(hashValue(pt.x())); ip.append(hashValue(pt.y())); ip.append(hashValue(pt.z())); return ip; }
Cache::i_Point Cache::hashPoint(const Point& pt) { i_Point ip; decimal x,y,z; pt.getXYZ(x,y,z); ip.append(hashValue(x)); ip.append(hashValue(y)); ip.append(hashValue(z)); return ip; }
/** * void hashMapInfos::addHasher ( string key, string value ) * @param key * @param value */ void hashMapInfos::addHasher ( string key, vector<int> value ) { if ( trouve ( hashValue ( key ) ) ==0 ) { // cerr << "ICI1" <<endl; infosHasher H ( hashValue ( key ),key,value ); // cerr <<" "<< hashValue ( key )<<" "<< key<<" "<<value <<endl; // cerr << "ICI2" <<endl; m_hasher.push_back ( H ); } }
static rc testHashImpliesEquals(void) { List *l1; List *l2; l1 = LIST_MAKE(CS("A"), CS("B")); l2 = LIST_MAKE(CS("A"), CS("B")); ASSERT_EQUALS_LONG(hashValue(l1), hashValue(l2), "same hash for l1 and l2"); return PASS; }
/***************************************************************************** Note that it is assumed that a "value" of zero means an undefined keyword and clients of this function should observe this. Also, all keywords added should be added in lower case. If we encounter a case-sensitive language whose keywords are in upper case, we will need to redesign this. *****************************************************************************/ void Keywords::addKeyword (const char *const string, Language language, int value) { const unsigned long hashedValue = hashValue (string); hashEntry *entry = getHashTableEntry (hashedValue); if (entry == NULL) { table [hashedValue] = newEntry (string, language, value); } else { hashEntry *prev = NULL; while (entry != NULL) { if (language == entry->language && strcmp (string, entry->string) == 0) { Assert (("Already in table" == NULL)); } prev = entry; entry = entry->next; } if (entry == NULL) { Assert (prev != NULL); prev->next = newEntry (string, language, value); } } }
// Remove item if it is in the map void StringMap::deleteItem(std::string key){ tableOffset = hashValue(key); if (values[tableOffset]->deleteItem(key)){ std::cout << DELETESUCCESS << std::endl; }else{ std::cout << DELETEFAIL << std::endl; } }
// insert a key, value pair into the map, standard insert void StringMap::insert(std::string key, std::string value){ tableOffset = hashValue(key); // The map index // std::cout << tableOffset << std::endl; if (values[tableOffset]->insert(value)) std::cout << INSERTSUCCESS << std::endl; else std::cout << INSERTFAIL << std::endl; }
// Insert a key using a string pointer Used for timing runs void StringMap::insert(std::string* empty, std::string* value){ tableOffset = hashValue(*value); // std::cout << tableOffset << std::endl; values[tableOffset]->insert(value); //use this insert for timing // if (values[tableOffset]->insert(value)) // std::cout << INSERTSUCCESS << std::endl; // else // std::cout << INSERTFAIL << std::endl; }
//Search for a specific item in the hash table. Return True if found. bool HashTable::search(int item) { bool flag = true; //Need a flag to know if we are finished. int j= 0; int hValue = hashValue(item, j); //j ill work on it //while ((count < (capacity) && (table[theHashIdx] != item) && (table[theHashIdx] != -1)) //linear probing while ((j < (capacity + 1) / 2) && (table[hValue] != item) && (table[hValue] != -1)) //quadratic function { hValue = hashValue(item, ++j); //value changed } //Created flag variable for readability //This flag determines if we were finished. Notice it ends at (capacity + 1)/2 if ((table[hValue] == -1) || ((capacity + 1) / 2 == j)) flag = false; return flag; }
hash_type SerializedObject::hash(void) const { if (!mHash) { hash_type h = (mSerializedData ? hashValue(*mSerializedData) : hash_type()); h = h + hashValue(mTypesReferenced); h = h + hashValue(mJovsReferenced); h = h + hashValue(mExpressionsReferenced); h = h + hashValue(mControlFlowGraphsReferenced); h = h + mMemoStorage.hash(); mHash = h; } return *mHash; }
//searchKeyIdx int HashTable::searchKeyIdx(int key) const { int j = 0; int hValue = hashValue(key, j); bool flag = false; while ((table[hValue] != -1) && (j < (capacity + 1) / 2) && (!flag)) { if (table[hValue] == key) flag = true; else { hValue = hashValue(key, ++j); flag = false; hValue = -999; } } return hValue; }
// Find and return the value associated with a key std::string* StringMap::find(std::string key){ tableOffset = hashValue(key); returnValue = values[tableOffset]->find(key); if (returnValue != NULL) // item is in list return (std::string*) &FINDSUCCESS; return returnValue; //NULL if function gets here. }
int hashMapInfos::trouve ( string key ) { long searchKey=hashValue ( key ); long foundKey;; // vector<infosHasher>::const_iterator l_hasher=m_hasher.begin(); for ( vector<infosHasher>:: iterator l_hasher=m_hasher.begin() ; l_hasher!=m_hasher.end() ; l_hasher++ ) { foundKey= ( *l_hasher ).getHashKey(); if ( searchKey == foundKey ) { return 1; } } return 0; }
void hashMapInfos::setValue ( string key , vector<int> value ) { long searchKey=hashValue ( key ); long foundKey; // vector<infosHasher>::const_iterator l_hasher=m_hasher.begin(); for ( vector<infosHasher>:: iterator l_hasher=m_hasher.begin() ; l_hasher!=m_hasher.end() ; l_hasher++ ) { foundKey= ( *l_hasher ).getHashKey(); if ( searchKey == foundKey ) { ( *l_hasher ).setValue ( value ); // return ( *l_hasher ).getValue(); } } }
//Function for insert void HashTable::insert(int theKey) { int j = 0; int hValue = hashValue(theKey, j); //Hash Value for Readability //while ((count < (capacity) && (table[hValue] != -1)) //linear probing //Quadratic function. while ((j < (capacity + 1) / 2) && (table[hValue] != -1) && (table[hValue] != -2)) //quadratic function { hValue = hashValue(theKey, ++j); } if (numOfElements == capacity) cerr << "Table is full. Cannot insert." << endl; else { ++numOfElements; table[hValue] = theKey; } //Insert should be when f == r. Cannot since f and r are not declared in private. }
infosHasher hashMapInfos::getHasher ( string key ) { long searchKey=hashValue ( key ); long foundKey; // vector<infosHasher>::const_iterator l_hasher=m_hasher.begin(); for ( vector<infosHasher>:: iterator l_hasher=m_hasher.begin() ; l_hasher!=m_hasher.end() ; l_hasher++ ) { foundKey= ( *l_hasher ).getHashKey(); if ( searchKey == foundKey ) { return ( *l_hasher ); } } vector<int> temp; infosHasher defaut(0,"",temp); return defaut; }
vector<int> hashMapInfos::getValue ( string key ) { long searchKey=hashValue ( key ); long foundKey; vector<int> retour; // vector<infosHasher>::const_iterator l_hasher=m_hasher.begin(); for ( vector<infosHasher>:: iterator l_hasher=m_hasher.begin() ; l_hasher!=m_hasher.end() ; l_hasher++ ) { foundKey= ( *l_hasher ).getHashKey(); if ( searchKey == foundKey ) { // cerr <<"value found : " << key<<"|"<< ( *l_hasher ).getValue()<<endl; return ( *l_hasher ).getValue(); } } return retour; }
int Keywords::lookupKeyword (const char *const string, Language language) { const unsigned long hashedValue = hashValue (string); hashEntry *entry = getHashTableEntry (hashedValue); int result = -1; while (entry != NULL) { if (language == entry->language && strcmp (string, entry->string) == 0) { result = entry->value; break; } entry = entry->next; } return result; }
static MemoryTrackerFileName_t *MemoryTrackerFileNameLookup(const char *filename, unsigned int *hash) { unsigned int hashVal; MemoryTrackerFileName_t *trk; int len = strlen(filename); hashVal = hashValue(filename) % MEMORY_TRACKER_BUCKETS; *hash = hashVal; for(trk = MemoryTrackerBuckets[hashVal]; trk != NULL; trk = trk->next) { if (trk->filenameLen == len) { if (memcmp(&trk->filename[0], filename, len) == 0) { return trk; } } } return NULL; }
void Scope::rehash() { _hashSize <<= 1; if (! _hashSize) _hashSize = DefaultInitialSize; _hash = reinterpret_cast<Symbol **>(realloc(_hash, sizeof(Symbol *) * _hashSize)); memset(_hash, 0, sizeof(Symbol *) * _hashSize); for (int index = 0; index < _symbolCount + 1; ++index) { Symbol *symbol = _symbols[index]; const unsigned h = hashValue(symbol); symbol->_next = _hash[h]; _hash[h] = symbol; } }
static uint32_t addToHashTable(uint64_t value) { uint64_t hash = hashValue(value); uint32_t locationsChecked = 0; while(hashTable[hash].value != value && hashTable[hash].count != 0) { hash++; if(hash == HASH_TABLE_SIZE) { hash = 0; } locationsChecked++; if(locationsChecked > 1024) { fprintf(stderr, "Hash table full. Increase HASH_TABLE_SIZE\n"); exit(1); } } hashTable[hash].value = value; hashTable[hash].count++; return hashTable[hash].count; }
HMACAuth::HMACHash HMACAuth::result() { HMACHash hashValue(EVP_MAX_MD_SIZE); unsigned int hashLen; QMutexLocker lock(&_lock); auto hmacResult = HMAC_Final(_hmacContext, &hashValue[0], &hashLen); if (hmacResult) { hashValue.resize((size_t)hashLen); } else { // the HMAC_FINAL call failed - should not be possible to get into this state qCWarning(networking) << "Error occured calling HMAC_Final"; assert(hmacResult); } // Clear state for possible reuse. HMAC_Init_ex(_hmacContext, nullptr, 0, nullptr, nullptr); return hashValue; }
void Scope::enterSymbol(Symbol *symbol) { if (++_symbolCount == _allocatedSymbols) { _allocatedSymbols <<= 1; if (! _allocatedSymbols) _allocatedSymbols = DefaultInitialSize; _symbols = reinterpret_cast<Symbol **>(realloc(_symbols, sizeof(Symbol *) * _allocatedSymbols)); } assert(! symbol->_scope || symbol->scope() == this); symbol->_index = _symbolCount; symbol->_scope = this; _symbols[_symbolCount] = symbol; if (_symbolCount >= _hashSize * 0.6) rehash(); else { const unsigned h = hashValue(symbol); symbol->_next = _hash[h]; _hash[h] = symbol; } }
// hash-source = "'" hash-algorithm "-" base64-value "'" // hash-algorithm = "sha256" / "sha384" / "sha512" // base64-value = 1*( ALPHA / DIGIT / "+" / "/" / "-" / "_" )*2( "=" ) bool ContentSecurityPolicySourceList::parseHashSource(const UChar* begin, const UChar* end) { if (begin == end) return false; const UChar* position = begin; if (!skipExactly<UChar>(position, end, '\'')) return false; ContentSecurityPolicyHashAlgorithm algorithm; if (!parseHashAlgorithmAdvancingPosition(position, end - position, algorithm)) return false; if (!skipExactly<UChar>(position, end, '-')) return false; const UChar* beginHashValue = position; skipWhile<UChar, isBase64Character>(position, end); skipExactly<UChar>(position, end, '='); skipExactly<UChar>(position, end, '='); if (position >= end || position == beginHashValue || *position != '\'') return false; Vector<uint8_t> digest; StringView hashValue(beginHashValue, position - beginHashValue); // base64url or base64 encoded // FIXME: Normalize Base64URL to Base64 instead of decoding twice. See <https://bugs.webkit.org/show_bug.cgi?id=155186>. if (!base64Decode(hashValue.toStringWithoutCopying(), digest, Base64ValidatePadding)) { if (!base64URLDecode(hashValue.toStringWithoutCopying(), digest)) return false; } if (digest.size() > maximumContentSecurityPolicyDigestLength) return false; m_hashes.add(std::make_pair(algorithm, digest)); m_hashAlgorithmsUsed |= algorithm; return true; }
// // Opens client-side sub-session for a registered script. The script session is modelled as a // client side sub-session with a peer server side sub-session. // TInt RSecMgrSubSession::Open(const RSessionBase& aSession, CScript& aScriptInfo, TPolicyID aPolicyID, const TDesC& aHashValue) { TIpcArgs args(aScriptInfo.ScriptID (), aPolicyID); TInt errCode(KErrNone); errCode = iFs.Connect(); if(errCode == KErrNone) { if ( KAnonymousScript==aScriptInfo.ScriptID ()) errCode = CreateSubSession (aSession, EGetTrustedUnRegScriptSession, args); else errCode = CreateSubSession (aSession, EGetScriptSession, args); if ( errCode==KErrNone) { // Retrieve the RFs and RFile handles from the server TPckgBuf<TInt> fh; // sub-session (RFile) handle TIpcArgs args(&fh); RFile file; CleanupClosePushL(file); if ( KErrNone==errCode) { iFs.ShareProtected (); TFileName tempDirPath; TFileName tempPath; iFs.PrivatePath (tempDirPath); BaflUtils::EnsurePathExistsL (iFs, tempDirPath); errCode = file.Temp (iFs, tempDirPath, tempPath, EFileWrite); if ( KErrNone==errCode) { file.TransferToServer (args, EMsgArgOne, EMsgArgTwo); errCode = SendReceive (EGetScriptFile, args); if ( KErrNone==errCode) { RFileReadStream rfs(file); CleanupClosePushL(rfs); aScriptInfo.InternalizeL (rfs); TBufC<KMaxPath> hashValue(aScriptInfo.Hash()); if(0 != hashValue.Compare(KNullDesC)) { if(!aScriptInfo.HashMatch(aHashValue)) { //hash check failed errCode = KErrNotFound; } } CleanupStack::PopAndDestroy(&rfs); } } iFs.Delete (tempPath); } CleanupStack::PopAndDestroy(&file); } } return errCode; }
static void doSerialize(A2PWriter writer, A2PType expected, ATerm value){ DKISIndexedSet sharedValues = writer->valueSharingMap; int valueHash = hashValue(value); int valueId = DKISget(sharedValues, (void*) value, (void*) expected, valueHash); /* TODO: Fix sharing (check types). */ if(valueId != -1){ writeByteToBuffer(writer->buffer, PDB_SHARED_FLAG); printInteger(writer->buffer, valueId); return; } switch(expected->id){ case PDB_VALUE_TYPE_HEADER: serializeUntypedTerm(writer, value); break; case PDB_BOOL_TYPE_HEADER: if(ATgetType(value) != AT_APPL){ fprintf(stderr, "Boolean didn't have AT_APPL type.\n"); exit(1); } writeBool(writer, (ATermAppl) value); break; case PDB_INTEGER_TYPE_HEADER: if(ATgetType(value) != AT_INT){ fprintf(stderr, "Integer didn't have AT_INT type.\n"); exit(1); } writeInteger(writer, (ATermInt) value); break; case PDB_DOUBLE_TYPE_HEADER: if(ATgetType(value) != AT_REAL){ fprintf(stderr, "Double didn't have AT_REAL type.\n"); exit(1); } writeDouble(writer, (ATermReal) value); break; case PDB_STRING_TYPE_HEADER: if(ATgetType(value) != AT_APPL || ATisQuoted(ATgetAFun((ATermAppl) value)) == ATfalse){ fprintf(stderr, "String didn't have 'quoted' AT_APPL type.\n"); ATabort(""); exit(1); } writeString(writer, (ATermAppl) value); break; case PDB_SOURCE_LOCATION_TYPE_HEADER: if(ATgetType(value) != AT_APPL){ fprintf(stderr, "Source location didn't have AT_APPL type.\n"); exit(1); } writeSourceLocation(writer, (ATermAppl) value); break; case PDB_NODE_TYPE_HEADER: if(ATgetType(value) != AT_APPL){ fprintf(stderr, "Node didn't have AT_APPL type.\n"); exit(1); } { ATermList annotations = (ATermList) ATgetAnnotations(value); if(annotations == NULL){ writeNode(writer, expected, (ATermAppl) value); }else{ if(((A2PNodeType) expected->theType)->declaredAnnotations == NULL){ fprintf(stderr, "Node term has annotations, but none are declared.\n"); exit(1); } writeAnnotatedNode(writer, expected, (ATermAppl) value, annotations); } } break; case PDB_TUPLE_TYPE_HEADER: if(ATgetType(value) != AT_APPL){ fprintf(stderr, "Tuple didn't have AT_APPL type.\n"); exit(1); } writeTuple(writer, expected, (ATermAppl) value); break; case PDB_LIST_TYPE_HEADER: if(ATgetType(value) != AT_LIST){ fprintf(stderr, "List didn't have AT_LIST type.\n"); exit(1); } writeList(writer, expected, (ATermList) value); break; case PDB_SET_TYPE_HEADER: if(ATgetType(value) != AT_LIST){ fprintf(stderr, "Set didn't have AT_LIST type.\n"); exit(1); } writeSet(writer, expected, (ATermList) value); break; case PDB_RELATION_TYPE_HEADER: if(ATgetType(value) != AT_LIST){ fprintf(stderr, "Relation didn't have AT_LIST type.\n"); exit(1); } writeRelation(writer, expected, (ATermList) value); break; case PDB_MAP_TYPE_HEADER: if(ATgetType(value) != AT_LIST){ fprintf(stderr, "Map didn't have AT_LIST type.\n"); exit(1); } writeMap(writer, expected, (ATermList) value); break; case PDB_CONSTRUCTOR_TYPE_HEADER: if(ATgetType(value) != AT_APPL){ fprintf(stderr, "Constructor didn't have AT_APPL type.\n"); exit(1); } { ATermList annotations = (ATermList) ATgetAnnotations(value); if(annotations == NULL){ writeConstructor(writer, expected, (ATermAppl) value); }else{ if(((A2PConstructorType) expected->theType)->declaredAnnotations == NULL){ fprintf(stderr, "Constructor term has annotations, but none are declared.\n"); exit(1); } writeAnnotatedConstructor(writer, expected, (ATermAppl) value, annotations); } } break; case PDB_ADT_TYPE_HEADER: writeADT(writer, expected, value); break; default: fprintf(stderr, "Unserializable type: %d\n.", expected->id); exit(1); } DKISstore(sharedValues, (void*) value, (void*) expected, valueHash); }
hash_type ArbitraryNativeConstantForString::hash() { return hashValue(mValue); }