Question: So I constructed my `unordered_set` passing 512 as min buckets, i.e. the `n` parameter.
My hash function will always return a value in the range `[0,511]`.

My question is, may I still get collision between two values which the hashes are not the same? Just to make it clearer, I tolerate any collision regarding values with the same hash, but I may not get collision with different hashes values.

Answer: 
Any sensible implementation would implement `bucket(k)` as `hasher(k) % bucket_count()`, in which case you won't get collisions from values with different hashes if the hash range is no larger than `bucket_count()`.

However, there's no guarantee of this; only that equal hash values map to the same bucket. A bad implementation could (for example) ignore one of the buckets and still meet the container requirements; in which case, you would get collisions.

If your program's correctness relies on different hash values ending up in different buckets, then you'll have to either check the particular implementation you're using (perhaps writing a test for this behaviour), or implement your own container satisfying your requirements.
Since you don't have an infinite number of buckets and/or a perfect hash function, you would surely eventually get collisions (i.e. hashes referring to the same location) if you continue inserting keys (or even with fewer keys, take a look at the [birthday paradox](http://en.wikipedia.org/wiki/Birthday_problem)).

The key to minimize them is to tune your *load factor* and (as I suppose STL does internally) [deal with collisions](http://en.wikipedia.org/wiki/Hash_table#Collision_resolution). Regarding the bucket value you should choose it in order to avoid rehashing.