Search in vectors of struct for unordered_set and extract values from the struct

I'm trying to find a way to search in **vectors of structs** namely `
data
` for **unordered_set of integer** namely `
Temp1
` such that:


1
2
3
4
5
6
7
 struct Sstruct{
    	int No;
    	float Prob;
    	float W;
    };
    std::vector<std::vector<Sstruct>> data;
    std::vector<std::unordered_set<int>> Temp1;


**Example for `
data
`**
: where each inter `No` has two float values (Prob, W)

1
2
3
4
    1  0.5  0.1    2  0.6  0.3    3  0.4  0.3      4  0.4  0.2 
    1  0.3  0.1    2  0.5  0.3    4  0.1  0.2 
    2  0.4  0.1    5  0.8  0.3
    4  0.4  0.2    5  0.1  0.3

...

**Example for `
Temp1
`**
:
1
2
3
4
    1 2 4
    1 4  
    2 3
    4 3



Thus, I want to check for each value of `Temp1` if it subset of `data`

**Example**: let take `(1 2 4)` the first `unordered_set` in `Temp1` and check if it is subset of any vector of `data`.

**1)** I will check if `(1 2 4)` is subset from the first vector of `data`:

1 0.5 0.1 2 0.6 0.3 3 0.4 0.3 4 0.4 0.2
**Yes**, then extract their first float values (their probabilities from that vector and save it in `p`

==>
`p += 0.5 * 0.6 * 0.4`


**2)** I will check if `(1 2 4)` is subset from the second vector of `data`:

1 0.3 0.1 2 0.5 0.3 4 0.1 0.2
**Yes**, then extract their first float values (their probabilities from that vector and save it in `p`

==>
`p += 0.3 * 0.5 * 0.1
`

**3)** I will check if `(1 2 4)` is subset from the third vector of `data`:
2 0.4 0.1 5 0.8 0.3
**No**, go to the next vector of `data` until `data.end()`


I did many versions of this code. I did use `std::includes` and `hash function`. the problem with hash function, I got error and also after I check `Temp1` if it subset of `data`, I couldn't extract the its probability values from `data`


**code:**

1
2
3
4
5
6
7
8
9
bool operator < (const Sstruct &a, const Sstruct &b)
    {return a.No < b.No; }
    
    
    bool operator==(Sstruct c, Sstruct d) { return c.No== d.No; }
            
    struct MyHash {
    size_t operator()(const Sstruct& x) const { return std::hash<int>()(x.No); }
    };


**// in the main function**


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
for (auto & Temp2: Temp1)
        {
          bool key = false;
          for (unsigned i = 0; i < data.size(); ++i)
            {
            	std::unordered_set<Sstruct, MyHash> d(data[i].begin(), data[i].end() );
            	float p= 1;
            
                if ((incld(d, Temp2)) == true) 
                 {
                   //calculate the `p` value
                    key = true
                 }
                else
                { if you didn't find it erase that unordered_set 
                    key = false
                    Temp1.erase(Temp2);
                }
            }
        }
     



**// searching method**


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
  bool incld(const std::unordered_set < Sstruct, MyHash >& d, const std::unordered_set<int>& Temp2) 
        { 	
       
            
        for (auto const& t3: Temp2)
        {
         std::unordered_set < Sstruct, MyHash >::iterator it = std::find_if(std::begin(d), std::end(d), t3);
    	//if (find(d.begin()->No, d.end()->No, t3))
    	//std::unordered_set < Sstruct>::iterator it = find(d.begin()->No, d.end()->No, t3);
        //if (std::find(d.begin(), d.end(), t3) == d.end())
    	//if (d.find(t3) == d.end())
        
                return false;
        }
           
        return true;
        }


**in the last function `incld`** i dont know how to use `find` with the `struc` to see if `Temp2` is subset of `data` (d) if yes i dont know how to get its valuds from `data`


**and this the error that i got:**

>
error C2064: term does not evaluate to a function taking 1 arguments


Last edited on
Topic archived. No new replies allowed.