home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.pascal.borland      Borland Pascal was actually pretty neat      2,978 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 1,920 of 2,978   
   Dr John Stockton to All   
   Re: Decoding RNA codons: fastest method    
   09 Oct 05 22:49:21   
   
   From: jrs@merlyn.demon.co.uk   
      
   JRS:  In article <19cik154cckref8e9duduins86dghajpbi@4ax.com>, dated   
   Sun, 9 Oct 2005 17:07:15, seen in news:comp.lang.pascal.borland, Bart   
    posted :   
   >   
   >Using a faster hashfunction:   
   >   
   >function CodonHash(const ACodon: tCodon): Longint;   
   >begin   
   >  Result := (Ord(ACodon[1]) shl 16) + (Ord(ACodon[2]) shl 8) +   
   >Ord(ACodon[3]);   
   >end;   
      
   Although that's like a Hash, you're not really using it as one.   
      
   It looks like Delphi; I don't recall Return in Pascal.  This should be   
   quicker, and gives the same but with a leading 3.   
      
           function CodonHash(const ACodon: tCodon): Longint;   
           begin CodonHash := Longint(ACodon) end;   
      
   Since it's so simple, don't use a function.   
      
   Or, since the codons are made of ACGU only, encode each letter as 2 bits   
   and store in a byte; you can then look the translation up in a small   
   array of enumerated or string (fill unused entries with 0 or '').   
      
   Since a letter needs only 5 bits, you could try encoding three in a byte   
   as (X1*2+X2)*2+X3; there *may* be no duplicates.  In fact, only 3 bits   
   vary in ACGU : ...X.XX. : so (X1*32+X2)*32+X3 looks safe, using word   
   arithmetic.   
      
   Remember that Pascal is 16-bit, so using a longint is a 2-step process,   
   unlike in 32-bit Delphi.   
      
   Arrange your numbers in order, and use a binary search; for 64 entries,   
   that's about 6 comparisons rather than average 32.   
      
   For elegance, use an enumerated type whenever it suits.   
      
   --   
    © John Stockton, Surrey, UK.  ?@merlyn.demon.co.uk   Delphi 3   Turnpike 4 ©   
     TP/BP/Delphi/&c., FAQqy topics & links;   
     clpdmFAQ;   
     news:borland.* Guidelines   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca