I find increasing the resolution of the timestamp by making it a real (ie not an integer) as suggested by Re: goto HACK a very good solution: essentially for each integer timestamp you get trillions of sub-timestamps to accommodate trillions of integer-timestamp duplicates. Additionally, sorting wrt keys as reals is fast - I guess faster than sorting keys as strings. And you can get your original integer timestamp fastly-fast too!
Adding a random number in (0,1) to the integer timestamp is also good solution to create non-duplicate keys and you do not need to keep track of the last real key inserted for that duplicate in order to increment it. However, it will cost you searching for already existing real keys your entire hash because it is entirely possible to get duplicate random numbers.
In similar situations I create an array as the value of each potentially duplicate timestamp-key and then keep pushing duplicates in there till the cows come home (suggested also at Re: goto HACK). Added benefits are you keep your hash small by branching (i.e. push items into arrays for one key). And the arrays are already in the order your data came in, if that's what you want.
In reply to Re: goto HACK
by bliako
in thread goto HACK
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |