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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.