Tessil / ordered-map

C++ hash map and hash set which preserve the order of insertion
MIT License
512 stars 66 forks source link

64 bit bucket_entry #16

Closed Peach1 closed 6 years ago

Peach1 commented 6 years ago

Is there any reason for restricting it to 32 bit indexes? Could 264 - 1 values be supported with just a trivial change?

in ordered_hash.h, the indexes are defined as 32 bit:

class bucket_entry
{
public:
    using index_type = std::uint_least32_t;
    using truncated_hash_type = std::uint_least32_t;

defining them as 64 bit would be:

    using index_type = std::uint64_t;
    using truncated_hash_type = std::uint64_t;

Besides additional memory usage, are there any implications of allowing 64 bit indexes?

Tessil commented 6 years ago

Hello,

The only reason I limited the size to 232 - 1 was effectively for memory reason (so that the size of bucket_entry stays at 8 bytes). The trivial change from uint32_t to uint64_t would be enough, bucket_entry will just use 16 bytes now.

When I designed the hash table, I had in mind to add a class template parameter to configure it if needed but I never actually did it. If you need larger maps, I will see to make it configurable.

Tessil commented 6 years ago

Hello,

Sorry for the delay, I added a way to configure this through an extra IndexType class template parameter.

tsl::ordered_map<int, int, std::hash<int>, std::equal_to<int>, 
                 std::allocator<std::pair<int, int>>, std::vector<std::pair<int, int>>, 
                 std::uint64_t> map;

I'll need to test that later before merging it to the master as I don't have enough RAM on my current computer to hold a large enough map.

Tessil commented 6 years ago

I merged the changes to the master. See #18 for details.