Polaris: IntSet Class Reference

IntSet Class Reference

A set of small, positive integers. More...

#include <IntSet.h>

List of all members.

Public Member Functions

 IntSet (unsigned int max_int=31)
 Create a new IntSet whose maximum integer value is the given value.
 IntSet (const IntSet &other)
 Copy constructor.
IntSetoperator= (const IntSet &)
 Make my set be equal to the given IntSet.
 ~IntSet ()
 Destructor.
int operator[] (unsigned int) const
 Return true if the given integer is in the set.
void ins (unsigned int)
void del (unsigned int)
 Insertion/deletion of elements in set.
void clear ()
 Remove all elements from the set.
int operator== (const IntSet &) const
 Return True if two sets are equal.
int operator!= (const IntSet &) const
 Return True if one set contains an element not in the other set.
int operator<= (const IntSet &) const
 Return True if I am a subset of the other set.
int operator>= (const IntSet &) const
 Return True if I am a superset of the other set.
int operator< (const IntSet &) const
 Return True if I am a proper subset of the other set.
int operator> (const IntSet &) const
 Return True if I am a proper superset of the other set.
int intersects_with (const IntSet &) const
 Return True if my set has at least one element in common with the other set.
const IntSet operator+ (const IntSet &) const
IntSet operator+ (const IntSet &)
const IntSet operator| (const IntSet &) const
IntSet operator| (const IntSet &)
 Return the union of the two sets.
const IntSet operator & (const IntSet &) const
IntSet operator & (const IntSet &)
 Return the intersection of the two sets.
const IntSet operator~ () const
IntSet operator~ ()
 Return the negation of myself.
IntSetnegate_in_place ()
 Assign the negation of myself to myself.
const IntSet operator- (const IntSet &other) const
IntSet operator- (const IntSet &other)
 Return the subtraction of the other set from my set.
IntSetoperator+= (const IntSet &)
IntSetoperator|= (const IntSet &)
IntSetoperator &= (const IntSet &)
IntSetoperator-= (const IntSet &)
 += -= |= etc for completeness.
int entries () const
 Number of entries in set.
int first () const
 Returns smallest integer in set.
int last () const
 Returns largest integer in set.
int next (unsigned int) const
 Returns the smallest integer in the set that is greater than the given integer.
int prev (unsigned int) const
 Returns the largest integer in the set that is smaller than the given integer.
void print (ostream &o) const
int structures_OK () const
 Return 1 if the internal data structures of myself are in a valid state.

Friends

ostream & operator<< (ostream &o, const IntSet &set)
 Print out the set.


Detailed Description

A set of small, positive integers.

Polaris Base

See also:
IntSet.h

IntSet.h

IntSet.cc

Overview

A IntSet object represents a set of small, positive integers. There is no limitation on the size of the integers placed in the set, but will be inefficient in both time and space if large integers are stored within it.

Description

An IntSet object represents a set of small, positive integers using a bit-vector implementation. Insertions and deletions take constant time while unions, intersections, and set comparisons take O(n) time, where n is the largest integer stored in the set. IntSets take up O(n) space. Because of these time and space bounds, IntSet objects are best used for relatively dense sets of integers with small magnitude. If one wishes to use sets containing large integers or large, sparse sets of integers, one should instead use the Set class (see Collection/Set.h and IntElem.h).

The first() and next() methods can be used to iterate over the elements of an IntSet. An example of this is:

for (int elem = int_set.first(); elem != -1; elem = int_set.next(elem)) { ... }

Iteration can also be done using the similar last() and prev() member functions.

IntSets will only take positive integers or zero.

Known Bugs or Limitations

The negation operation for IntSets is poorly implemented.

Definition at line 60 of file IntSet.h.


Constructor & Destructor Documentation

IntSet::IntSet unsigned int  max_int = 31  ) 
 

Create a new IntSet whose maximum integer value is the given value.

This integer value is not required, but may prevent unnecessary allocations and deletes as successively larger integers are placed in the set.

IntSet::IntSet const IntSet other  ) 
 

Copy constructor.

Definition at line 34 of file IntSet.cc.

References register_instance().

IntSet::~IntSet  )  [inline]
 

Destructor.

Definition at line 187 of file IntSet.h.


Member Function Documentation

IntSet & IntSet::operator= const IntSet  ) 
 

Make my set be equal to the given IntSet.

Definition at line 59 of file IntSet.cc.

References _data, and _max_size.

int IntSet::operator[] unsigned  int  )  const [inline]
 

Return true if the given integer is in the set.

Definition at line 197 of file IntSet.h.

void IntSet::ins unsigned  int  )  [inline]
 

Definition at line 206 of file IntSet.h.

Referenced by _annotate_expr(), _compute_private_kill_sets(), _make_nonlocals_modified_at_calls(), _remove_local_effects_from_expr1(), array_in_subscript(), PropConstIntMap::constant(), DFS_S(), LINK_S(), main(), and PropConstIntMap::PropConstIntMap().

void IntSet::del unsigned  int  )  [inline]
 

Insertion/deletion of elements in set.

Definition at line 221 of file IntSet.h.

Referenced by _annotate_expr(), _iterate_to_fixed_point_phase(), _make_nonlocals_modified_at_calls(), _remove_local_effects_from_expr1(), PropConstIntMap::constant(), Dominator_S(), main(), and PropConstIntMap::non_const().

void IntSet::clear  ) 
 

Remove all elements from the set.

