Esempio n. 1
0
/*Main function that reads in every transaction*/
void readTransactions(FILE* f, int numCustomers, int numTransactions){
	HashRef h = createHashSet();
	int custNum, wantPrint;
	int count =0;
	long bookId;
	ListRef customers[numCustomers];
	for(int i=0; i<numCustomers+1; i++)
		customers[i] = newList();
	while(count < numTransactions){
		++count;
		fscanf(f, "%d", &custNum);
		fscanf(f, "%lu", &bookId);
		fscanf(f, "%d", &wantPrint);
	if(hasBook(customers[custNum],bookId)){		//customer already bought book
	//	checkPurchased(customers, custNum, bookId);
		insertionSort(customers[custNum], bookId);
	}
	else{
		addCopurchase(h, bookId, customers, custNum);
		insertionSort(customers[custNum], bookId);
		}
		
	if(wantPrint){
		printRecommendation(h, bookId, customers, custNum);
	}
	
	}
	//debugHash(h);//uncomment me to see the hash status
	destroy(h);
	for(int i=0; i<numCustomers+1; i++){
		makeEmpty(customers[i]);
		freeList(customers[i]);
	}
}
Esempio n. 2
0
struct HashSet *resizeHashset(struct HashSet *hashset, int newSize)
{
	struct HashSet *newHashSet;
	struct ListNode *current;
	int bucketNumber;

	newHashSet = createHashSet(newSize, hashset->hashFunc);

	for (bucketNumber = 0; bucketNumber < hashset->numberBuckets;
		bucketNumber++) {
		current = hashset->buckets[bucketNumber]->start;
		while (current != NULL) {
			addElementToHashset(newHashSet, current->word);
			current = current->next;
		}
	}

	deleteHashSet(hashset);
	return newHashSet;
}