[comp.lang.icon] cset comparisons

dscargo@CIM-VAX.HONEYWELL.COM ("DAVE CARGO") (09/12/89)

I found myself doing some cset manipulations for a program and then realized
that I couldn't remember what kinds of comparison operators work for csets.
So I tried looking in the Icon book.  Nothing seemed to be clearly indicated.
At a guess csets are converted to strings for comparisons.  Is that the way
it works?  Is it unavoidable?

I wanted to see if the intersection of two csets was empty or not, e. g.,

if a ** b == '' then ...

but then I realized that I wasn't sure if == was the right operator.
(Not that I think that every type needs its own equality operator.)
Can someone provide some guidance (what to use and why Icon wants it that way)?

David S. Cargo
DSCARGO@CIM-VAX.HONEYWELL.COM

ralph@ARIZONA.EDU ("Ralph Griswold") (09/12/89)

The correct comparison operation to use is

	c1 === c2

provided both c1 and c2 are csets (=== does no type conversion).  For
csets, the bits are compared in about as fast a way as possible.

If you write

	c1 == c2

both operands are converted to strings and then compared.  Slow and
it also requires storage allocation.

Incidentally, to find out if a cset is empty, it's probably better to use

	*c1 = 0

I'm not positive about this; would have to do timings.  The size of
a cset is computed only when it's first needed.  IF it's used the second
time, it's available without additional computation.

  Ralph Griswold / Dept of Computer Science / Univ of Arizona / Tucson, AZ 85721
  +1 602 621 6609   ralph@Arizona.EDU  uunet!arizona!ralph