From: Bill Newman
Subject: Testing bit vectors for zero-ness.
Date: 
Message-ID: <wnewmanEnK1t2.5F@netcom.com>
I have bit vectors which represent sets. After I've created a set with
various bit-and, bit-or, and similar operations, I'd like to detect
whether the set is empty.  Is there an efficient, concise, portable
way to do this? The only portable way I can see is by looping over all
individual bits and checking them all individually. It seems like a
shame to do this when the data are packed into machine words which can
be tested efficiently for zeroness without being unpacked.  I've been
over the fine manual a few times, but maybe I missed something?

  Bill Newman
From: Barry Margolin
Subject: Re: Testing bit vectors for zero-ness.
Date: 
Message-ID: <PS2A.50$Ey4.924622@cam-news-reader1.bbnplanet.com>
In article <················@netcom.com>,
Bill Newman <·······@netcom.com> wrote:
>I have bit vectors which represent sets. After I've created a set with
>various bit-and, bit-or, and similar operations, I'd like to detect
>whether the set is empty.  Is there an efficient, concise, portable
>way to do this? The only portable way I can see is by looping over all
>individual bits and checking them all individually. It seems like a
>shame to do this when the data are packed into machine words which can
>be tested efficiently for zeroness without being unpacked.  I've been
>over the fine manual a few times, but maybe I missed something?

(every #'zerop set) will do it, but it will probably loop over all
the bits checking them individually.

If your bit vectors are all the same length you can define something like:

(defconstant +zero-bv+ #*000000000)

and then use

(equal set +zero-bv+)

It's possible that an implementation would optimize this so that it does
the comparisons word-by-word rather than element-by-element, but I don't
know offhand if any do.

One way to solve your problem is to use integers and the boolean functions
rather than bit vectors.  Then you can just use (zerop set).

-- 
Barry Margolin, ······@bbnplanet.com
GTE Internetworking, Powered by BBN, Cambridge, MA
Support the anti-spam movement; see <http://www.cauce.org/>
Please don't send technical questions directly to me, post them to newsgroups.