head	1.28;
access;
symbols
	bobbase:1.28
	bob:1.28.1
	r2_1:1.25
	r2_0:1.25
	r1_1_beta:1.25
	r1_1_alpha:1.25
	r1_0:1.24
	r0_11:1.24
	r0_10:1.23
	r0_9:1.22
	Eglin_alpha_1:1.21;
locks
	thoth:1.28.1.1
	thoth:1.28; strict;
comment	@ * @;


1.28
date	94.10.06.15.51.07;	author fjsoria;	state Exp;
branches
	1.28.1.1;
next	1.27;

1.27
date	94.10.03.17.54.28;	author thoth;	state Exp;
branches;
next	1.26;

1.26
date	94.09.27.02.57.24;	author gmt;	state Exp;
branches;
next	1.25;

1.25
date	94.07.08.16.12.39;	author thoth;	state Exp;
branches;
next	1.24;

1.24
date	94.03.14.15.35.40;	author thoth;	state Exp;
branches;
next	1.23;

1.23
date	94.01.31.16.34.30;	author thoth;	state Exp;
branches;
next	1.22;

1.22
date	93.11.17.17.57.51;	author thoth;	state Exp;
branches;
next	1.21;

1.21
date	93.06.10.17.09.49;	author thoth;	state Exp;
branches;
next	1.20;

1.20
date	93.05.26.16.32.07;	author thoth;	state Exp;
branches;
next	1.19;

1.19
date	93.02.20.15.23.13;	author thoth;	state Exp;
branches;
next	1.18;

1.18
date	93.02.08.19.57.51;	author thoth;	state Exp;
branches;
next	1.17;

1.17
date	92.12.14.16.18.10;	author jm;	state Exp;
branches;
next	1.16;

1.16
date	92.10.22.14.05.13;	author jm;	state Exp;
branches;
next	1.15;

1.15
date	92.09.29.15.26.54;	author jm;	state Exp;
branches;
next	1.14;

1.14
date	92.09.25.14.47.01;	author jm;	state Exp;
branches;
next	1.13;

1.13
date	92.09.16.17.06.33;	author jm;	state Exp;
branches;
next	1.12;

1.12
date	92.09.16.16.36.33;	author jm;	state Exp;
branches;
next	1.11;

1.11
date	92.09.16.14.38.59;	author jm;	state Exp;
branches;
next	1.10;

1.10
date	92.09.08.14.37.04;	author jm;	state Exp;
branches;
next	1.9;

1.9
date	92.09.08.14.30.47;	author jm;	state Exp;
branches;
next	1.8;

1.8
date	92.09.01.14.04.42;	author jm;	state Exp;
branches;
next	1.7;

1.7
date	92.08.27.15.57.11;	author jm;	state Exp;
branches;
next	1.6;

1.6
date	92.08.27.12.02.07;	author jm;	state Exp;
branches;
next	1.5;

1.5
date	92.08.05.17.09.23;	author jm;	state Exp;
branches;
next	1.4;

1.4
date	92.08.04.12.04.34;	author jm;	state Exp;
branches;
next	1.3;

1.3
date	92.07.29.12.30.23;	author jm;	state Exp;
branches;
next	1.2;

1.2
date	92.07.14.14.25.51;	author jm;	state Exp;
branches;
next	1.1;

1.1
date	92.07.13.15.20.26;	author jm;	state Exp;
branches;
next	;

1.28.1.1
date	94.12.08.14.48.55;	author thoth;	state Exp;
branches;
next	;


desc
@ValueSet.h: header file fot Value Sets
@


1.28
log
@removed value-range, g++ gets buggy
@
text
@// Emacs -*- C++ -*-

//
//	Copyright 1993, Center for Computer Vision and Visualization,
//	University of Florida.  All rights reserved.
//

