·······@CS.YALE.EDU (ken yip) writes:
>The obvious way:
>(defun set-equal? (x y &key (test #'equal) (key #'(lambda(x)x)))
> (and (subsetp x y :test test :key key)
> (subsetp y x :test test :key key)))
>seems to be doing a lot of redundant computations. I can't assume
>the given sets have no duplicates. Can someone suggest a fast
>implementation? Thanks ahead.
how about
(defun set-equal? (x y &key (test #'equal) (key #'identity))
(null (set-difference x y :test test :key key)))
If the sets are sorted then faster methods may be available. However,
the above code is easy and simple (I am assuming that the
set-difference provided by LISP would be faster than anything
equivalent that you could write).
Hope this helps
Bharat
--
R. Bharat Rao, E-mail: ······@cs.uiuc.edu (······@kbesrl.me.uiuc.edu)
AI Group, Beckman Institute for Advanced Science and Technology
405 N. Matthews, Urbana, IL 61801 (217)-244-1263 (O), 337-6498 (H)
Electrical & Computer Engineering, University of Illinois, Urbana