Making a "map" of things
Computers are fast these days fast enough to have allowed scripting languages like php to be viable. This allows for lazy programming, so I thought it might be interesting to revisit a problem I encountered many years ago. The problem/solution is simplified here, so never mind that you don't see why it is solved this way, it make sense in the actual context. We have a stream of queries keeping count of events to a database. The queries are all of the form: UPDATE table SET total=total+1 WHERE key = blah This stream is too much for the database to cope with. So instead of loads of queries we make a string map of the queries adding 1 to a total against the query when we see a duplicate. So the query becomes: UPDATE table SET total=total+__TOTAL__ WHERE key = blah Every so often we iterate the map, substitute __TOTAL__ and start again. In practice this reduced load to about 10% of what it was. So lets program this naively using std::map // gcc -O ordered_map.cpp -lstdc++ #include ...