static int hashHash(const byte* data, word32 len, byte* hash, word32 algo, word32 hsize) { int ret = 0; #ifdef WOLFSSL_SMALL_STACK wolfssl_TI_Hash* hash_desc; #else wolfssl_TI_Hash hash_desc[1]; #endif #ifdef WOLFSSL_SMALL_STACK hash_desc = (wolfssl_TI_Hash*)XMALLOC(sizeof(wolfssl_TI_Hash), NULL, DYNAMIC_TYPE_TMP_BUFFER); if (hash_desc == NULL) return MEMORY_E; #endif if ((ret = hashInit(hash_desc)) != 0) { WOLFSSL_MSG("Hash Init failed"); } else { hashUpdate(hash_desc, data, len); hashFinal(hash_desc, hash, algo, hsize); } #ifdef WOLFSSL_SMALL_STACK XFREE(hash_desc, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return ret; }
static int hashFinal(wolfssl_TI_Hash *hash, byte* result, word32 algo, word32 hsize) { hashGetHash(hash, result, algo, hsize) ; XFREE(hash->msg, NULL, DYNAMIC_TYPE_TMP_BUFFER); hashInit(hash) ; return 0 ; }
int main() { int n,i,j; scanf("%d%d", &n, &k); hashInit(); scanf("%d", A+1); amax=(amin=A[1]); for(i=2; i<=n; i++) { scanf("%d", A+i); if(A[i]>amax) amax=A[i]; if(A[i]<amin) amin=A[i]; } for(j=1; j<k; j++) hashInsert(A[j]); for(i=1; j<n; i++, j++) { hashInsert(A[j]); A[i-1]=findMax(); printf("%d ",findMin()); hashDelete(A[i]); } hashInsert(A[j]); A[i-1]=findMax(); printf("%d\n",findMin()); for(i=0; i<n-k; i++) printf("%d ",A[i]); printf("%d\n",A[i]); scanf("%d", A); return 0; }
//-------------------------------------------------------------------------- // Main global function //-------------------------------------------------------------------------- int main() { std::hash_map<char*, char*>::iterator ihashMap; hashInit(); vservManagerInit(hashMap); if(hashMap.size() > 1) { ihashMap = hashMap.find("ShowAt"); if(ihashMap->second == "start" || ihashMap->second == "both"){ vservManagerFetchingAdData(); } else{ HelloWorldMain(); } } return 0; }
int cds_openDataStore(char *database) { if(cdsInfo.state != CDS_CLOSED) { LOG_ERROR("CDS already open. \n"); return CDS_ALREADYOPEN; } //adding .sch extension char *temp=(char *)malloc(sizeof(char)*(strlen(database)+5)); strcpy(temp,database); strcat(temp,".sch"); cdsInfo.database=(char*)malloc(sizeof(char)*(strlen(database)+1)); strcpy(cdsInfo.database,database); FILE *scf;//schema file scf=fopen(temp,"rb"); if(scf==NULL) return OPENCDS_FAIL; cdsInfo.freelist=(struct stack *)malloc(sizeof(struct stack)); //reading .sch file line by line and storing it in buffer char *line = (char *)malloc(sizeof(char)*80); int i=0; FILE *pndx,*sndx,*fp;//pointers to hold .ndx files //this loop parses .sch file and opens all ndx and dat files and also populates cdsInfo structure while( fgets(line,80,scf) != NULL ) { char *temp=strTok(line,":"); //Colname char *size=strTok(NULL,":"); //size of the field char *datatype=strTok(NULL,":"); //string char *last=strTok(NULL,":"); if(temp!=NULL && size!=NULL && datatype!=NULL && last==NULL) { cdsInfo.fileregister[i].colname=(char*)malloc(sizeof(char)*strlen(temp)); strcpy(cdsInfo.fileregister[i].colname,temp); strcat(cdsInfo.fileregister[i].colname,"\0"); cdsInfo.fileregister[i].type = TYPE_STRING; cdsInfo.fileregister[i].length=atoi(size); char *fieldname = convert_to_filename(database,temp,".dat"); fp=fopen(fieldname,"rb+"); if(fp==NULL) { LOG_ERROR(".dat file not getting created \n"); return OPENCDS_FAIL; } cdsInfo.fileregister[i].fptr=fp; if(i==0) { char *indexfilename=convert_to_filename(database,temp,".ndx"); pndx=fopen(indexfilename,"rb"); if(pndx==NULL) { LOG_ERROR("Cannot open primary .ndx file.\n"); return OPENCDS_FAIL; } } if(i==1) { char *indexfilename=convert_to_filename(database,temp,".ndx"); sndx=fopen(indexfilename,"rb"); if(sndx==NULL) { LOG_ERROR("Cannot open secondary .ndx file.\n"); return OPENCDS_FAIL; } } } i++; } cdsInfo.numCols=i; //Populating freelist variable of cdsInfo and loading it cdsInfo.freelist=(struct stack *)malloc(sizeof(struct stack)); stackInit(cdsInfo.freelist); LOG_INFO("Initialized free list\n"); if(stackLoadFromFile(pndx, cdsInfo.freelist)==STACK_FAIL) { LOG_ERROR("Didn't load stack from primary .ndx file\n"); return OPENCDS_FAIL; } LOG_INFO("Loaded stack with freelist from primary .ndx file \n"); cdsInfo.primaryNdx = bstLoadFromFile(pndx); LOG_INFO("\nLoaded BST from primary .ndx file\n"); cdsInfo.secondaryNdx=(struct hashTable*)malloc(sizeof(struct hashTable)); hashInit(cdsInfo.secondaryNdx,0);//Initializing hashtable if(hashLoadFromFile(sndx,cdsInfo.secondaryNdx)==HASH_FAIL) { LOG_ERROR("Didn't load hash table from secondary .ndx file\n"); return OPENCDS_FAIL;//hashLoad Failed } LOG_INFO("\nLoaded Hash Table from secondary .ndx file\n"); //closing ndx files fclose(pndx); fclose(sndx); //closing schema file fclose(scf); LOG_INFO("CDS open!"); cdsInfo.state = CDS_OPEN_RW; // else set state to open for(i=0;i<cdsInfo.numCols;i++) printf("%s\n",cdsInfo.fileregister[i].colname); free(temp); return OPENCDS_SUCCESS; }
WOLFSSL_API int wc_InitSha256(Sha256* sha256) { if (sha256 == NULL) return 1 ; return hashInit((wolfssl_TI_Hash *)sha256) ; }
WOLFSSL_API int wc_InitSha224(Sha224* sha224) { if (sha224 == NULL) return 1 ; return hashInit((wolfssl_TI_Hash *)sha224) ; }
WOLFSSL_API int wc_InitSha(Sha* sha) { if (sha == NULL) return 1 ; return hashInit((wolfssl_TI_Hash *)sha) ; }
WOLFSSL_API void wc_InitMd5(Md5* md5) { if (md5 == NULL) return ; hashInit((wolfssl_TI_Hash *)md5) ; }
static int hashFree(wolfssl_TI_Hash *hash) { XFREE(hash->msg, NULL, DYNAMIC_TYPE_TMP_BUFFER); hashInit(hash) ; return 0 ; }
//common parser method. //This function takes the file name and get the data as stream. Hash* parseFileDataStream(const char *fname) { Hash *mp=(Hash *)malloc(sizeof(Hash)*N); hashInit(mp); int k=0,tempIdx=0,nOctact=0,len=0; char temp[4],temp1[4],charcter[4]; char a[4],b[4],c[4],d[4]; char ch,prvChar='\0'; FILE *fptr=fopen(fname, "r"); if(!fptr){ perror("falied to open the file.."); return NULL; } a[0]=b[0]=c[0]=d[0]='\0'; while (( fscanf(fptr,"%c",&ch) ) != EOF) { if(ch!='.'){ len++; temp[(len-1)%3]=ch; if(len<4) temp1[len-1]=ch; if(len>3) { tempIdx=(len-1)%3; } } else if(prvChar=='.'&&ch=='.') { len=0; nOctact=0; } else { nOctact++; temp1[3]='\0'; if(len<=3) tempIdx=0; else tempIdx=(tempIdx+1)%3; int i=tempIdx,j; j=0; do{ charcter[j]=temp[i]; j++; if(len>3) i=(i+1)%3; else i=(i+1)%len; }while(i!=tempIdx); if(len>3) charcter[3]='\0'; else charcter[len]='\0'; switch(nOctact) { case 1: strCopy(a,charcter,0,strlen(charcter)-1); break; case 2: strCopy(b,charcter,0,strlen(charcter)-1); break; case 3: strCopy(c,charcter,0,strlen(charcter)-1); break; case 4: if(len>3) k=3; else k=len; strCopy(d,temp1,0,k-1); generateComb(a,d,b,c,mp); } if(len>3) { nOctact=1; strCopy(a,charcter,0,strlen(charcter)-1); } else if(nOctact==4) { nOctact=3; strCopy(a,b,0,strlen(b)-1); strCopy(b,c,0,strlen(c)-1); strCopy(c,d,0,strlen(d)-1); } len=0; } prvChar=ch; } if(nOctact==3) { if(len>3) k=3; else k=len; strCopy(d,temp1,0,k-1); generateComb(a,d,b,c,mp); } fclose(fptr); return mp; }