Question: I have custom hash function for unordered\_set of vectors< int >:

```
struct VectorHash {
int operator()(const vector<int> &V) const {
    int hsh=V[0] + V[1];
    return  hash<int>()(hsh);
}};

```

And for two such vectors I have the same hash equal 3:

```
vector<int> v1{2,1};
vector<int> v2{1,2};

```

But when I try to insert first vector v1 in unordered\_set, and then check if I have the same vector by hash as v2 in my unordered\_set I get false:

```
std::unordered_set<std::vector<int>, VectorHash> mySet;
mySet.insert(v1); 

if(mySet.find(v2) == mySet.end())
    cout << "didn't find" << endl;

Output:  "didn't find"

```

I assume that if two elements in unordered\_set have the same hash then if I have v1 in my unordered\_set, `find` method should return true, when I try to find v2. But it is not the case.

Could anyone explain me what is wrong in my reasoning?

Answer: 
> 
> I assume that if two elements in unordered\_set have the same hash then if I have v1 in my unordered\_set, find method should return true, when I try to find v2.
> 
> 
> 

That assumption is incorrect, same hash doesn't mean objects are equal.

[`unordered_map`](https://en.cppreference.com/w/cpp/container/unordered_map) uses the equality predicate to determine key equality (by default `std::equal_to`).
If you happen to want unique identifiers but not automatically compare values, you could use an `(unordered_)map<int, vector<int>>` and use that VectorHash function to generate the int key:

```
unordered_map<int, vector<int>> map;

int key=V[0] + V[1]
map[key] = V;

```