/* $RCSfile: ValueSet.h,v $
   $Log: ValueSet.h,v $
 * Revision 1.27  1994/10/03  17:54:28  thoth
 * Added iterators.
 * changed ValueType to T.
 * removed the binary ops between Sets and scalars since they were
 * inaccessible to users and unused by the IA_Set class.
 *
 * Revision 1.26  1994/09/27  02:57:24  gmt
 * Hack to fix screwed up complex.h .
 *
 * Revision 1.25  1994/07/08  16:12:39  thoth
 * Fix segvs caused by unexepected returns from ia_throw.
 *
 * Revision 1.24  1994/03/14  15:35:40  thoth
 * ValueSet is now derived from BaseSet.
 *
 * Revision 1.23  1994/01/31  16:34:30  thoth
 * added the ability to reset a ValueSetIter.
 *
 * Revision 1.22  1993/11/17  17:57:51  thoth
 * added choice() member to valueset.
 *
 * Revision 1.21  1993/06/10  17:09:49  thoth
 * Fix array constructor.
 *
 * Revision 1.20  93/05/26  16:32:07  thoth
 * Copyright Notices
 * 
 * Revision 1.19  93/02/20  15:23:13  thoth
 * The LatticeRelation that was causing a compiler bug is now
 * used from IA instead of IA_ValueSet<T>.
 * 
 * Revision 1.18  93/02/08  19:57:51  thoth
 * added output method for testing.
 * added workaround for 3.0.2 bug.
 * 
 * Revision 1.17  92/12/14  16:18:10  jm
 * Renamed class ValueSet to IA_ValueSet
 * 
 * Revision 1.16  92/10/22  14:05:13  jm
 * *** empty log message ***
 * 
 * Revision 1.15  92/09/29  15:26:54  jm
 * *** empty log message ***
 * 
 * Revision 1.14  92/09/25  14:47:01  jm
 * *** empty log message ***
 * 
 * Revision 1.13  92/09/16  17:06:33  jm
 * added spec for value_range function
 * 
 * Revision 1.12  92/09/16  16:36:33  jm
 * Added commnet to compare function
 * changed NULL to 0.
 * 
 * Revision 1.11  92/09/16  14:38:59  jm
 * Added the class ValueSetIter to provide an iterator for ValueSet
 * Rearranged the different operators for esthetic purposes
 * Added keyword 'const' to all member operators
 * Added LatticeRelation enum type, used by the compare function
 * Added declaration for compare function
 * added operators '>' and '<' for proper superset and proper subset
 * added keyword 'const' to private function count_dup
 * Moved function value_range outside the class as an independent function
 *   that takes only integer parameters
 * 
 * Revision 1.10  92/09/08  14:37:04  jm
 * removed code that had been commented out before.
 * 
 * Revision 1.9  92/09/08  14:30:47  jm
 * the operators have been redefined to be class members in the case of
 * valueset op element, and valueset op valueset. The combination 
 * element op valueset remains as a friend.
 * the function make_set does not take parameters anymore. It operates on
 * the internal value_array and size.
 * function value_range has been changed from class member to independent. It
 * will only work with integer arguments.
 * predicate operators now return an int instead of a char, in order to be
 * able to print the result.
 * 
Revision 1.1  92/09/01  14:02:25  jm
Initial revision

*/

#ifndef ValueSet_h_
#define ValueSet_h_

#ifndef __SC__
#include <search.h>
#endif

#include <iostream.h>
#include "ia.h"
#include "BaseSet.h"

// This class is created to provide a "default" comparator function
// for ValueType. If the user of ValueSet does not like this comparator,
// a new one can be provided.
// Notice the use of void parameters; this is because the return type and
// the argument types must match exactly to the specification needed by
// the "bsearch" and "qsort" routines used in the "contains" and "make_set"
// functions, respectively.

template <class T>
class IA_ValueSetComparator {
public:
    static int value_type_compare(const void *, const void *); 
};

template <class T> class IA_ValueSetIter;
template <class T> class IA_ValueSet;

template <class T> ostream& operator<< (ostream&, const IA_ValueSet<T>&);

