Thread: solid tutorial suggestion

  1. #16
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    An address is an integer. Are you doing something like return &x instead of return x?

  2. #17
    Registered User
    Join Date
    Sep 2012
    Posts
    86
    No I'm doing return x

    Code:
    for (int i = 0; i < String.size(); i++){
    	mystring = String.at(i);
    	std::cout<<mystring<<std::endl;
    	mystringmap(mystring, tablesize);
    	std::cout << "string value in bloom "<<stringvalue;
    and then it goes to the called function from before and returns
    "stringvalue"

  3. #18
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    I guess the question is why do you think you're getting an address. Based on the code you posted above, mystringmap is supposed to return a number. Why do you think it's an address instead of the number you want?

  4. #19
    Registered User
    Join Date
    Sep 2012
    Posts
    86
    Well, I don't think it is passing anything now, at the beginning of my function I initialize it to 0 and after the second function call it prints 0 still. I am having trouble figuring out why..

  5. #20
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    There's a difference between
    Code:
    mystringmap(mystring, tablesize);
    and
    Code:
    stringvalue = mystringmap(mystring, tablesize);
    in that one of them does something and one of them does nothing.

  6. #21
    Registered User
    Join Date
    Sep 2012
    Posts
    86
    Wow, it's the easiest things that waste the most time.

    One more stupid question, I'm trying to set the value of the index to true in a vector <bool> but I am having trouble getting the syntax to work, can anyone help set me straight with that?

  7. #22
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Quote Originally Posted by carpeltunnel View Post
    Wow, it's the easiest things that waste the most time.

    One more stupid question, I'm trying to set the value of the index to true in a vector <bool> but I am having trouble getting the syntax to work, can anyone help set me straight with that?
    How are you currently trying to do it?
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  8. #23
    Registered User
    Join Date
    Sep 2012
    Posts
    86
    Well my current attempt is this:

    Code:
    std::vector <bool> truthtable = valuei.at(index);
    But I think I'm getting farther away.

  9. #24
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Are you trying to do the entire vector at once, or just a particular element of the vector?

  10. #25
    Registered User
    Join Date
    Sep 2012
    Posts
    86
    Just a value at a time, I have it in a for loop that increments through all strings and hash functions.

  11. #26
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Then just assign to that value.
    Code:
    truthtable[n] = true or false;

  12. #27
    Registered User
    Join Date
    Sep 2012
    Posts
    86
    Code:
    vector <bool> bloomprediction = bloom.searchhash();
    This is supposed to take the return vector from search of of Boolean value and store into Boolean vector in main.

    When it gets to this line it says "Error, vector <bool> iterator is dereferencable"


    Header definition
    Code:
    std::vector <bool> searchhash();
    Private member
    Code:
    std::vector <bool> truthtable, stringtruth;
    Return value
    Code:
    return stringtruth;

  13. #28
    Registered User
    Join Date
    Sep 2012
    Posts
    86
    do you need something else?

  14. #29
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Quote Originally Posted by carpeltunnel View Post
    do you need something else?
    You'll need to post more code; the small snippets you've posted don't reveal much. Perhaps you could provide a small program that reproduces the error?
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  15. #30
    Registered User
    Join Date
    Sep 2012
    Posts
    86
    I changed the vector to int instead of bool because I was seeing if that was the problem. I know the function call works within searhhash(), and truthtable works, but it freezes up and says out of subscript on the function call of search hash from above. Here is the function.

    Code:
    std::vector <int> bloomfilter::searchhash(){
     int index = 0;
     std::vector <int> stringtruth;
     int size = String2.size();
     for (int i = 0; i < size; i++){
      stringtruth.resize(i);
      mystring2 = String2.at(i);
      stringvalue = mystringmap(mystring2, tablesize);
      for (index = 0; index < hashfunctions; index++){ //for loop to incremement through hash functions
       int insertvalue2 = ((static_cast<long long>(A.at(index)) * stringvalue * B.at(index)) %primenumber) %tablesize;
       if (truthtable[insertvalue2] == 1){
        index++;
        stringtruth[i] = 1;
        std::cout << "truth of " << stringtruth[i] << "is: " << std::endl;
        std::cout << String2[i] << " is true! " << std::endl;
       }
       else
       {
        stringtruth[i] = 0;
        std::cout << "truth of " << stringtruth[i] << "is: " << std::endl;
        std::cout << String2[i] << " is false. " << std::endl;
       }
      }
     }
     
     return stringtruth;
    }
    Let me know if there is another part of the code needed to help

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, 05:27 PM
  4. Direct X + C = Solid App?
    By fatpotatohead in forum Game Programming
    Replies: 1
    Last Post: 09-03-2001, 04:37 PM