Definition at line 50 of file IntSet.cc.

Referenced by PropConstIntMap::all_non_const(), Dominator_S(), and main().

int IntSet::operator== const IntSet  )  const
 

Return True if two sets are equal.

Definition at line 78 of file IntSet.cc.

int IntSet::operator!= const IntSet  )  const [inline]
 

Return True if one set contains an element not in the other set.

Definition at line 228 of file IntSet.h.

int IntSet::operator<= const IntSet  )  const
 

Return True if I am a subset of the other set.

Definition at line 107 of file IntSet.cc.

int IntSet::operator>= const IntSet  )  const [inline]
 

Return True if I am a superset of the other set.

Definition at line 234 of file IntSet.h.

int IntSet::operator< const IntSet  )  const [inline]
 

Return True if I am a proper subset of the other set.

Definition at line 240 of file IntSet.h.

int IntSet::operator> const IntSet  )  const [inline]
 

Return True if I am a proper superset of the other set.

Definition at line 246 of file IntSet.h.

int IntSet::intersects_with const IntSet  )  const
 

Return True if my set has at least one element in common with the other set.

Definition at line 131 of file IntSet.cc.

References _max_size.

Referenced by main().

const IntSet IntSet::operator+ const IntSet  )  const [inline]
 

Definition at line 260 of file IntSet.h.

IntSet IntSet::operator+ const IntSet  )  [inline]
 

Definition at line 268 of file IntSet.h.

const IntSet IntSet::operator| const IntSet  )  const [inline]
 

Definition at line 276 of file IntSet.h.

IntSet IntSet::operator| const IntSet  )  [inline]
 

Return the union of the two sets.

Definition at line 282 of file IntSet.h.

const IntSet IntSet::operator & const IntSet  )  const [inline]
 

Definition at line 288 of file IntSet.h.

IntSet IntSet::operator & const IntSet  )  [inline]
 

Return the intersection of the two sets.

Definition at line 296 of file IntSet.h.

const IntSet IntSet::operator~  )  const [inline]
 

Definition at line 320 of file IntSet.h.

IntSet IntSet::operator~  )  [inline]
 

Return the negation of myself.

Definition at line 328 of file IntSet.h.

IntSet & IntSet::negate_in_place  ) 
 

Assign the negation of myself to myself.

Definition at line 194 of file IntSet.cc.

const IntSet IntSet::operator- const IntSet other  )  const [inline]
 

Definition at line 304 of file IntSet.h.

IntSet IntSet::operator- const IntSet other  )  [inline]
 

Return the subtraction of the other set from my set.

Definition at line 312 of file IntSet.h.

IntSet & IntSet::operator+= const IntSet  ) 
 

Definition at line 145 of file IntSet.cc.

References _data.

IntSet & IntSet::operator|= const IntSet  )  [inline]
 

Definition at line 252 of file IntSet.h.

IntSet & IntSet::operator &= const IntSet  ) 
 

Definition at line 159 of file IntSet.cc.

References _data.

IntSet & IntSet::operator-= const IntSet  ) 
 

+= -= |= etc for completeness.

Definition at line 180 of file IntSet.cc.

References _data, and _max_size.

int IntSet::entries  )  const
 

Number of entries in set.

Definition at line 346 of file IntSet.cc.

Referenced by _iterate_to_fixed_point_phase(), _kill_bad_join_consts(), main(), and PropConstIntMap::structures_OK().

int IntSet::first  )  const
 

Returns smallest integer in set.

If there are no integers in the set, it returns -1.

Definition at line 236 of file IntSet.cc.

Referenced by _annotate_stmt(), _build_modified_vars(), _iterate_to_fixed_point_phase(), _kill_bad_join_consts(), insert_pseudo_assignment_stmts(), PropConstIntMap::operator==(), and print().

int IntSet::last  )  const
 

Returns largest integer in set.

If there are no integers in the set, it returns -1.

Definition at line 259 of file IntSet.cc.

int IntSet::next unsigned  int  )  const
 

Returns the smallest integer in the set that is greater than the given integer.

If there are no larger integers in the set, it returns -1.

Definition at line 282 of file IntSet.cc.

Referenced by _annotate_stmt(), _build_modified_vars(), _iterate_to_fixed_point_phase(), _kill_bad_join_consts(), insert_pseudo_assignment_stmts(), PropConstIntMap::operator==(), and print().

int IntSet::prev unsigned  int  )  const
 

Returns the largest integer in the set that is smaller than the given integer.

If there are no smaller integers in the set, it returns -1.

Definition at line 315 of file IntSet.cc.

void IntSet::print ostream &  o  )  const
 

Definition at line 362 of file IntSet.cc.

References first(), and next().

Referenced by operator<<(), and PropConstIntMap::print().

int IntSet::structures_OK  )  const
 

Return 1 if the internal data structures of myself are in a valid state.

Otherwise, print out an error and return 0.

Definition at line 389 of file IntSet.cc.

Referenced by PropConstWS::structures_OK(), PropConstIntMap::structures_OK(), PropConstValue::structures_OK(), and DeadCodeElimWS::structures_OK().


Friends And Related Function Documentation

ostream& operator<< ostream &  o,
const IntSet set
[friend]
 

Print out the set.

Definition at line 380 of file IntSet.cc.


The documentation for this class was generated from the following files:
 © 1995-2005 University of Illinois, Urbana-Champaign. All rights reserved.  Fri Mar 25 23:07:35 2005