void Dictionary::SetAt(const ieResRef key, unsigned int type, unsigned int value) { int i; unsigned int nHash; MyAssoc* pAssoc=GetAssocAt( key, type, nHash ); if (pAssoc == NULL) { if (m_pHashTable == NULL) InitHashTable( m_nHashTableSize ); // it doesn't exist, add a new Association pAssoc = NewAssoc(); // put into hash table pAssoc->pNext = m_pHashTable[nHash]; m_pHashTable[nHash] = pAssoc; } for(i=0;i<KEYSIZE && key[i];i++) { pAssoc->key[i]=tolower(key[i]); } for(;i<KEYSIZE;i++) { pAssoc->key[i]=0; } pAssoc->type = type; pAssoc->value = value; }
void* CFX_MapPtrToPtr::GetValueAt(void* key) const { FX_DWORD nHash; CAssoc* pAssoc = GetAssocAt(key, nHash); if (pAssoc == NULL) { return NULL; } return pAssoc->value; }
bool CFX_MapPtrToPtr::Lookup(void* key, void*& rValue) const { uint32_t nHash; CAssoc* pAssoc = GetAssocAt(key, nHash); if (!pAssoc) { return false; } rValue = pAssoc->value; return true; }
FX_BOOL CFX_MapPtrToPtr::Lookup(void* key, void*& rValue) const { FX_DWORD nHash; CAssoc* pAssoc = GetAssocAt(key, nHash); if (pAssoc == NULL) { return FALSE; } rValue = pAssoc->value; return TRUE; }
void Dictionary::RemoveAt(const ieResRef key, unsigned int type) { unsigned int nHash; MyAssoc* pAssoc = GetAssocAt( key, type, nHash ); if (pAssoc != NULL) { FreeAssoc(pAssoc); } }
FX_BOOL CFX_MapPtrToPtr::Lookup(void* key, void*& rValue) const { uint32_t nHash; CAssoc* pAssoc = GetAssocAt(key, nHash); if (!pAssoc) { return FALSE; } rValue = pAssoc->value; return TRUE; }
LTBOOL CMapWordToPtr::Lookup(int32 key, void*& rValue) const { uint16 nHash; CAssoc* pAssoc = GetAssocAt(key, nHash); if (pAssoc == LTNULL) return LTFALSE; // not in map rValue = pAssoc->value; return LTTRUE; }
bool THashTable:: Lookup(char* key, int& rValue) const { UINT nHash; bool bHasBucket; TAssoc* pAssoc = GetAssocAt(key, nHash,bHasBucket); if (pAssoc == NULL) return false; // not in map rValue = pAssoc->fValue; return true; }
BOOL CMapPtrToPtr::Lookup(void* key, void*& rValue) const { ASSERT_VALID(this); UINT nHash; CAssoc* pAssoc = GetAssocAt(key, nHash); if (pAssoc == NULL) return FALSE; // not in map rValue = pAssoc->value; return TRUE; }
BOOL CMapWordToOb::Lookup(WORD key, CObject*& rValue) const { ASSERT_VALID(this); UINT nHash; CAssoc* pAssoc = GetAssocAt(key, nHash); if (pAssoc == NULL) return FALSE; // not in map rValue = pAssoc->value; return TRUE; }
BOOL CMapDWORDToChar::Lookup(DWORD key, char& rValue) const { ASSERT_VALID(this); UINT nHash; CAssoc* pAssoc = GetAssocAt(key, nHash); if (pAssoc == NULL) return FALSE; // not in map rValue = pAssoc->value; return TRUE; }
BOOL CMapStringToPtr::LookupKey(LPCTSTR key, LPCTSTR& rKey) const { ASSERT_VALID(this); UINT nHash; CAssoc* pAssoc = GetAssocAt(key, nHash); if (pAssoc == NULL) return FALSE; // not in map rKey = pAssoc->key; return TRUE; }
BOOL CMapStringToString::Lookup(LPCTSTR key, CString& rValue) const { ASSERT_VALID(this); UINT nHash; CAssoc* pAssoc = GetAssocAt(key, nHash); if (pAssoc == NULL) return FALSE; // not in map rValue = pAssoc->value; return TRUE; }
BOOL CMapStringToOb::Lookup(LPCTSTR key, CObject*& rValue) const { ASSERT_VALID(this); UINT nHashBucket, nHashValue; CAssoc* pAssoc = GetAssocAt(key, nHashBucket, nHashValue); if (pAssoc == NULL) return FALSE; // not in map rValue = pAssoc->value; return TRUE; }
BOOL CMapWordToPtr::Lookup(WORD key, void*& rValue) const { ASSERT_VALID(this); UINT nHashBucket, nHashValue; CAssoc* pAssoc = GetAssocAt(key, nHashBucket, nHashValue); if (pAssoc == NULL) return FALSE; // not in map rValue = pAssoc->value; return TRUE; }
bool Dictionary::Lookup(const ieResRef key, unsigned int type, unsigned int& rValue) const { unsigned int nHash; MyAssoc* pAssoc = GetAssocAt( key, type, nHash ); if (pAssoc == NULL) { return false; } // not in map rValue = pAssoc->value; return true; }
void THashTable:: SetAt(char* key, int value){ UINT nHash; TAssoc* pAssoc; TBucket* pBucket; bool bHasBucket; if ((pAssoc = GetAssocAt(key, nHash, bHasBucket)) == NULL) { if (bHasBucket == false) { // create a TBucket pBucket = new TBucket(BUCKET_SIZE); fBuckets[nHash] = pBucket; fBucketsUsed++; } pBucket = fBuckets[nHash]; pAssoc = new TAssoc(key,value); pBucket->insert(pAssoc); //if (pBucket->entries() > 1 ){ // fCollisions++; //} } }
char& CMapDWORDToChar::operator[](DWORD key) { ASSERT_VALID(this); UINT nHash; CAssoc* pAssoc; if ((pAssoc = GetAssocAt(key, nHash)) == NULL) { if (m_pHashTable == NULL) InitHashTable(m_nHashTableSize); // it doesn't exist, add a new Association pAssoc = NewAssoc(); pAssoc->nHashValue = nHash; pAssoc->key = key; // 'pAssoc->value' is a constructed object, nothing more // put into hash table pAssoc->pNext = m_pHashTable[nHash]; m_pHashTable[nHash] = pAssoc; } return pAssoc->value; // return new reference }
int& THashTable:: operator[](char* key){ UINT nHash; TAssoc* pAssoc; TBucket* pBucket; bool bHasBucket; if ((pAssoc = GetAssocAt(key, nHash, bHasBucket)) == NULL) { if (bHasBucket == false) { // create a TBucket pBucket = new TBucket(BUCKET_SIZE); fBuckets[nHash] = pBucket; fBucketsUsed++; } pBucket = fBuckets[nHash]; // dummy in value pAssoc = new TAssoc(key,0); pBucket->insert(pAssoc); //if (pBucket->entries() > 1 ){ // fCollisions++; //} } return pAssoc->fValue; // assigns value }
void* CFX_MapPtrToPtr::GetValueAt(void* key) const { uint32_t nHash; CAssoc* pAssoc = GetAssocAt(key, nHash); return pAssoc ? pAssoc->value : nullptr; }