Date: Sun, 29 Nov 2026 08:13:17 -0800
On Saturday, 28 November 2026 21:06:57 Pacific Standard Time Aleksandr
Povaliaev wrote:
> Correction!: "(key1, value2) argument" is about std:unordered_map not about
> std::unordered set. I will elaborate a little bit on it: if you have (key1.
> value1) already in place to std:unordered_set S structure, and you make
> something like "S[key2] = value2" where key1 != key2, but CompPred(key1,
> key2) is true, so you're overwriting the value and will get (key1, value2)
> pair in place after all. It might be a possible source of error due to
> unwanted (key1, value2) combination which might be used further, let's say
> after "extract".
If Comp(key1, key2) = true, then that's all that matters and the keys are
equivalent for the purposes of the discussion. The container is expected to
treat the two as equivalent and replace or not replace as key as such. The
fact that there is another function that may return false is irrelevant. Don't
bring it up.
If someone is making a mistake doing that, it's their problem. I agree that it
would be useful to detect the error and tell the user. Can you write an
algorithm that detects when it's wrong? This feels more like a job for an AI
assistant, not the compiler.
> You wrote "the size of the key is the least of the problems" :DDDD
> So if you're using only, let'say, 1% of Key object size for "CompPred"
> comparison, and you still put other 99% of Key to the unordered_set
> structure (99% is not used for Key comparison, but just occupies space in
> memory) - it make 100 times more usage of the CPU cache.
If you must store it, then you must store it and the cache usage is exactly
what was expected.
Povaliaev wrote:
> Correction!: "(key1, value2) argument" is about std:unordered_map not about
> std::unordered set. I will elaborate a little bit on it: if you have (key1.
> value1) already in place to std:unordered_set S structure, and you make
> something like "S[key2] = value2" where key1 != key2, but CompPred(key1,
> key2) is true, so you're overwriting the value and will get (key1, value2)
> pair in place after all. It might be a possible source of error due to
> unwanted (key1, value2) combination which might be used further, let's say
> after "extract".
If Comp(key1, key2) = true, then that's all that matters and the keys are
equivalent for the purposes of the discussion. The container is expected to
treat the two as equivalent and replace or not replace as key as such. The
fact that there is another function that may return false is irrelevant. Don't
bring it up.
If someone is making a mistake doing that, it's their problem. I agree that it
would be useful to detect the error and tell the user. Can you write an
algorithm that detects when it's wrong? This feels more like a job for an AI
assistant, not the compiler.
> You wrote "the size of the key is the least of the problems" :DDDD
> So if you're using only, let'say, 1% of Key object size for "CompPred"
> comparison, and you still put other 99% of Key to the unordered_set
> structure (99% is not used for Key comparison, but just occupies space in
> memory) - it make 100 times more usage of the CPU cache.
If you must store it, then you must store it and the cache usage is exactly
what was expected.
-- Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org Principal Engineer - Intel Data Center - Platform & Sys. Eng.
Received on 2026-11-29 16:13:27
