3 ms·
There’s a third party crate for this. C++’s STL also doesn’t have it by default. The creation-order-preserving hash map is basically two data structures in one
by amluto 2y ago
There’s a third party crate for this. C++’s STL also doesn’t have it by default.
The creation-order-preserving hash map is basically two data structures in one, it’s more complex and slower than a normal hash map, and IMO it’s rather bizarre and I have never really understood why anyone wants one.
- Conscat 2y agoIt's especially unfortunate that the intuitive name, `std::map`, is that ordered and generally least useful option of the standard library's three hash map containers. My last job did rely on ordered-ness of `QMap`, because the elements are listed in a Qt GUI and it could confuse users if those widgets randomly rearranged themselves. That's the only use-case I've personally encountered for an ordered hash map.
- taeric 2y agoI would be surprised if it was dramatically slower, all told. Though, fair that I have not benchmarked in a long time, here. My main "idea" here is to stop from having to check all of the headers on a "per header" basis. Yes, you can make each check faster, as the TRIE does. You can also remove the entire reason to check individual headers by starting a traversal after where the internal headers are. You could also go with something like making sure the first header is "InternalHeaderCount: N" where you then keep the internal headers segregated form the others by a simple count. (This assumes you have solid control over what is adding the headers internally, of course.) (I also forgot to give kudos on the blog title. Any Die Hard reference is a good reference. :D )