template <class T>
class IA_ValueSet: public IA_BaseSet<T>,
	public IA_ValueSetComparator<T> {
  private:
    unsigned int size;
    T *value_array;

    static char dummy;
  public:
    IA_ValueSet() {size = 0; value_array = 0;}
    IA_ValueSet(const IA_ValueSet&);
    IA_ValueSet& operator= (const IA_ValueSet&);
    ~IA_ValueSet() {if (this->value_array != 0) delete [] value_array;}
    
    IA_ValueSet(T);
    IA_ValueSet(T, T);
    IA_ValueSet(T, T, T);
    IA_ValueSet(T, T, T, T);
    IA_ValueSet(T, T, T, T, T);
    IA_ValueSet( const T*, unsigned int);

    static IA::Type s_type() { return &dummy; }
    IA::Type type() const { return &dummy; }
    // card: cardinality, number of elements in the set
    
    unsigned int card() const {return this->size;}
    
    // contains: predicate for testing membership of an element in a set
    
    int contains(T) const;
    
    // min: minimum element of the set
    
    T min() const {
	if (this->size == 0) {
	    T	rval;
	    ia_throw(IA::INVALID_OPERATION, __FILE__, __LINE__);    
	    return rval;
	} else 
	    return this->value_array[0];
    }
    
    // max: maximum element of the set
    
    T max() const {
	if (this->size == 0)  {
	    T	rval;
	    ia_throw(IA::INVALID_OPERATION, __FILE__, __LINE__);    
	    return rval;
	} else   
	    return this->value_array[this->size-1];
    }

    // choice: some element from the set, we don't care which one
    T choice() const {
	return max();		// how lame.
    }
    
    // empty: predicate for testing emptiness of a set 
    
    int empty() const {return (this->size == 0);}

    IA_BaseSetIter<T> *iterator() const;
    
    IA_ValueSet<T> operator|  (const IA_ValueSet<T>&) const;
    IA_ValueSet<T> operator&  (const IA_ValueSet<T>&) const;
    IA_ValueSet<T> operator/  (const IA_ValueSet<T>&) const;
    IA_ValueSet<T> operator^  (const IA_ValueSet<T>&) const;

#if 0
    IA_ValueSet<T> operator|  (const T&) const;
    IA_ValueSet<T> operator&  (const T&) const;
    IA_ValueSet<T> operator/  (const T&) const;
    IA_ValueSet<T> operator^  (const T&) const;
    
    friend IA_ValueSet<T>	
    operator|  (const T&, const IA_ValueSet<T>&);
    friend IA_ValueSet<T>	
    operator&  (const T&, const IA_ValueSet<T>&);
    friend IA_ValueSet<T>	
    operator/  (const T&, const IA_ValueSet<T>&);
    friend IA_ValueSet<T>	
    operator^  (const T&, const IA_ValueSet<T>&);
#endif

    // The range of return values for this compare function does not include
    // all the enumerated values.
    
    int operator<= (const IA_ValueSet<T>&) const;
    int operator>= (const IA_ValueSet<T>&) const;
    int operator<  (const IA_ValueSet<T>&) const;
    int operator>  (const IA_ValueSet<T>&) const;
    int	operator== (const IA_ValueSet<T>&) const;
    int	operator!= (const IA_ValueSet<T>&) const;
#if 0
    int operator<= (const T&) const;
    int operator>= (const T&) const;
    int operator<  (const T&) const;
    int operator>  (const T&) const;
    int	operator== (const T&) const;
    int operator!= (const T&) const;
    
    friend int operator<= (const T&, const IA_ValueSet<T>&);
    friend int operator>= (const T&, const IA_ValueSet<T>&);
    friend int operator<  (const T&, const IA_ValueSet<T>&);
    friend int operator>  (const T&, const IA_ValueSet<T>&);
    friend int operator== (const T&, const IA_ValueSet<T>&);
    friend int operator!= (const T&, const IA_ValueSet<T>&);
#endif

    friend IA::LatticeRelation
    compare(const IA_ValueSet<T>&,
	    const IA_ValueSet<T>&);
   
#ifndef WORKAROUND_CFRONT_FRIEND_MANGLING_BUG
    friend ostream& operator<< (ostream&, const IA_ValueSet<T>&);
#endif
    friend class IA_ValueSetIter<T>;
    
  private:
    
    // Set_Nth procedure, note:  indices start at 0
    void set_nth (unsigned int index, T value) {
	if (index >= this->size) {
	    ia_throw(IA::POINT_INDEX_MISMATCH, __FILE__, __LINE__);
	} else
	    this->value_array[index] = value;
	// problem? need promotion to proper type?
    }
    
    int count_dup() const;
    void make_set();
    void remove_dup();
    
};

#if 0
template <class T>
class IA_ValueSetIter {
    const IA_ValueSet<T>* vsp;
    int i;
public:
    IA_ValueSetIter(const IA_ValueSet<T> &vs) { vsp = &vs; i = 0;}
    int operator()(T& vt) {
	int ret = 1;
	if (i < vsp->size) vt = vsp->value_array[i++];
	else ret = 0;
	return ret;
    }
    void reset() {
	i=0;
    }
};
#endif



#endif
@


1.28.1.1
log
@new extensive() method.
Conversion to throws of class objects.
choice is now random.
@
text
@a9 3
 * Revision 1.28  1994/10/06  15:51:07  fjsoria
 * removed value-range, g++ gets buggy
 *
a103 1
#include "set_errors.h"
a146 3

    int extensive() const { return 1; }

d148 1
d159 3
a161 2
	    ia_throw(Set_Empty_Exception(__FILE__, __LINE__));    
	    return T();
d170 3
a172 2
	    ia_throw(Set_Empty_Exception(__FILE__, __LINE__));    
	    return T();
d179 1
a179 5
	if (this->size == 0)  {
	    ia_throw(Set_Empty_Exception(__FILE__, __LINE__));    
	    return T();
	} else   
	    return value_array[IA::rand_mod(size)];
a211 1
#if 0
d218 1
a218 1

d244 1
a244 1
#if 0
d253 1
a253 1
#endif
@


1.27
log
@Added iterators.
changed ValueType to T.
removed the binary ops between Sets and scalars since they were
inaccessible to users and unused by the IA_Set class.
@
text
@d10 6
a279 1
IA_ValueSet<int> value_range(int v0, int v1);
@


