Thanks for your response, Earnest.
It sounds like the most efficient approach for my problem may be to use a
standard binary search on a sorted list (List B is loaded and sorted only
once on start up) and implement it in Java.

How does the new feature request process work?

Regards,

Brett

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Behalf Of [EMAIL PROTECTED]
Sent: Thursday, 22 July 2004 1:38 a.m.
To: [EMAIL PROTECTED]
Subject: Re: JESS: Efficiency of list processing


I think Brett Daniel wrote:
> I have a problem where I am trying to establish if a String element in a
> given list A exists in another larger list B.  There are obviously a
number
> of ways I can do this in either Jess or in Java.  In Jess, I could use the
> member$ function and iterate through the list B until I have found the
> element (is there the equivalent of "break" to exit a loop in Jess).  In
> Java, I could create a sorted TreeSet and use the "contains" method.
>
> Which is the most efficient?  How are lists represented in Jess and how
does
> the member$ function work?

Jess lists are basically arrays. not linked lists as in Lisp.

member$ asks if a given item is in a given list; you don't have to do
any iteration. It has linear complexity (i.e., it searches linearly
through the list.)

nth$ returns the item at a given index from a list; it is O(1).

Since you mention two lists, you may be interested in their
intersection (see the intersection$ function) or their complement (see
the complement$ function). Both of these are implemented using
HashMaps, and therefore have linear rather than quadratic complexity
(linear because all the items have to get put into the maps.)

There is no "break" in Jess; I'd consider that a useful feature
request, however.


---------------------------------------------------------
Ernest Friedman-Hill
Science and Engineering PSEs        Phone: (925) 294-2154
Sandia National Labs                FAX:   (925) 294-2234
PO Box 969, MS 9012                 [EMAIL PROTECTED]
Livermore, CA 94550         http://herzberg.ca.sandia.gov

--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the list
(use your own address!) List problems? Notify [EMAIL PROTECTED]
--------------------------------------------------------------------

--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the list
(use your own address!) List problems? Notify [EMAIL PROTECTED]
--------------------------------------------------------------------

Reply via email to