Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change uint to unsigned int #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions include/MyBloom.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
#include <bitset>
#include "bitArray.h"

std::vector<uint> myhash(std::string key, int len, int k, int r, int range);
std::vector<unsigned int> myhash(std::string key, int len, int k, int r, int range);

class BloomFiler{
public:
// BloomFiler(int capacity, float FPR, int k);
BloomFiler(int sz, float FPR, int k);
void insert(std::vector<uint> a);
bool test(std::vector<uint> a);
void insert(std::vector<unsigned int> a);
bool test(std::vector<unsigned int> a);
void serializeBF(std::string BF_file);
void deserializeBF(std::vector<std::string> BF_file);

Expand Down
4 changes: 2 additions & 2 deletions include/Rambo_construction.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
#include "bitArray.h"


// vector<uint> hashfunc( void* key, int len, int R, int B){
// vector<unsigned int> hashfunc( void* key, int len, int R, int B){
// }

class RAMBO{
public:

RAMBO(int n, int r1, int b1, int K);
std::vector<uint> hashfunc( std::string key, int len);
std::vector<unsigned int> hashfunc( std::string key, int len);
void insertion (std::string setID, std::vector<std::string> keys);
std::set<int> takeunion(std::set<int> set1, std::set<int> set2);
std::set<int> takeIntrsec(std::set<int>* setArray);
Expand Down
6 changes: 3 additions & 3 deletions include/bitArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ class bitArray{
// friend class boost::serialization::access;

bitArray(int size);
void SetBit(uint k);
void ClearBit( uint k);
bool TestBit( uint k);
void SetBit(unsigned int k);
void ClearBit( unsigned int k);
bool TestBit( unsigned int k);
void ANDop(char* B);
void serializeBitAr(std::string BF_file);
void deserializeBitAr(std::vector<std::string> BF_file);
Expand Down
10 changes: 5 additions & 5 deletions src/MyBloom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

using namespace std;

vector<uint> myhash( std::string key, int len, int k, int r, int range){
vector<unsigned int> myhash( std::string key, int len, int k, int r, int range){
// int hashvals[k];
vector <uint> hashvals;
uint op; // takes 4 byte
vector <unsigned int> hashvals;
unsigned int op; // takes 4 byte

for (int i=0+ k*r; i<k+ k*r; i++){
MurmurHash3_x86_32(key.c_str(), len, i, &op);
Expand All @@ -29,14 +29,14 @@ BloomFiler::BloomFiler(int sz, float FPR, int k){
m_bits = new bitArray(sz);
}

void BloomFiler::insert(vector<uint> a){
void BloomFiler::insert(vector<unsigned int> a){
int N = a.size();
for (int n =0 ; n<N; n++){
m_bits->SetBit(a[n]);
}
}

bool BloomFiler::test(vector<uint> a){
bool BloomFiler::test(vector<unsigned int> a){
int N = a.size();
for (int n =0 ; n<N; n++){
if (!m_bits->TestBit(a[n])){
Expand Down
32 changes: 16 additions & 16 deletions src/Rambo_construction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@

using namespace std;

vector<uint> RAMBO:: hashfunc( std::string key, int len){
vector<unsigned int> RAMBO:: hashfunc( std::string key, int len){
// int hashvals[k];
vector <uint> hashvals;
uint op;
vector <unsigned int> hashvals;
unsigned int op;
for (int i=0; i<R; i++){
MurmurHash3_x86_32(key.c_str(), len, 10, &op); //seed i
hashvals.push_back(op%B);
Expand All @@ -43,7 +43,7 @@ std::vector <std::string> RAMBO:: getdata(string filenameSet){
stringstream is;
is<<line1;
if (line1[0]!= '>' && line1.size()>30 ){
for (uint idx =0; idx<line1.size()-31 +1; idx++){
for (unsigned int idx =0; idx<line1.size()-31 +1; idx++){
allKeys.push_back(line1.substr(idx, 31));
totKmerscnt++;
}
Expand Down Expand Up @@ -78,7 +78,7 @@ RAMBO::RAMBO(int n, int r1, int b1, int K){
// one time process- a preprocess step
void RAMBO::createMetaRambo(int K, bool verbose){
for(int i=0;i<K;i++){
vector<uint> hashvals = RAMBO::hashfunc(std::to_string(i), std::to_string(i).size()); // R hashvals, each with max value B
vector<unsigned int> hashvals = RAMBO::hashfunc(std::to_string(i), std::to_string(i).size()); // R hashvals, each with max value B
for(int r=0; r<R; r++){
metaRambo[hashvals[r] + B*r].push_back(i);
}
Expand All @@ -99,13 +99,13 @@ void RAMBO::createMetaRambo(int K, bool verbose){

// give set and keys in the set
void RAMBO::insertion (std::string setID, std::vector<std::string> keys){
vector<uint> hashvals = RAMBO::hashfunc(setID, setID.size()); // R hashvals
vector<unsigned int> hashvals = RAMBO::hashfunc(setID, setID.size()); // R hashvals

//make this loop parallel
#pragma omp parallel for
for(std::size_t i=0; i<keys.size(); ++i){
for(int r=0; r<R; r++){
vector<uint> temp = myhash(keys[i].c_str(), keys[i].size() , k,r, range);
vector<unsigned int> temp = myhash(keys[i].c_str(), keys[i].size() , k,r, range);
Rambo_array[hashvals[r] + B*r]->insert(temp);
}
}
Expand All @@ -120,10 +120,10 @@ void RAMBO::insertion2 (std::vector<string> alllines){
std::vector<string>KeySets = line2array(alllines[i], d);//sets for a key

std::vector<string>KeySet = line2array(KeySets[1], ',');
for (uint j = 0; j<KeySet.size(); j++){
vector<uint> hashvals = RAMBO::hashfunc(KeySet[j], KeySet[j].size()); // R hashvals
for (unsigned int j = 0; j<KeySet.size(); j++){
vector<unsigned int> hashvals = RAMBO::hashfunc(KeySet[j], KeySet[j].size()); // R hashvals
for(int r=0; r<R; r++){
vector<uint> temp = myhash(KeySets[0].c_str(), KeySets[0].size() , k, r, range);// i is the key
vector<unsigned int> temp = myhash(KeySets[0].c_str(), KeySets[0].size() , k, r, range);// i is the key
Rambo_array[hashvals[r] + B*r]->insert(temp);
}
}
Expand All @@ -132,7 +132,7 @@ void RAMBO::insertion2 (std::vector<string> alllines){

// // give set and keys in the set
// void RAMBO::insertionRare (std::string setID, std::vector<std::string> keys){
// vector<uint> hashvals = RAMBO::hashfunc(setID, setID.size()); // R hashvals
// vector<unsigned int> hashvals = RAMBO::hashfunc(setID, setID.size()); // R hashvals
//
// //make this loop parallel
// int skip =0;
Expand All @@ -141,7 +141,7 @@ void RAMBO::insertion2 (std::vector<string> alllines){
// bitArray MemVec = RAMBO::query(keys[i].c_str(), keys[i].size());
// if ( MemVec.getcount() <10 ){
// for(int r=0; r<R; r++){
// vector<uint> temp = myhash(keys[i].c_str(), keys[i].size() , k, r, range);
// vector<unsigned int> temp = myhash(keys[i].c_str(), keys[i].size() , k, r, range);
// Rambo_array[hashvals[r] + B*r]->insert(temp);
// }
// }
Expand All @@ -157,15 +157,15 @@ bitArray RAMBO::query (string query_key, int len){
// bitset<Ki> bitarray_K;
// set<int> res;
float count=0.0;
vector<uint> check;
vector<unsigned int> check;
for(int r=0; r<R; r++){
check = myhash(query_key, len , k, r,range); //hash values correspondign to the keys
bitArray bitarray_K1(Ki);
// bitset<Ki> bitarray_K1;
for(int b=0; b<B; b++){
if (Rambo_array[b + B*r]->test(check)){
chrono::time_point<chrono::high_resolution_clock> t5 = chrono::high_resolution_clock::now();
for (uint j=0; j<metaRambo[b + B*r].size(); j++){
for (unsigned int j=0; j<metaRambo[b + B*r].size(); j++){
bitarray_K1.SetBit(metaRambo[b + B*r][j]);
}
chrono::time_point<chrono::high_resolution_clock> t6 = chrono::high_resolution_clock::now();
Expand All @@ -179,7 +179,7 @@ bitArray RAMBO::query (string query_key, int len){
bitarray_K.ANDop(bitarray_K1.A);
}
}
vector<uint>().swap(check);
vector<unsigned int>().swap(check);
return bitarray_K;
}

Expand All @@ -196,7 +196,7 @@ void RAMBO::deserializeRAMBO(vector<string> dir){
for(int b=0; b<B; b++){
for(int r=0; r<R; r++){
vector<string> br;
for (uint j=0; j<dir.size(); j++){
for (unsigned int j=0; j<dir.size(); j++){
br.push_back(dir[j] + to_string(b) + "_" + to_string(r) + ".txt");
}
Rambo_array[b + B*r]->deserializeBF(br);
Expand Down
8 changes: 4 additions & 4 deletions src/bitArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ bitArray::bitArray(int size){
}
}

void bitArray::SetBit(uint k) {
void bitArray::SetBit(unsigned int k) {
A[(k/8)] |= (1 << (k%8));
}

void bitArray::ClearBit(uint k) {
void bitArray::ClearBit(unsigned int k) {
A[(k/8)] &= ~(1 << (k%8));
}

bool bitArray::TestBit(uint k) {
bool bitArray::TestBit(unsigned int k) {
return (A[(k/8)] & (1 << (k%8)));
}

Expand Down Expand Up @@ -55,7 +55,7 @@ void bitArray::serializeBitAr(string BF_file){
}

void bitArray::deserializeBitAr(std::vector<string> BF_file){
for(uint j =0; j<BF_file.size(); j++){
for(unsigned int j =0; j<BF_file.size(); j++){
char* C;
C = new char[ar_size/8 +1];
ifstream in(BF_file[j]);
Expand Down
4 changes: 2 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ if (insert == true){
int stpt;
stpt = 5;
//}
for (uint ss=0; ss<setIDs.size(); ss++){
for (unsigned int ss=0; ss<setIDs.size(); ss++){
stpCnt++;
char d = ',';
vector<std::string> setID = line2array(setIDs[ss], d);
Expand Down Expand Up @@ -111,7 +111,7 @@ if(test){
//std::vector<string> alllines = readlines("data/query.txt", 0);
std::vector<string> testKeys;
std::vector<int> gt_size;
for(uint i=0; i<alllines.size(); i++){
for(unsigned int i=0; i<alllines.size(); i++){
std::vector<string>KeySets = line2array(alllines[i], ';');//sets for a key
testKeys.push_back(KeySets[0]);
gt_size.push_back( line2array(KeySets[1], ',').size() );
Expand Down
8 changes: 4 additions & 4 deletions src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,14 @@ return s;

std::map<std::string, vector<int>> makeInvIndex(int n, vector<std::string> foldernames){
std::map<std::string, vector<int>> m;
for (uint f=0; f<foldernames.size(); f++){
for (unsigned int f=0; f<foldernames.size(); f++){
string foldername = foldernames[f];
for (int batch=0; batch<47; batch++){
string dataPath = foldername + to_string(batch)+ "_indexed.txt";
std::vector<string> setIDs = readlines(dataPath, 0);
cout<<setIDs[0]<<endl;

for (uint ss=0; ss<setIDs.size(); ss++){
for (unsigned int ss=0; ss<setIDs.size(); ss++){
char d = ',';
vector<std::string> setID = line2array(setIDs[ss], d);
string mainfile = foldername + setID[1]+ ".out";
Expand All @@ -172,7 +172,7 @@ std::map<std::string, vector<int>> makeInvIndex(int n, vector<std::string> folde
}
else{

for (uint i =0; i<keys.size(); i++){
for (unsigned int i =0; i<keys.size(); i++){
if (m.find(keys[i]) != m.end()){
std::cout << "map contains the key!\n";
m[keys[i]].push_back(std::stoi(setID[0]));
Expand All @@ -188,7 +188,7 @@ std::map<std::string, vector<int>> makeInvIndex(int n, vector<std::string> folde

std::vector<std::string> getkmers(std::string query_key, int kmersize){
std::vector<std::string> query_kmers;
for (uint idx =0; idx<query_key.size()-kmersize +1; idx++){
for (unsigned int idx =0; idx<query_key.size()-kmersize +1; idx++){
query_kmers.push_back(query_key.substr(idx, kmersize));
}
return query_kmers;
Expand Down