CheckedNumeric's are hard to use in HashMap |
||||
Issue descriptionI'm facing difficulties using a CheckedNumeric<int16_t> inside a class that I use a key of a HashMap. I believe due to the memory-zeroing optimizations of HashMap. tkent@, jschuh@, eae@ - your help would be appreciated. I'll upload a CL demoing the problem.
,
Jul 18 2017
,
Jul 18 2017
,
Jul 19 2017
I guess CheckedNumeric::ValueOrDie() called in ClassUsingCheckedInt16::operator== dies because CheckedNumericState::is_valid_ is 0. kEmptyValueIsZero in HashTraits should be false.
,
Jul 19 2017
It's unclear if we want to do this... Generally, storing as int would be sufficient (but be careful that 0 and -1 are not usable). One extra bool flag which should be always true simply makes the space efficiency worse. One possible idea is to store the actual data as a plain int, ignoring the CheckedNumeric data structure. Getters and setters can only receive CheckedNumeric<Int>. However, it's not clear whether we can make 0 and -1 as the empty value and the deleted value. I have no idea about how useful such traits would be...
,
Jul 19 2017
Thanks for taking the time to take a look and providing feedback. What you're saying partially overlaps with what I heard from Justin: It's not efficient to use a CheckedNumeric for storage, but it should instead be mainly used for computation. |
||||
►
Sign in to add a comment |
||||
Comment 1 by drott@chromium.org
, Jul 18 2017