void rmFromFinf(char *listFile, char *oldFinf, char *newFinf) /* rmFromFinf - Remove clones in list from finf file. */ { struct hash *rmHash = hashList(listFile); struct lineFile *lf = lineFileOpen(oldFinf, TRUE); FILE *f = mustOpen(newFinf, "w"); char *row[7]; int i; char clone[256]; while (lineFileRow(lf, row)) { strcpy(clone, row[0]); chopSuffix(clone); if (!hashLookup(rmHash, clone)) { for (i=0; i<ArraySize(row); ++i) { fprintf(f, "%s", row[i]); if (i == ArraySize(row)-1) fputc('\n', f); else fputc('\t', f); } } else printf("Skipping %s\n", clone); } }
void PolicyOr::Execute(class Tpm2& tpm, PolicyTree& p) { // Calculate the or-chain digests TPM_ALG_ID hashAlg = p.Session->GetHashAlg(); vector<TPM2B_DIGEST> hashList(Branches.size()); for (size_t j = 0; j < Branches.size(); j++) { hashList[j].buffer = PolicyTree::GetPolicyDigest(Branches[j], hashAlg).digest; } tpm.PolicyOR(*p.Session, hashList); }
struct slName *subtractLists(struct slName *listA, struct slName *listB) /* Subtract two lists. */ { struct hash *theHash = hashList(listB); struct slName *diffList = NULL, *cur; for (cur = listA; cur != NULL; cur = cur->next) { if (hashLookup(theHash, cur->name) == NULL) slNameAddHead(&diffList, cur->name); } freeHashAndVals(&theHash); slReverse(&diffList); return diffList; }
struct slName *intersectFiles(struct slName *fileList) /* Successively intersect files. */ { struct slName *isectList = slNameLoadReal(fileList->name); struct slName *curFile = fileList->next; struct slName *cur; while (curFile != NULL) { struct hash *isectHash = hashList(isectList); struct slName *someWords = slNameLoadReal(curFile->name); struct slName *bothWords = thoseInHash(isectHash, someWords, FALSE); slNameFreeList(&someWords); slNameFreeList(&isectList); isectList = bothWords; freeHashAndVals(&isectHash); curFile = curFile->next; } return isectList; }
struct slName *unionFiles(struct slName *fileList) /* Successively union files. */ { struct slName *initialList = slNameLoadReal(fileList->name); struct hash *theHash = hashList(initialList); struct slName *nextFile = fileList->next; struct slName *unionList = NULL; struct slName *cur; while (nextFile != NULL) { struct slName *someWords = slNameLoadReal(nextFile->name); addMoreToHash(theHash, someWords); slNameFreeList(&someWords); nextFile = nextFile->next; } unionList = hashToList(theHash); hashFree(&theHash); slNameFreeList(&initialList); return unionList; }
int main() { printf("Hello\n"); printf("Enter a command followed by a number between 0 and 999 inclusive to perform operation on hash table\n"); printf("Valid commands are: insert #, delete #, search #, list #.\n"); printf("Enter searchlist to print entire table\n"); printf("Enter term to print table and exit .\n"); Hashtable * newTable = makeTable(10); char * regex = " \n"; char str [100]; while(1) { printf("Enter: "); char * result = fgets(str, 100, stdin); char * token1 = strtok(result, regex); char * token2 = strtok(NULL, regex); long long val; if(token2 != NULL) { char * end_ptr = 0; val = strtoll(token2,&end_ptr,10); if((end_ptr != 0 && *end_ptr != '\n' && *end_ptr != '\0') || overflow(val)){ printf("Error: invalid input. %s is outside valid range (0 - 999)\n", token2); continue; } } if(token1 == NULL) { printf("Error: invalid input. \n"); continue; } else if(strcasecmp(token1,"searchlist") == 0) { hashListFull(newTable); } else if(strcasecmp(token1, "term") == 0) { hashListFull(newTable); term(newTable); printf("You've been terminated\n"); break; } else if(strcasecmp(token1,"insert") == 0) { if(token2 == NULL) { printf("Error: No number listed\n"); continue; } if(hashInsert(val,newTable)) { printf("True \n"); } else { printf("False \n"); } }else if(strcasecmp(token1,"search") == 0) { if(token2 == NULL) { printf("Error: No number listed\n"); continue; } if(search(val,newTable)) { printf("True\n"); } else { printf("False\n"); } }else if(strcasecmp(token1,"delete") == 0){ if(token2 == NULL) { printf("Error: No number listed\n"); continue; } if(hashDelete(val,newTable)) { printf("True \n"); } else { printf("False\n"); } }else if(strcasecmp(token1, "list") == 0) { if(token2 == NULL) { printf("Error: No index listed\n"); continue; } if(isNull(hash(val),newTable)) { printf("False\n"); }else { printf("List #%i :", hash(val)); hashList(hash(val),newTable); printf("\n"); } }else{ printf("Error: invalid input. %s is not recognized keyword: insert, search,list,delete\n", token1); continue; } } return 0; }