New issue
Advanced search Search tips

Issue 745813 link

Starred by 1 user

Issue metadata

Status: WontFix
Owner: ----
Closed: Jul 2017
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: All
Pri: 3
Type: Bug



Sign in to add a comment

CheckedNumeric's are hard to use in HashMap

Project Member Reported by drott@chromium.org, Jul 18 2017

Issue description

I'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. 
 

Comment 1 by drott@chromium.org, Jul 18 2017

Demonstration in https://chromium-review.googlesource.com/c/575971/ - this test cases fails with triggering __builtin_trap(), I believe when the HashMap compares zero initialized memory to find an empty bucket, but I am not exactly sure.

It would be great if you had any suggestions as to how to address this. What to modify in the HashTraits for example.

Comment 2 by drott@chromium.org, Jul 18 2017

Cc: -tkent@chromium.org haraken@chromium.org
Cc: yutak@chromium.org

Comment 4 by tkent@chromium.org, Jul 19 2017

I guess CheckedNumeric::ValueOrDie() called in ClassUsingCheckedInt16::operator== dies because CheckedNumericState::is_valid_ is 0. kEmptyValueIsZero in HashTraits should be false.

Comment 5 by yutak@chromium.org, 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...

Comment 6 by drott@chromium.org, Jul 19 2017

Status: WontFix (was: Available)
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