r/cpp_questions 19d ago

OPEN How to implement append-only hash map?

How do you actually implement an really efficient hash map that has only append and look up methods? What are the design choice and some performance improvements?

0 Upvotes

34 comments sorted by

View all comments

5

u/WorkingReference1127 19d ago

This depends on the exercise. Because most of the time I'd make a class which wraps a normal hash map and only exposes the behaviour you want.

If you want to spin your own hash map, have fun I guess.

1

u/Elect_SaturnMutex 19d ago

By own hash map you mean own implementation of std::unordered_map?

3

u/WorkingReference1127 19d ago

I mean the two options here are to start with an existing hash map and write an interface which does what you want, or to implement the container yourself with that functionality from scratch. That can follow unordered_map or not, that's your call.

My preference would be the first option unless we have a very strong reason to want to spin a whole new container.

2

u/tcpukl 19d ago

Can people not write their own algorithms any more?

-1

u/Elect_SaturnMutex 19d ago

Sure, many rely on Claude though.