[mercury-users] Switching on strings

Michael Day mikeday at yeslogic.com
Thu Jul 24 09:58:32 AEST 2003


Hi,

Following on from the discussion of fact tables, how about strings?
Specifically, considering these two cases:

func1(S) = X :-
    ( if S = "one" then X = 1
    else if S = "two" then X = 2
    else if S = "three" then X = 3
    ...
    else fail ).

func2("one") = 1.
func2("two") = 2.
func2("three") = 3.

The first will require N/2 string comparisons on average, but will the
second be implemented using a hash table instead?

Thanks,

Michael

-- 
YesLogic Prince prints XML!
http://yeslogic.com

--------------------------------------------------------------------------
mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the users mailing list