Like Tree2Likes

solid tutorial suggestion

This is a discussion on solid tutorial suggestion within the C++ Programming forums, part of the General Programming Boards category; Alright, I am attempting to write a program that implements a bloom filter with a given set of hash functions ...

  1. #1
    Registered User
    Join Date
    Sep 2012
    Posts
    86

    solid tutorial suggestion

    Alright, I am attempting to write a program that implements a bloom filter with a given set of hash functions from an input file that give m p c a0 b0.....a(c-1) b(c-1).

    m = number of locations for bloom filter
    p = large primenumber for hash functions
    c = number of hash functions
    ai and bi = parameter of the equations for the ith term

    Also, we have to use string to integer mapping from the keys from a separate file.

    All the code I have found through search is not very similar or not well commented. Does anybody have any snippets, well documented links, or easy to locate reading material?

    Thanks in advance

  2. #2
    Registered User
    Join Date
    Sep 2012
    Posts
    86
    bump

  3. #3
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    1,008
    Read the wikipedia page and try something yourself?
    stahta01 and oogabooga like this.

  4. #4
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    I agree with mutant. Why are you looking for code? You should write your own code and ask questions about it here. The algorithm seems pretty simple and typing "bloom filter" into google gives plenty of good info.
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

  5. #5
    Registered User
    Join Date
    Sep 2012
    Posts
    86
    So this section of code is supposed to read in the file, read in the first line to get the values needs. Then read in the second line open it and store the strings into a vector I am getting:

    some error message
    - value - value - value
    some error message
    some error message

    Code:
    #include <iostream>
    #include <fstream>
    #include <sstream>
    #include <vector>
    #include <iterator>
    #include <string>
    using namespace std;
    int main(int argc, char * argv[]) {
     int i = 0;
     int m, c;// table size, number of hash functions
     int long p; //large prime number
     vector <int> vectorA;
     vector <int> vectorB;
     vector <string> vectorString;
     
     ifstream inFile (argv[1]);
     ifstream inFile2;
     string line;
     
     if (!getline(inFile,line)){   //checking for line 1
      cout << "Some error message"<< endl;
     }
     istringstream eqnparam (line);
      eqnparam>>m>>p>>c;
      cout << m << p << c << endl;
     for (i = 0; i < c; i++){
      eqnparam>>vectorA[i]>>vectorB[i];
      cout <<vectorA[i]<<vectorB[i]<<endl;
     }
     if (!eqnparam){
      cout <<"Some error message"<< endl;
     if (!getline(inFile, line)){ //checking for line 2
      cout << "Some error message"<< endl;
     }
     getline(inFile, line); 
     ifstream inFile2 (line);
     while (!inFile2.eof()){
      string someLine;
      getline(inFile2, someLine);//read in line
      vectorString.push_back(someLine);//put line into vector
     }
     for( std::vector<string>::const_iterator i = vectorString.begin(); i != vectorString.end(); ++i) {
      std::cout << *i << ' ';//print vector
     }
     if (!getline(inFile, line)){ //checking for line 3, haven't put necessary code in trying to get first part to work
      cout << "Some error message"<< endl;
     }
     getline(inFile, line);
     ifstream inFile3 (line);
     
     
    
    return 0;
     }
    }

  6. #6
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,655
    >> ifstream inFile (argv[1]);

    Always check to see that the file was in fact open. If not, stop processing.

    >> cout << "Some error message"<< endl;

    How hard is it to print a meaningful message?

    >> cout << m << p << c << endl;

    How exactly do you distinguish three numbers without any spacing between?

    >> eqnparam>>vectorA[i]>>vectorB[i];

    VectorA and VectorB are empty at this point. You should have resized them before the loop. It still doesn't matter much, of course, because even then their elements would have been set to zero, so why are you attempting to read values from them?

    >> while (!inFile2.eof()){

    You need to check for EOF right after getline(), not at the top of the loop.

  7. #7
    Registered User
    Join Date
    Sep 2012
    Posts
    86
    I cannot figure out what is wrong with this.

    Code:
    for (int i = 0; i < 10; i++){
        mystringmap(String[i]);
        
    //hash function h[i]k = ((a[i]*k*b[i])%p)%m
            
    for (int index = 0; index < hashfunctions; index++){ //for loop to incremement through hash functions
    
            std::vector <
    int> value;
            }
    
            std::vector <
    int> value.at(index) = ((std::vector <int> A.at(index) * stringvalue * std::vector <int> B.at(index)) %primenumber) %tablesize;
    This is supposed to take a string, pass it to a function to convert to an int value, and assign the hash function into vector value.

    This is the error:
    error C2143: syntax error : missing ';' before '.'

  8. #8
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    You don't keep typing the type when you want to use a variable. You don't have a lot of "int index"es in your code, right? When you want to use it, it's just index. Same here.

  9. #9
    Registered User
    Join Date
    Sep 2012
    Posts
    86
    Thanks!

    Is there a way to find where in my code this issue is being caused?

    line:932
    expression: vector subscript is out of range

    I have no compiler error or warning and I am using Microsoft Visual Studio.

  10. #10
    Registered User
    Join Date
    Sep 2012
    Posts
    86
    Can anyone explain why nothing within the for loop is printing? I understand you may not be able to with only a snippet.

    Code:
    int i = 0;
    
    	
    int length = 0;
    
    	
    int stringvalue = 0;
    
    	std::cout<<
    "string in mystringmap "<<mystring<<std::endl;
    	length = mystring.length();
    
    	std::cout<<
    "length of string "<<length<<std::endl;
    
    	
    // declare variable for storing int value of key
    
    	
    for (i = 0; i > length; i++){	//incrememnt through string<endl
    
    		std::cout<<
    "character is: "<<mystring[i]<<std::endl;
    
    		
    char character = mystring[i];
    
    		std::cout<<
    "character is: "<<character<<std::endl;
    
    		stringvalue = stringvalue * 37 ^ stringtoint(character); 
    // v = v *37 xor stringtoing(string[i]);
    	}
    
    	
    //stringvalue = stringvalue / tablesize; //value / tablesize to convert from long to string 
    
    	std::cout<<
    "string value before returning"<<stringvalue<<std::endl;
    
    	
    return stringvalue;
    }

  11. #11
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Nothing in your for loop is happening because you set up your for loop to never happen. i > length is false, so the loop ends immediately.

  12. #12
    Registered User
    Join Date
    Sep 2012
    Posts
    86
    If I am trying take the "stringvalue" and return it to a function in my class (this is a function in separate file). Why might I receive an address value in my class function?

  13. #13
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by carpeltunnel View Post
    If I am trying take the "stringvalue" and return it to a function in my class (this is a function in separate file). Why might I receive an address value in my class function?
    That depends. Are you using real strings or C-style strings? For C-style strings, that's exactly what you would expect (since a C-style string reduces to a pointer to the location of the characters in memory). For real strings, the type system would prevent that.

  14. #14
    Registered User
    Join Date
    Sep 2012
    Posts
    86
    I'm using std::string, yes. But I'm trying to return an integer value back to my function, so why would it pass an address if that is the case?

  15. #15
    Registered User
    Join Date
    Sep 2012
    Posts
    86
    Well I initialized my stringvalue to 0 in my function, it prints 0, so the value is not being sent from the function call. I'll look at it for a while.

Page 1 of 3 123 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. I have a feeling this movie will be solid win!
    By Cynic in forum General Discussions
    Replies: 16
    Last Post: 03-25-2012, 01:40 AM
  2. Suggestion for the tutorial quizzes answer key.
    By Warrax in forum C++ Programming
    Replies: 1
    Last Post: 04-15-2007, 12:12 PM
  3. Replies: 3
    Last Post: 04-04-2002, 04:27 PM
  4. Direct X + C = Solid App?
    By fatpotatohead in forum Game Programming
    Replies: 1
    Last Post: 09-03-2001, 04:37 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21