ResID ApexResourceProvider::NameSpace::getOrCreateID(const char* &name, const char* NSName) { /* Hash Table Entry: | nextEntry* | ResID | name | */ uint16_t h = genHash(name); const char* entry = hash[h]; while (entry) { entryHeader* hdr = (entryHeader*) entry; const char* entryName = entry + sizeof(entryHeader); if (mArp->stringsMatch(name, entryName)) { name = entryName; return hdr->id; } entry = hdr->nextEntry; } size_t len = strlen(name); size_t bufsize = len + 1 + sizeof(entryHeader); char* newEntry = (char*) PX_ALLOC(bufsize, PX_DEBUG_EXP("ApexResourceProvider::NameSpace::getOrCreateID")); if (newEntry) { #if defined(WIN32) strncpy_s(newEntry + sizeof(entryHeader), bufsize - sizeof(entryHeader), name, len); #else strcpy(newEntry + sizeof(entryHeader), name); #endif entryHeader* hdr = (entryHeader*) newEntry; hdr->nextEntry = hash[h]; hdr->id = mArp->mResources.size(); resource res; res.ptr = (void*) UnknownValue; res.valueIsSet = false; res.name = newEntry + sizeof(entryHeader); res.nameSpace = NSName; res.refCount = 0; res.usedGetResource = 0; mArp->mResources.pushBack(res); hash[h] = (const char*) newEntry; name = res.name; return hdr->id; } return INVALID_RESOURCE_ID; }
vec_ZZ Decryer::genUserVec(){ vec_ZZ userVec(2*_groupSize); for (int i =0; i < 2 * _groupSize; i++){ if(_secret.first == i){ userVec[i] = 1; } else if(0 <= i && i <= _groupSize){ userVec[i] = 0; } else { userVec[i] = genHash(_secret.second, _ranSysVar[i - _groupSize]); } } return userVec; }
int jpegHashFromBuffer(unsigned char *imageBuf, long bufSize, unsigned char **hash, int size) { unsigned char *image; unsigned long imageSize = 0; unsigned char *scaled; int width, height; imageSize = decodeFileFromBuffer(imageBuf, bufSize, &image, FILETYPE_JPEG, &width, &height, JCS_GRAYSCALE); if (!imageSize) return 1; scale(image, width, height, &scaled, size, size); free(image); genHash(scaled, size, size, hash); free(scaled); return 0; }
void dir_read(const char dir[]) { struct direct **files; long nfiles, x; int dir_filter(const struct direct *entry); char path[500]; char fnames[500]; // //FILE *doc_dic; // nfiles = scandir(dir, &files, dir_filter, alphasort); for(x=0;x<nfiles;x++) { if( files[x]->d_type == DT_DIR ) { strcpy(path,"\0"); strcpy(path,dir); strcat(path,"/"); strcat(path,files[x]->d_name); dir_read(path); } } if(nfiles <= 0); //return 0; for(x=0;x<nfiles;x++) if(files[x]->d_type != DT_DIR) { strcpy(fnames,"\0"); sprintf(fnames,"%s/%s", dir, files[x]->d_name); strcat(fnames,"\0"); //printf("\nIndexing File : %s",fnames); //////////////Doc Dic start /* doc_dic = fopen("../bin/docdic","ab+"); doc_dictionay *dd_node = (doc_dictionay *)malloc(sizeof(doc_dictionay)); dd_node->docID = ++doc_count; strcpy(dd_node->path,fnames); dd_node->path[strlen(dd_node->path)]='\0'; fwrite(dd_node,sizeof(doc_dictionay),1,doc_dic); fclose(doc_dic); free(dd_node); */ //Doc Dic ++doc_count; g_idocid = doc_count; //v2.1 strcpy(g_ifile,"\0");//Remove previous contents strcpy(g_ifile,fnames); //copying current indexing file to global variable g_ifile g_ifile[strlen(g_ifile)]='\0'; //printf("Indexing File gfile name %s\n",g_ifile); //End of v2.1 /* */ fflush(stdin); do_stem(fnames);// stemmed o/p will be in ../bin/stemop genHash("../bin/stemop"); //For every File read Start building Tree //Write Doc_Dic doc_dictionay *dd_node = (doc_dictionay *)malloc(sizeof(doc_dictionay)); dd_node->docID = doc_count; dd_node->doc_len = doc_len; strcpy(dd_node->path,fnames); dd_node->path[strlen(dd_node->path)]='\0'; dd_node->next = NULL; if(doc_dic_root) { doc_dic_last->next = dd_node; doc_dic_last = dd_node; } else { doc_dic_root = dd_node; doc_dic_last = doc_dic_root; } // avg_doc_len = (double) ( (( avg_doc_len*(doc_count-1) ) + doc_len )/doc_count); } }