1.26
log
@Hack to fix screwed up complex.h .
@
text
@d10 3
d107 1
a107 1
template <class ValueType>
d113 2
a114 2
template <class ValueType> class IA_ValueSetIter;
template <class ValueType> class IA_ValueSet;
d118 3
a120 3
template <class ValueType>
class IA_ValueSet: public IA_BaseSet<ValueType>,
	public IA_ValueSetComparator<ValueType> {
d123 1
a123 1
    ValueType *value_array;
d132 6
a137 6
    IA_ValueSet(ValueType);
    IA_ValueSet(ValueType, ValueType);
    IA_ValueSet(ValueType, ValueType, ValueType);
    IA_ValueSet(ValueType, ValueType, ValueType, ValueType);
    IA_ValueSet(ValueType, ValueType, ValueType, ValueType, ValueType);
    IA_ValueSet( const ValueType*, unsigned int);
d147 1
a147 1
    int contains(ValueType) const;
d151 1
a151 1
    ValueType min() const {
d153 1
a153 1
	    ValueType	rval;
d162 1
a162 1
    ValueType max() const {
d164 1
a164 1
	    ValueType	rval;
d172 1
a172 1
    ValueType choice() const {
d179 2
d182 21
a202 19
    IA_ValueSet<ValueType> operator|  (const IA_ValueSet<ValueType>&) const;
    IA_ValueSet<ValueType> operator&  (const IA_ValueSet<ValueType>&) const;
    IA_ValueSet<ValueType> operator/  (const IA_ValueSet<ValueType>&) const;
    IA_ValueSet<ValueType> operator^  (const IA_ValueSet<ValueType>&) const;
    
    IA_ValueSet<ValueType> operator|  (const ValueType&) const;
    IA_ValueSet<ValueType> operator&  (const ValueType&) const;
    IA_ValueSet<ValueType> operator/  (const ValueType&) const;
    IA_ValueSet<ValueType> operator^  (const ValueType&) const;
    
    friend IA_ValueSet<ValueType>	
    operator|  (const ValueType&, const IA_ValueSet<ValueType>&);
    friend IA_ValueSet<ValueType>	
    operator&  (const ValueType&, const IA_ValueSet<ValueType>&);
    friend IA_ValueSet<ValueType>	
    operator/  (const ValueType&, const IA_ValueSet<ValueType>&);
    friend IA_ValueSet<ValueType>	
    operator^  (const ValueType&, const IA_ValueSet<ValueType>&);
    
d206 21
a226 20
    int operator<= (const IA_ValueSet<ValueType>&) const;
    int operator>= (const IA_ValueSet<ValueType>&) const;
    int operator<  (const IA_ValueSet<ValueType>&) const;
    int operator>  (const IA_ValueSet<ValueType>&) const;
    int	operator== (const IA_ValueSet<ValueType>&) const;
    int	operator!= (const IA_ValueSet<ValueType>&) const;
    
    int operator<= (const ValueType&) const;
    int operator>= (const ValueType&) const;
    int operator<  (const ValueType&) const;
    int operator>  (const ValueType&) const;
    int	operator== (const ValueType&) const;
    int operator!= (const ValueType&) const;
    
    friend int operator<= (const ValueType&, const IA_ValueSet<ValueType>&);
    friend int operator>= (const ValueType&, const IA_ValueSet<ValueType>&);
    friend int operator<  (const ValueType&, const IA_ValueSet<ValueType>&);
    friend int operator>  (const ValueType&, const IA_ValueSet<ValueType>&);
    friend int operator== (const ValueType&, const IA_ValueSet<ValueType>&);
    friend int operator!= (const ValueType&, const IA_ValueSet<ValueType>&);
d229 2
a230 2
    compare(const IA_ValueSet<ValueType>&,
	    const IA_ValueSet<ValueType>&);
d233 1
a233 1
    friend ostream& operator<< (ostream&, const IA_ValueSet<ValueType>&);
d235 1
a235 1
    friend class IA_ValueSetIter<ValueType>;
d240 1
a240 1
    void set_nth (unsigned int index, ValueType value) {
d254 2
a255 1
template <class ValueType>
d257 1
a257 1
    const IA_ValueSet<ValueType>* vsp;
d260 2
a261 2
    IA_ValueSetIter(const IA_ValueSet<ValueType> &vs) { vsp = &vs; i = 0;}
    int operator()(ValueType& vt) {
d271 2
@


1.25
log
@Fix segvs caused by unexepected returns from ia_throw.
@
text
@d10 3
d88 1
d90 2
a265 1

@


1.24
log
@ValueSet is now derived from BaseSet.
@
text
@d10 3
d143 2
a144 1
	if (this->size == 0) 
d146 3
a148 1
	return this->value_array[0];
d154 2
a155 1
	if (this->size == 0) 
d157 3
a159 1
	return this->value_array[this->size-1];
d227 1
a227 1
	if (index >= this->size)
d229 2
a230 1
	this->value_array[index] = value;
@


1.23
log
@added the ability to reset a ValueSetIter.
@
text
@d10 3
d83 1
a83 2
#include <stream.h>
#include <assert.h>
d85 1
d107 2
a108 1
class IA_ValueSet: public IA_ValueSetComparator<ValueType> {
d112 2
d126 3
a128 1
    
@


1.22
log
@added choice() member to valueset.
@
text
@d10 3
d233 3
@


1.21
log
@Fix array constructor.
@
text
@d9 4
a12 1
   $Log:	ValueSet.h,v $
d140 5
@


1.20
log
@Copyright Notices
@
text
@d10 3
d113 1
a113 1
    IA_ValueSet(ValueType* const, unsigned int);
@


1.19
log
@The LatticeRelation that was causing a compiler bug is now
used from IA instead of IA_ValueSet<T>.
@
text
@d3 5
d10 4
@


1.18
log
@added output method for testing.
added workaround for 3.0.2 bug.
@
text
@d1 1
d5 4
d87 1
a87 1
private:
d90 1
a90 1
public:
d110 1
a110 1

d128 1
a128 1

d135 1
a135 1
        
d149 1
a149 5

    enum LatticeRelation {
	P_SUBSET, MP_SUBSET, EQUAL, MP_SUPERSET, P_SUPERSET, NO_REL, UNKNOWN
	};

d152 1
a152 4
 
    friend LatticeRelation 
    compare(const IA_ValueSet<ValueType>&, const IA_ValueSet<ValueType>&);

d159 1
a159 1

d166 1
a166 1

d174 4
d182 3
a184 3

private:

d194 1
d196 1
a196 2
    void make_set();

@


1.17
log
@Renamed class ValueSet to IA_ValueSet
@
text
@d4 3
d75 2
a76 2
template <class ValueType>
class IA_ValueSetIter;
d78 2
d176 3
a178 1
    friend ostream& operator<< (ostream&, IA_ValueSet<ValueType>&);
@


1.16
log
@*** empty log message ***
@
text
@d4 3
d67 1
a67 1
class ValueSetComparator {
d73 1
a73 1
class ValueSetIter;
d76 1
a76 1
class ValueSet: public ValueSetComparator<ValueType> {
d81 4
a84 4
    ValueSet() {size = 0; value_array = 0;}
    ValueSet(const ValueSet&);
    ValueSet& operator= (const ValueSet&);
    ~ValueSet() {if (this->value_array != 0) delete [] value_array;}
d86 6
a91 6
    ValueSet(ValueType);
    ValueSet(ValueType, ValueType);
    ValueSet(ValueType, ValueType, ValueType);
    ValueSet(ValueType, ValueType, ValueType, ValueType);
    ValueSet(ValueType, ValueType, ValueType, ValueType, ValueType);
    ValueSet(ValueType* const, unsigned int);
d121 4
a124 4
    ValueSet<ValueType>	operator|  (const ValueSet<ValueType>&) const;
    ValueSet<ValueType>	operator&  (const ValueSet<ValueType>&) const;
    ValueSet<ValueType>	operator/  (const ValueSet<ValueType>&) const;
    ValueSet<ValueType>	operator^  (const ValueSet<ValueType>&) const;
d126 4
a129 4
    ValueSet<ValueType>	operator|  (const ValueType&) const;
    ValueSet<ValueType>	operator&  (const ValueType&) const;
    ValueSet<ValueType>	operator/  (const ValueType&) const;
    ValueSet<ValueType>	operator^  (const ValueType&) const;
d131 8
a138 8
    friend ValueSet<ValueType>	
    operator|  (const ValueType&, const ValueSet<ValueType>&);
    friend ValueSet<ValueType>	
    operator&  (const ValueType&, const ValueSet<ValueType>&);
    friend ValueSet<ValueType>	
    operator/  (const ValueType&, const ValueSet<ValueType>&);
    friend ValueSet<ValueType>	
    operator^  (const ValueType&, const ValueSet<ValueType>&);
d148 1
a148 1
    compare(const ValueSet<ValueType>&, const ValueSet<ValueType>&);
d150 6
a155 6
    int operator<= (const ValueSet<ValueType>&) const;
    int operator>= (const ValueSet<ValueType>&) const;
    int operator<  (const ValueSet<ValueType>&) const;
    int operator>  (const ValueSet<ValueType>&) const;
    int	operator== (const ValueSet<ValueType>&) const;
    int	operator!= (const ValueSet<ValueType>&) const;
d164 6
a169 6
    friend int operator<= (const ValueType&, const ValueSet<ValueType>&);
    friend int operator>= (const ValueType&, const ValueSet<ValueType>&);
    friend int operator<  (const ValueType&, const ValueSet<ValueType>&);
    friend int operator>  (const ValueType&, const ValueSet<ValueType>&);
    friend int operator== (const ValueType&, const ValueSet<ValueType>&);
    friend int operator!= (const ValueType&, const ValueSet<ValueType>&);
d171 2
a172 2
    friend ostream& operator<< (ostream&, ValueSet<ValueType>&);
    friend class ValueSetIter<ValueType>;
d191 2
a192 2
class ValueSetIter {
    const ValueSet<ValueType>* vsp;
d195 1
a195 1
    ValueSetIter(const ValueSet<ValueType> &vs) { vsp = &vs; i = 0;}
d204 1
a204 1
ValueSet<int> value_range(int v0, int v1);
@


1.15
log
@*** empty log message ***
@
text
@d4 3
@


1.14
log
@*** empty log message ***
@
text
@d4 3
@


1.13
log
@added spec for value_range function
@
text
@d4 3
@


1.12
log
@Added commnet to compare function
changed NULL to 0.
@
text
@d4 4
d191 2
@


1.11
log
@Added the class ValueSetIter to provide an iterator for ValueSet
Rearranged the different operators for esthetic purposes
Added keyword 'const' to all member operators
Added LatticeRelation enum type, used by the compare function
Added declaration for compare function
added operators '>' and '<' for proper superset and proper subset
added keyword 'const' to private function count_dup
Moved function value_range outside the class as an independent function
  that takes only integer parameters
@
text
@d4 11
d65 1
a65 1
    ValueSet() {size = 0; value_array = NULL;}
d68 1
a68 1
    ~ValueSet() {if (this->value_array != NULL) delete [] value_array;}
d128 3
@


1.10
log
@removed code that had been commented out before.
@
text
@d4 3
d46 3
d94 4
a97 4
    // union of two sets, an element and a set, a set and an element
    
    ValueSet<ValueType>
	operator|  (const ValueSet<ValueType>&);
d99 4
a102 2
    ValueSet<ValueType>
	operator|  (const ValueType&);
d104 8
a111 2
    friend ValueSet<ValueType>
	operator|  (const ValueType&, const ValueSet<ValueType>&);
d113 3
a115 1
    // intersection (and)
d117 2
a118 2
    ValueSet<ValueType> 
	operator&  (const ValueSet<ValueType>&);
d120 6
a125 2
    ValueSet<ValueType> 
	operator&  (const ValueType&);
d127 6
a132 2
    friend ValueSet<ValueType> 
	operator&  (const ValueType&, const ValueSet<ValueType>&);
d134 6
a139 1
    // set difference
a140 66
    ValueSet<ValueType> 
	operator/  (const ValueSet<ValueType>&);
    
    ValueSet<ValueType> 
	operator/  (const ValueType&);
    
    friend ValueSet<ValueType> 
	operator/  (const ValueType&, const ValueSet<ValueType>&);
    
    // symmetric difference (xor)
    
    ValueSet<ValueType> 
	operator^  (const ValueSet<ValueType>&);

    ValueSet<ValueType> 
	operator^  (const ValueType&);

    friend ValueSet<ValueType> 
	operator^  (const ValueType&, const ValueSet<ValueType>&);

    // subset

    int 
	operator<= (const ValueSet<ValueType>&);

    int 
	operator<= (const ValueType&);

    friend int     
	operator<= (const ValueType&, const ValueSet<ValueType>&);

    // superset

    int     
	operator>= (const ValueSet<ValueType>&);

    int     
	operator>= (const ValueType&);

    friend int     
	operator>= (const ValueType&, const ValueSet<ValueType>&);

    // equality

    int     
	operator== (const ValueSet<ValueType>&);

    int     
	operator== (const ValueType&);

    friend int     
	operator== (const ValueType&, const ValueSet<ValueType>&);

    // non-equality

    int     
	operator!= (const ValueSet<ValueType>&);

    int     
	operator!= (const ValueType&);

    friend int     
	operator!= (const ValueType&, const ValueSet<ValueType>&);

    // range of ValueTypes

d142 1
d154 1
a154 1
    int count_dup();
d160 13
a172 13
ValueSet<int> value_range(int v0, int v1) {
    ValueSet<int> vs;
    int sz = v1 - v0;
    
    if (sz < 0)
	return ValueSet<int>();
    if (sz == 0)
	return ValueSet<int>(v0);
    int *ret_array = new int[++sz];
    for (int i = 0; i < sz; i++)
	ret_array[i] = v0+i;
    return ValueSet<int>(ret_array, sz);
}
@


1.9
log
@the operators have been redefined to be class members in the case of
valueset op element, and valueset op valueset. The combination 
element op valueset remains as a friend.
the function make_set does not take parameters anymore. It operates on
the internal value_array and size.
function value_range has been changed from class member to independent. It
will only work with integer arguments.
predicate operators now return an int instead of a char, in order to be
able to print the result.
@
text
@d2 13
a14 2
/* $RCSfile: ValueSet.H,v $
   $Log:	ValueSet.H,v $
a176 3

//    template <class ValueType>
//	friend ValueSet<ValueType> value_range (ValueType, ValueType);
@


1.8
log
@*** empty log message ***
@
text
@d2 5
a6 2
/* $RCSfile$
   $Log$
d12 1
a12 2
//typedef float ValueType;

a15 1
#include <search.h>
d17 8
d41 1
a41 1

d47 4
a50 4
    ValueSet(const ValueType*, unsigned int);

    // cardinality function

d52 4
d57 2
a58 15
    // contains function

    char contains(ValueType e) const {
	ValueType *ptr;
	
	ptr = (ValueType *)bsearch((ValueType *)(&e), 
				   (ValueType *)this->value_array,
				   this->size, sizeof(ValueType),
				   this->value_type_compare);
	    
	return (ptr == NULL ? 0 : 1);
	}    

    // min

d64 3
a66 3

    // max

d72 2
d75 10
a84 4
    char empty() const {return (this->size == 0);}

    // union (or)

d86 1
a86 1
 operator |  (const ValueSet<ValueType>&, const ValueSet<ValueType>&);
d90 2
a91 1
    friend ValueSet<ValueType> operator &  (const ValueSet<ValueType>&, const ValueSet<ValueType>&);
d93 6
d101 9
a109 2
    friend ValueSet<ValueType> operator /  (const ValueSet<ValueType>&, const ValueSet<ValueType>&);

d111 3
d115 2
a116 1
    friend ValueSet<ValueType> operator ^  (const ValueSet<ValueType>&, const ValueSet<ValueType>&);
d118 3
d123 2
a124 1
    friend char     operator <= (const ValueSet<ValueType>&, const ValueSet<ValueType>&);
d126 6
d134 2
a135 1
    friend char     operator >= (const ValueSet<ValueType>&, const ValueSet<ValueType>&);
d137 6
d145 2
a146 1
    friend char     operator == (const ValueSet<ValueType>&, const ValueSet<ValueType>&);
d148 6
d156 2
a157 1
    friend char     operator != (const ValueSet<ValueType>&, const ValueSet<ValueType>&);
d159 6
d167 2
a168 2
    template <class ValueType>
    friend ValueSet<ValueType> value_range (ValueType, ValueType);
d170 1
a170 1
    friend ostream& operator << (ostream&, ValueSet<ValueType>&);
d177 2
a178 2
	ia_throw(IA::POINT_INDEX_MISMATCH, __FILE__, __LINE__);
	    this->value_array[index] = value;
d180 1
a180 1
	}
d182 3
a184 3
    int count_dup(ValueType*, unsigned int);
    void remove_dup(ValueType*&, unsigned int&);
    ValueType* make_set(const ValueType*, unsigned int&);
d188 14
a202 3



@


1.7
log
@changed <iostream.h> to <stream.h>. It is working with typedef, and
is ready to be templatized.
@
text
@d1 5
d9 1
a9 1
typedef float ValueType;
d16 1
a16 1

d22 2
a23 1
class ValueSet: public ValueSetComparator {
d55 1
a55 1
    }    
d77 2
a78 1
    friend ValueSet operator |  (const ValueSet&, const ValueSet&);
d82 1
a82 1
    friend ValueSet operator &  (const ValueSet&, const ValueSet&);
d86 1
a86 1
    friend ValueSet operator -  (const ValueSet&, const ValueSet&);
d90 1
a90 1
    friend ValueSet operator ^  (const ValueSet&, const ValueSet&);
d94 1
a94 1
    friend char     operator <= (const ValueSet&, const ValueSet&);
d98 1
a98 1
    friend char     operator >= (const ValueSet&, const ValueSet&);
d102 1
a102 1
    friend char     operator == (const ValueSet&, const ValueSet&);
d106 1
a106 1
    friend char     operator != (const ValueSet&, const ValueSet&);
d110 2
a111 1
    friend ValueSet value_range (ValueType, ValueType);
d113 1
a113 1
    friend ostream& operator << (ostream&, ValueSet&);
d120 2
a121 2
	    ia_throw(IA::POINT_INDEX_MISMATCH, __FILE__, __LINE__);
	this->value_array[index] = value;
d123 2
a124 2
    }
	
a129 1
	
@


1.6
log
@Changed throw -> iaa_throw
@
text
@d4 3
d8 2
a9 3
#include <iostream.h>
#include <ia.h>
#include <std.h>
a10 1
typedef float ValueType;
d14 1
a14 7
    static int value_type_compare(void *t1, void *t2) {
	if (*(ValueType *)t1 > *(ValueType *)t2)
	    return 1;
	if (*(ValueType *)t1 < *(ValueType *)t2)
	    return -1;
	return 0;
    }
d55 1
a55 1
	    iaa_throw(IA::INVALID_OPERATION, __FILE__, __LINE__);    
d63 1
a63 1
	    iaa_throw(IA::INVALID_OPERATION, __FILE__, __LINE__);    
d112 1
a112 1
	    iaa_throw(IA::POINT_INDEX_MISMATCH, __FILE__, __LINE__);
@


1.5
log
@Back to untemplatized version. all operators working fine.
@
text
@d60 1
a60 1
	    throw(IA::INVALID_OPERATION, __FILE__, __LINE__);    
d68 1
a68 1
	    throw(IA::INVALID_OPERATION, __FILE__, __LINE__);    
d117 1
a117 1
	    throw(IA::POINT_INDEX_MISMATCH, __FILE__, __LINE__);
@


1.4
log
@ ValueSet is templatized instead of having a typedef
@
text
@d9 1
d11 1
a11 4
//typedef float ValueType;

template <class ValueType>
class ValueSetComparator{
d13 7
a19 7
    static int value_type_compare(void *t1, void *t2)
	{ if (*(ValueType *)t1 > *(ValueType *)t2)
	      return 1;
	  if (*(ValueType *)t1 < *(ValueType *)t2)
	      return -1;
	  return 0;
      }
d22 1
a22 3

template <class ValueType>
class ValueSet: ValueSetComparator<ValueType> {
d29 1
a29 1
    ValueSet& operator=(const ValueSet&);
d43 13
d60 1
a60 1
	    throw(IA::INVALID_OPERATION_ON_EMPTY_SET, __FILE__, __LINE__);    
d68 1
a68 1
	    throw(IA::INVALID_OPERATION_ON_EMPTY_SET, __FILE__, __LINE__);    
d106 2
d117 1
a117 1
	    throw(IA::VALUESET_INDEX_MISMATCH, __FILE__, __LINE__);
a127 11
template <class ValueType>
ValueSet<ValueType>::ValueSet(const ValueSet& vs) {
	this->size = vs.size;
	if (this->size == 0)
	    this->value_array = NULL;
	else {
	    this->value_array = new ValueType[this->size];
	    for (unsigned int i = 0; i < this->size; i++)
		this->value_array[i] = vs.value_array[i];
	}
    }
d129 1
a130 3
template <class ValueType>
ValueSet<ValueType>::ValueSet(ValueType v0) {
    this->value_array = new ValueType[this->size = 1];
a131 122
    this->value_array[0] = v0;
}

template <class ValueType>
ValueSet<ValueType>::ValueSet(ValueType v0, ValueType v1) {
    ValueType *ret_array = new ValueType[this->size = 2];

    ret_array[0] = v0;
    ret_array[1] = v1;
    
    this->value_array = make_set(ret_array, this->size);
    delete [] ret_array;
}

template <class ValueType>
ValueSet<ValueType>::ValueSet(ValueType v0, ValueType v1, ValueType v2) {
    ValueType *ret_array = new ValueType[this->size = 3];

    ret_array[0] = v0;
    ret_array[1] = v1;
    ret_array[2] = v2;
    
    this->value_array = make_set(ret_array, this->size);
    delete [] ret_array;
}

template <class ValueType>
ValueSet<ValueType>::ValueSet(ValueType v0, ValueType v1, ValueType v2, ValueType v3) {
    ValueType *ret_array = new ValueType[this->size = 4];

    ret_array[0] = v0;
    ret_array[1] = v1;
    ret_array[2] = v2;
    ret_array[3] = v3;
    
    this->value_array = make_set(ret_array, this->size);
    delete [] ret_array;
}

template <class ValueType>
ValueSet<ValueType>::ValueSet(ValueType v0, ValueType v1, ValueType v2, ValueType v3, 
                   ValueType v4) {
    ValueType *ret_array = new ValueType[this->size = 5];

    ret_array[0] = v0;
    ret_array[1] = v1;
    ret_array[2] = v2;
    ret_array[3] = v3;
    ret_array[4] = v4;
    
    this->value_array = make_set(ret_array, this->size);
    delete [] ret_array;
}

template <class ValueType>
ValueSet<ValueType>::ValueSet(const ValueType* ar, unsigned int sz) {
    this->value_array = make_set(ar, sz);
    this->size = sz;
}

template <class ValueType>
ValueType* ValueSet<ValueType>::make_set(const ValueType* a, unsigned int &sz){
    ValueType *ar1 = new ValueType[sz];
    
    if (sz == 0)
	return NULL;
    
    ar1 = new ValueType[sz]; 
    
    
    for (unsigned int i=0; i<sz; i++)
	ar1[i] = a[i];
    
    qsort(ar1, sz, sizeof(ValueType), value_type_compare);
    remove_dup(ar1,sz);
    
    return ar1;
}
template <class ValueType>
void ValueSet<ValueType>::remove_dup(ValueType* &a, unsigned int &sz) {

    ValueType *ret_array = new ValueType[sz-count_dup(a,sz)];
    
    unsigned int di = 0;
    
    for (unsigned int i=0; i < sz-1; i++)
	if (a[i] != a[i+1])
	    ret_array[di++] = a[i];
    
    ret_array[di++] = a[sz-1];
    
    delete [] a;
    a = ret_array;
    sz = di;
}


template <class ValueType>
int ValueSet<ValueType>::count_dup(ValueType* a, unsigned int sz) {
    int count = 0;
    for (unsigned int i=0; i < sz-1; i++)
	if (a[i] == a[i+1])
	    count++;
    return count;
}

template <class ValueType>
ostream& operator << (ostream& stream, ValueSet<ValueType>& vs) {
    int last_index = vs.size-1;
    stream << "<";
    if (vs.size > 0) {
	for (int i=0; i < last_index; i++)
	    stream << vs.value_array[i] << " ";
	if (vs.size > 0)
	    stream << vs.value_array[last_index];
    }
    stream << ">" << '\n';
    return stream;
}


#endif
@


1.3
log
@changed typedef to float to see how it behaved with floats.
@
text
@d10 1
a10 1
typedef float ValueType;
d12 1
a12 1
//template <class T>
d24 3
a26 1
class ValueSet: ValueSetComparator {
d117 138
@


1.2
log
@Added value_range function
@
text
@d10 1
a10 1
typedef int ValueType;
d16 6
a21 1
	{ return *(ValueType *)t1 - *(ValueType *)t2; }
@


1.1
log
@Initial revision
@
text
@d90 2
d107 1
@
