treeNode* Delete(treeNode* root, string wrd) { treeNode* tmpCell; if(root == NULL) { cout << "Element not found" << endl; return NULL; } else if(DJBHash(wrd) < DJBHash(root->getWord())) // Go Left root->setLeft(Delete(root->getLeft(),wrd)); else if(DJBHash(wrd) > DJBHash(root->getWord())) // Go Right root->setRight(Delete(root->getRight(),wrd)); else if(root->getLeft() && root->getRight()) // Two children { tmpCell = FindMin(root->getRight()); root->setData(tmpCell->getWord(),tmpCell->getMeaning(),tmpCell->getDescription()); root->setRight(Delete(root->getRight(),wrd)); } else // one Child or zero { tmpCell = root; if(root->getLeft() == NULL) root = root->getRight(); else if(root->getRight() == NULL) root = root->getLeft(); delete tmpCell; } return root; }
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 int RHTable::RemoteHash( unsigned char *key, unsigned int size ) { mdk::mdk_assert(NULL != HashFunction); unsigned char hashKey[256]; unsigned int hashSize; HashFunction( hashKey, hashSize, key, size ); return DJBHash( hashKey, hashSize ); }
string_id cInternString::getId(TCHAR const* str) { string_id id = DJBHash(str, _tcslen(str)); if (!m_hash->is(id)) { m_hash->insert(id, str); } return id; }
void insert(treeNode* root, string wrd , string mng, string des) { unsigned int d = 0 ; treeNode* Newnode = new treeNode(wrd, mng, des); treeNode *p,*q; p = q = root; d = DJBHash(wrd); while(d != DJBHash(p->getWord()) && q != NULL) { p = q; if(d < DJBHash(p->getWord())) { q = p->getLeft(); } else { q = p->getRight(); } } if(d == DJBHash(p->getWord())) { cout << endl << "dublicate value :" << p->getWord() << endl; } else if(d < DJBHash(p->getWord())) { p->setLeft(Newnode); } else if(d > DJBHash(p->getWord())) { p->setRight(Newnode); } }
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 = DJBHash((char *)str, (unsigned int )tmp); hash = tmp___0; if (hash == 1235568949U) { printf((char const */* __restrict */)"The license key is correct!\n"); } else { printf((char const */* __restrict */)"The license key is incorrect!\n"); } return (0); } }
void insert_to_hashtable(struct node *n) { int key; struct node *node; //generate the hash key key = DJBHash(n->diskname); //get hash entry node = hash_table[key].p2node; if(node == NULL) { hash_table[key].p2node = n; } else { //go to tail while(node->next != NULL) { node = node->next; } //add new node to tail; node->next = n; } }
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; }
static unsigned int gen_dir_hash(const char *path) { char dir[PATH_MAX], *base; int len; strncpy(dir, path, sizeof(dir)); dir[sizeof(dir)-1] = '\0'; base = strrchr(dir, '/'); if( !base ) base = strrchr(dir, '\\'); if( base ) { *base = '\0'; len = base - dir; } else return 0; return DJBHash(dir, len); }
char * check_embedded_art(const char *path, const char *image_data, int image_size) { int width = 0, height = 0; char *art_path = NULL; char *cache_dir; FILE *dstfile; image_s *imsrc; static char last_path[PATH_MAX]; static unsigned int last_hash = 0; static int last_success = 0; unsigned int hash; if( !image_data || !image_size || !path ) { return NULL; } /* If the embedded image matches the embedded image from the last file we * checked, just make a hard link. Better than storing it on the disk twice. */ hash = DJBHash(image_data, image_size); if( hash == last_hash ) { if( !last_success ) return NULL; art_cache_exists(path, &art_path); if( link(last_path, art_path) == 0 ) { return(art_path); } else { if( errno == ENOENT ) { cache_dir = strdup(art_path); make_dir(dirname(cache_dir), S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH); free(cache_dir); if( link(last_path, art_path) == 0 ) return(art_path); } DPRINTF(E_WARN, L_METADATA, "Linking %s to %s failed [%s]\n", art_path, last_path, strerror(errno)); free(art_path); art_path = NULL; } } last_hash = hash; imsrc = image_new_from_jpeg(NULL, 0, image_data, image_size, 1, ROTATE_NONE); if( !imsrc ) { last_success = 0; return NULL; } width = imsrc->width; height = imsrc->height; if( width > 160 || height > 160 ) { art_path = save_resized_album_art(imsrc, path); } else if( width > 0 && height > 0 ) { size_t nwritten; if( art_cache_exists(path, &art_path) ) goto end_art; cache_dir = strdup(art_path); make_dir(dirname(cache_dir), S_IRWXU|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH); free(cache_dir); dstfile = fopen(art_path, "w"); if( !dstfile ) { free(art_path); art_path = NULL; goto end_art; } nwritten = fwrite((void *)image_data, 1, image_size, dstfile); fclose(dstfile); if( nwritten != image_size ) { DPRINTF(E_WARN, L_METADATA, "Embedded art error: wrote %d/%d bytes\n", nwritten, image_size); remove(art_path); free(art_path); art_path = NULL; goto end_art; } } end_art: image_free(imsrc); if( !art_path ) { DPRINTF(E_WARN, L_METADATA, "Invalid embedded album art in %s\n", basename((char *)path)); last_success = 0; return NULL; } DPRINTF(E_DEBUG, L_METADATA, "Found new embedded album art in %s\n", basename((char *)path)); last_success = 1; strcpy(last_path, art_path); return(art_path); }
int get_hash_entry(char* hash_key) { return DJBHash(hash_key); }
// Convolves a set of impulse responses into a single one. // // Parameters: // impulse_info the set of impulse responses // filter_length the convolution filter length // realsize the "float" size // // Returns the name of the processed file or empty on error. std::wstring convolve_impulses(std::vector<struct impulse_info> impulse_info, int filter_length, int realsize) { int n; int n_channels, g_channels = 0; int sampling_rate, g_sampling_rate = 0; int n_frames, g_frames = 0; int filter_blocks; int length; long hash_code = 0; std::vector<struct impulse_info>::iterator it; std::wstring fn_concat; std::wstringstream out; std::wstring m_out_filename; brutefir *filter; bool status; void **coeffs; void *inbuf; void *outbuf; // find the largest frame size for (it = impulse_info.begin(); it < impulse_info.end(); it++) { fn_concat.append(it->filename); buffer::get_snd_file_params(it->filename.c_str(), &n_channels, &n_frames, &sampling_rate); if (n_frames > g_frames) { g_frames = n_frames; } if ((g_channels != 0) && (g_channels != n_channels)) { throw; } if ((g_sampling_rate != 0) && (g_sampling_rate != sampling_rate)) { throw; } g_channels = n_channels; g_sampling_rate = sampling_rate; } // calculate filter blocks length = util::get_next_multiple(g_frames, filter_length); filter_blocks = length / filter_length; // assemble the output filename hash_code = DJBHash((char *)fn_concat.c_str(), fn_concat.size()); out << "file-" << std::hex << hash_code << "-" << std::dec << g_frames << "-" << realsize << "-" << g_channels << "-" << g_sampling_rate << ".wav"; m_out_filename = bfir_path::append_temp_path(out.str()); // run the impulse convolver if the output file does not already exist if (!boost::filesystem::exists(m_out_filename)) { // instantiate filter filter = new brutefir( filter_length, filter_blocks, realsize, g_channels, (realsize == 4) ? BF_SAMPLE_FORMAT_FLOAT_LE : BF_SAMPLE_FORMAT_FLOAT64_LE, (realsize == 4) ? BF_SAMPLE_FORMAT_FLOAT_LE : BF_SAMPLE_FORMAT_FLOAT64_LE, g_sampling_rate, false); // allocate the output buffer outbuf = _aligned_malloc(filter_length * filter_blocks * g_channels * realsize, ALIGNMENT); memset(outbuf, 0, filter_length * filter_blocks * g_channels * realsize); // use a dirac impulse response for the initial coefficients coeffs = coeff::load_dirac_coeff(g_channels, filter_length, realsize); filter->set_coeff(coeffs, g_channels, filter_length, filter_blocks, 1.0); for (it = impulse_info.begin(); it < impulse_info.end(); it++) { // load the sound file into the input buffer inbuf = buffer::load_from_snd_file(it->filename.c_str(), &n_channels, &n_frames, realsize, filter_length * filter_blocks, true); // break on error if ((inbuf == NULL) || (n_channels != g_channels)) { m_out_filename.clear(); break; } // run the filter status = true; for (n = 0; n < filter_blocks; n++) { status &= (filter->run(&(((uint8_t *)inbuf)[n * filter_length * g_channels * realsize]), &(((uint8_t *)outbuf)[n * filter_length * g_channels * realsize])) == 0); } // free coefficients if (coeffs != NULL) { for (n = 0; n < g_channels; n++) { if (coeffs[n] != NULL) { _aligned_free(coeffs[n]); coeffs[n] = NULL; } } _aligned_free(coeffs); coeffs = NULL; } // the output buffer becomes the coefficients for the next iteration if (status) { coeffs = buffer::deinterlace(outbuf, g_channels, filter_length * filter_blocks, realsize); filter->set_coeff(coeffs, g_channels, filter_length, filter_blocks, it->scale); } // free the input buffer if (inbuf != NULL) { _aligned_free(inbuf); inbuf = NULL; } // break on error if (!status) { m_out_filename.clear(); break; } } if (!m_out_filename.empty()) { // write the final output buffer to the output file buffer::save_to_snd_file(m_out_filename.c_str(), outbuf, g_channels, g_frames, realsize, g_sampling_rate); } // free the output buffer if (outbuf != NULL) { _aligned_free(outbuf); outbuf = NULL; } // free coefficients if (coeffs != NULL) { for (n = 0; n < g_channels; n++) { if (coeffs[n] != NULL) { _aligned_free(coeffs[n]); coeffs[n] = NULL; } } _aligned_free(coeffs); coeffs = NULL; } delete filter; } return m_out_filename; }
constexpr unsigned int f(void) { return DJBHash("01234567890123456"); }