-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
finished the requirements for project 2.0 implemented a bloom filter for user occurrence, a tree for a recursive sort. A recursive function ( the war loop) .
- Loading branch information
Showing
46 changed files
with
2,630 additions
and
347 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file modified
BIN
+0 Bytes
(100%)
cis17cLabBloomFilter1.1/dist/Debug/Cygwin-Windows/cis17clabbloomfilter1.1
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+0 Bytes
(100%)
cis17cProject1.5/dist/Debug/Cygwin-Windows/cis17cproject1.5
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* File: BloomFilter.cpp | ||
* Author: Jason | ||
* | ||
* Created on May 31, 2021, 6:43 PM | ||
*/ | ||
#include "BloomFilter.h" | ||
/******************************************************************************\ | ||
bloomFilterPush | ||
\******************************************************************************/ | ||
bool BloomFilter::bfSearch(string s) | ||
{ | ||
return (bitarray[ELFHash(s) % BFarrSize] && bitarray[APHash(s) % BFarrSize]); | ||
} | ||
|
||
/******************************************************************************\ | ||
bloomFilterPush | ||
\******************************************************************************/ | ||
void BloomFilter::bfPush(string s) | ||
{ | ||
bitarray[ELFHash(s) % BFarrSize] = true; | ||
bitarray[APHash(s) % BFarrSize] = true; | ||
} | ||
|
||
unsigned int BloomFilter::ELFHash(const std::string& str) | ||
{ | ||
unsigned int hash = 0; | ||
unsigned int x = 0; | ||
|
||
for (std::size_t i = 0; i < str.length(); i++) | ||
{ | ||
hash = (hash << 4) + str[i]; | ||
if ((x = hash & 0xF0000000L) != 0) | ||
{ | ||
hash ^= (x >> 24); | ||
} | ||
hash &= ~x; | ||
} | ||
|
||
return hash; | ||
} | ||
|
||
unsigned int BloomFilter::APHash(const std::string& str) | ||
{ | ||
unsigned int hash = 0xAAAAAAAA; | ||
|
||
for (std::size_t i = 0; i < str.length(); i++) | ||
{ | ||
hash ^= ((i & 1) == 0) ? ((hash << 7) ^ str[i] * (hash >> 3)) : | ||
(~((hash << 11) + (str[i] ^ (hash >> 5)))); | ||
} | ||
|
||
return hash; | ||
} | ||
|
||
void BloomFilter::getBloomData() | ||
{ | ||
ifstream file ("bloomFilter.bin", ios::binary|ios::in); | ||
file.read(reinterpret_cast<char *>(bitarray), sizeof(bool) * BFarrSize); | ||
file.close(); | ||
} | ||
|
||
void BloomFilter::pushBloomData() | ||
{ | ||
ofstream file ("bloomFilter.bin", ios::binary|ios::out); | ||
file.write(reinterpret_cast<char *>(bitarray), sizeof(bool) * BFarrSize); | ||
file.close(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* File: BloomFilter.h | ||
* Author: Jason | ||
* | ||
* Created on May 31, 2021, 6:42 PM | ||
*/ | ||
|
||
|
||
#ifndef BLOOMFILTER_H | ||
#define BLOOMFILTER_H | ||
#include "Game.h" | ||
|
||
|
||
/******************************************************************************\ | ||
BloomFilter Class | ||
This Class will check to see if a player has played the game before by | ||
storing all usernames in a bloom filter bit vector. If the user has played | ||
a welcome back will be displayed. If the user has not played the rules | ||
menu option will be encouraged | ||
\******************************************************************************/ | ||
#define BFarrSize 512 | ||
|
||
class BloomFilter | ||
{ | ||
|
||
private: | ||
bool *bitarray; | ||
void getBloomData();//reads the bloom filter form text file | ||
void pushBloomData();//pushes bloom data to the file | ||
|
||
public: | ||
BloomFilter(); | ||
~BloomFilter(); | ||
void setBFname(string s); | ||
// search the bloom filter for user case | ||
bool bfSearch(string s); | ||
// set the bloom filter in the event there is a new user case | ||
void bfPush(string s); | ||
unsigned int ELFHash(const std::string& str); | ||
unsigned int APHash(const std::string& str); | ||
}; | ||
|
||
inline BloomFilter::BloomFilter() | ||
{ | ||
bitarray = new bool[BFarrSize]; | ||
for (int i = 0; i < BFarrSize; i++) | ||
bitarray[i] = false; | ||
getBloomData(); | ||
} | ||
inline BloomFilter::~BloomFilter() | ||
{ | ||
pushBloomData(); | ||
delete[] bitarray; | ||
} | ||
|
||
#endif /* BLOOMFILTER_H */ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.