Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^2: Determining uniqueness in a string.

by BrowserUk (Patriarch)
on Oct 04, 2005 at 00:03 UTC ( [id://497093]=note: print w/replies, xml ) Need Help??


in reply to Re: Determining uniqueness in a string.
in thread Determining uniqueness in a string.

Unless your XS version is quicker than my Inline C algorithm:

__DATA__ __C__ int uniq( char* s ) { int i; int t = 0; for( i=0; i<10; i++ ) { t |= 1 << ( s[i] - 48 ); } return t == 1023; }

which doesn't seem likely, then the big hash lookup will still be faster,


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.

Replies are listed 'Best First'.
Re^3: Determining uniqueness in a string.
by creamygoodness (Curate) on Oct 04, 2005 at 00:55 UTC
    With the caveat that your algo needs a variable offset or it will fail on EBCDIC machines, I like it better than mine. Your first and your last solutions are the best two on the page, IMHO.

    WRT the giant hash lookup: "That's nice, honey. Did you remember to feed the dog?" ;)

    --
    Marvin Humphrey
    Rectangular Research ― http://www.rectangular.com

      The big hash takes very little time to load from a pre-generated file of the 10! permutations--it doesn't actually take that long to generate either--and the 350 MB loads easily within my 512 MB ram machine without swapping (if I haven't got much else running at the time).

      If raw performance is the criteria, it is by far the quickest and simplest option.

      Of course, if the criteria changed to be 11 digits, it starts to becomes impractical, but that's tomorrows problem :)


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
      "Science is about questioning the status quo. Questioning authority".
      The "good enough" maybe good enough for the now, and perfection maybe unobtainable, but that should not preclude us from striving for perfection, when time, circumstance or desire allow.

        Well, if you are untroubled by the prospect of requiring 350 MB of ram, I can certainly see how you would be untroubled by the prospect of EBCDIC incompatibility.

        If raw performance is the _only_ criteria, then granted, giganto-hash wins. Unless the script is a one-off, though, it's a poor choice, because, as you note, the algo falls apart if the criteria change even slightly, and most scripts have to be maintained. It demonstrates that hashing is an efficient way to test uniqueness, but that's not exactly shocking news, is it?

        There's an awful lot of esoterica in this thread: solutions which don't scale, which are painfully verbose and/or obtuse and/or "clever", which savage the KISS principle, etc. Since this is largely an academic exercise, it's necessary and important to push the boundaries and explore techniques which are wildly unbalanced. And yet the reasoning bears little resemblance to the approach I take when there's code that needs to be optimized.

        --
        Marvin Humphrey
        Rectangular Research ― http://www.rectangular.com

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://497093]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (4)
As of 2024-03-29 05:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found