Recent

Author Topic: Fsearch,if Else problems  (Read 18751 times)

Bart

  • Hero Member
  • *****
  • Posts: 5702
    • Bart en Mariska's Webstek
Re: Fsearch,if Else problems
« Reply #15 on: February 25, 2010, 04:28:41 pm »
I know I shouldn't, .....

<snip>

 :-X I just couldn't help my self....
 >:D Don't do what I do, do what they say !  :D

One could also create a haslist for all commands allowed, then do a binary search in the hashlist?

Or use nested case statements.
Say we have 3 commands: Help, Halt, Install:

Code: [Select]
case Command[1] of
  'H': case Command[2] of
         'E': case Command[3] of  etc. etc.
         'A':
         else //code for wrong input here
        end; 
  'I':  case Command[2] of
         'N': case Command[3] of etc.etc.
         else //code for wrong input here
       end;
  else //code for wrong input here
end;

(I actually once wrote such piece of code with nested case statements to decode codons (3 successive letters (array[1..3] of char), coding for an amino-acid), where this approach proved to be faster then any other alternative anyone else came up with.)

Bart

eny

  • Hero Member
  • *****
  • Posts: 1657
Re: Fsearch,if Else problems
« Reply #16 on: February 26, 2010, 04:21:11 pm »
One could also create a haslist for all commands allowed, then do a binary search in the hashlist?

Abstract a little futher and you end up with a design pattern  ::)
All posts based on: Win11; Lazarus 4_4  (x64) 12-02-2026 (unless specified otherwise...)

cdbc

  • Hero Member
  • *****
  • Posts: 2665
    • http://www.cdbc.dk
Re: Fsearch,if Else problems
« Reply #17 on: February 27, 2010, 12:49:02 am »
@RudieD

Nice piece of code mate, good on you :-)

Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE6/QT6 -> FPC Release -> Lazarus Release &  FPC Main -> Lazarus Main

 

TinyPortal © 2005-2018