1

Apparently, STL precursors of the C++ standard library used to include hash-based containers in a header file named hash_map.h (specifically, I guess, a hash_map container). But - the C++ standard library does not have a <hash_map>; and AFAIK unordered_map is not exactly the same thing.

Now, I'm trying to build this old codebase and I've just noticed it includes <hash_map.h>.

What should I do to get the code to build, assuming I'm using Devuan Beowulf (~= Debian Buster) Linux on an AMD64 machine?

Notes:

  • I don't want to replicate a complete 10-year-old development environment; this codebase should eventually be buildable with my (or any modern) Linux distribution.
  • I'm willing to:

    • Make minor changes to the code.
    • Install some distribution-appropriate packages.
    • Install something under /usr/local


    in decreasing order of preference.

einpoklum
  • 118,144
  • 57
  • 340
  • 684
  • 1
    What would happen if you did a global search and replace for `hash_map<` and replaced with `unordered_map`. Likewise replace `#include ` with `#include `. Wouldn't it just work? Maybe? – selbie Jul 11 '19 at 22:49
  • @selbie: The code doesn't build right now for other reasons. I want to know whether what you suggested is _supposed_ to work, or known to generally work; and if not, what the caveats are. – einpoklum Jul 11 '19 at 22:53
  • 1
    There's at least one web page suggesting that hash_map is synchronized with respect to threads. Assuming you aren't relying on the hash_maps to be accessed by multiple threads without a lock, I would think you are going to be ok. Even if you brought in an alternate implementation for hash_map, you'd still have to test your code in a similar manner. – selbie Jul 11 '19 at 23:28
  • What are you hashing? There are topnotch free algorithms, better tested than most would expect. Standard libs are often lazy. Hashing an `int` is a no-op which results in poor spread. There are people skilled enough to do this properly. Inspiration: http://mostlymangling.blogspot.com/ Do you need some hashing that fits into an old scheme or a replacement that works really well? Checkout the blog and the references to "random". It's plug and play. The fun part is that you can actually `constexpr` many situations even though it takes time to compile :) – Ted Lyngmo Jul 12 '19 at 00:29
  • If you need a `` header with functions to make the rest of the code happy, I think I can provide it. Just provide the signatures you need. – Ted Lyngmo Jul 12 '19 at 00:38

1 Answers1

2

Depends on how much work you're willing to do, and what your future plans for this code base are.

You could:

  • find an old compiler that has <hash_map> and install that. I'd suggest something like a 10 year old version of gcc.
  • Find a different chunk of code that does what you want.
  • Change all the the uses of hash_map into unordered_map and then figure out what else needs to change.
Marshall Clow
  • 15,972
  • 2
  • 29
  • 45
  • Only option 3 is relevant. But - can you guarantee that `unordered_map` behaves like `hash_map` (ignoring implementation details of course)? – einpoklum Jul 11 '19 at 22:59
  • 2
    No; you can't guarantee that they behave identically. I'm confident they behave "similarly", but that's not the same. If I thought that they were identical, I would not have added "figure out what else needs to change" to my answer – Marshall Clow Jul 11 '19 at 23:05
  • I don't suppose there's a description somewhere of how they differ... ? Also - Boost ASIO seems to have a hash_map; wouldn't that work? – einpoklum Jul 11 '19 at 23:11
  • @einpoklum The SGI documentation ( http://www.sgi.com/tech/stl/hash_map.html ) got taken down, but someone seems to be hosting it on their website ( http://www.martinbroadhurst.com/stl/hash_map.html ). The documentation may help in figuring out how close the two are. – Justin Jul 11 '19 at 23:16
  • If you going to do a port to some other implementation of hash_map, which isn't standardized, you might as well do the work to just convert to . – selbie Jul 11 '19 at 23:25
  • @selbie: I was hoping maybe I could just replace the inclusion with an inclusion of the Boost header, and a `using` statement... – einpoklum Jul 11 '19 at 23:39
  • @selbie: Actually, possibly 0, since I haven't found any instantiations for now, making the question somewhat theoretical. But - suppose there were several. What then? – einpoklum Jul 12 '19 at 08:01