mikeagn / sparsehash

Automatically exported from code.google.com/p/sparsehash
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Using the special values as normal keys break the hash structures' integrity. #27

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Observe the effect of the following code block

    google::dense_hash_map<int, int> xxx;
    xxx.set_deleted_key(-2);
    xxx.set_empty_key(-1);

    xxx[-1] = 55;

    cout << xxx.size() << endl;

    cout << std::distance(xxx.begin(), xxx.end()) << endl;

What is the expected output? What do you see instead?
Apparently, after running the code, xxx.size() reports 1, yet iterating
over the map yields no elements.

What version of the product are you using? On what operating system?

Please provide any additional information below.
I'd suggest adding asserts at insert()'s to guard against inadvertently
using the special 'empty' and 'deleted' values in user code as normal key
values.

Original issue reported on code.google.com by tai...@gmail.com on 13 Jan 2009 at 11:30

GoogleCodeExporter commented 9 years ago
That's a good idea.  I'll do that for the next release.

Original comment by csilv...@gmail.com on 14 Jan 2009 at 1:13

GoogleCodeExporter commented 9 years ago

Original comment by csilv...@gmail.com on 14 Jan 2009 at 1:16

GoogleCodeExporter commented 9 years ago
I've added assert checks in sparsehash 1.4, just released.

Original comment by csilv...@gmail.com on 29 Jan 2009 at 1:42