14

This isn’t a bad idea for a learning project, and I’d say it’s implemented quite well. Before I dive into the code itself, I’m going to do a high-level design review. Design review You’re using std::map backwards So you want a list of pairs of values, where one value is the tax rate and the other income lower bound for that tax rate. In your code you made ...


6

In C++ STL, the set and closely related map containers are sorted and provide an efficient way to look up the set element (or map key) which is not less than a given value. This is accomplished using the lower_bound method, which is available for both set and map. You can use this to your advantage here. Instead of having the taxRate map rates to minimum ...


2

To add to the answer by chux which suggests using primes for mod or compression as it often called, I was going through articles on good hash and compression functions and found 2 alternatives: Make N as prime (as mentioned in the answer by @chux-reinstate-monica ) But most recommended taking away the burden of being prime from the storage capacity (N) and ...


1

Just a few points for now, I will extend my answer over the weekend: I think you should think about the max size of your table anyway. I mean you can't have 4 billion nodes in there. This is connected to the size. If you only have to resize your table maybe once or twice, it's probably not worth storing the hash value. It's a trade off between speed and ...


Only top voted, non community-wiki answers of a minimum length are eligible