Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

idep_binrel.h

Go to the documentation of this file.
00001 // idep_binrel.h
00002 #ifndef INCLUDED_IDEP_BINREL
00003 #define INCLUDED_IDEP_BINREL
00004 
00005 // This leaf component defines 1 class:
00006 //   idep_BinRel: Square matrix of bits with transitive closure capability.
00007 
00008 #include <iosfwd>
00009 
00010 class idep_BinRel {
00011     char **d_rel_p;     // array of pointers into a contiguous byte array
00012     int d_size;         // physical size of array
00013     int d_length;       // logical size of array
00014 
00015   private:
00016     void grow();
00017       // Increase the physical size of this relation.
00018 
00019     void compress();
00020       // Make the physical size same as Logical size (unless that is 0).
00021 
00022     void warshall(int bit);
00023       // Perform Warshall's algorithm either forward or backward. 
00024 
00025   public:
00026     // CREATORS
00027     idep_BinRel(int initialEntries = 0, int maxEntriesHint = 0);
00028         // Create a binary relation that can be extended as needed.
00029         // By default, the initial number of entires in the relation
00030         // is 0.  If the final number of entries is known and is not
00031         // the same as initialEntries, that value may optionally be
00032         // specified as the second argument (as a "hint").
00033 
00034     idep_BinRel(const idep_BinRel& rel);
00035     ~idep_BinRel();
00036 
00037     // MANIPULATORS
00038     idep_BinRel& operator=(const idep_BinRel& rel);
00039 
00040     void set(int row, int col, int bit);
00041         // Set the specified row/col of this relation to the specified 
00042         // binary value.
00043 
00044     void set(int row, int col);
00045         // Set the specified row/col of this relation to 1.
00046 
00047     void clr(int row, int col);
00048         // Set specified row/col of this relation to 0.
00049 
00050     void makeTransitive();
00051         // Apply Warshall's algorithm to this relation.  The result is the
00052         // reflexive transitive closure of the original relation.
00053 
00054     void makeNonTransitive();
00055         // Remove all redundant relationships such that the transitive
00056         // closure would be left unaffected.  In cases where there is
00057         // a cyclic dependency, the solution is not unique.  To work 
00058         // properly, the relation must already be fully transitive 
00059         // (see makeTransitive).
00060 
00061     int appendEntry();
00062         // Append an entry to this relation and return its integer index.
00063         // The logical size is increased by 1 with all new entries 0'ed.
00064 
00065     // ACCESSORS
00066     int get(int row, int col) const;
00067         // Get the boolean value at the specified row/col of this relation.
00068 
00069     int cmp(const idep_BinRel& rel) const;
00070         // Return 0 if and only if the specified relation has the same
00071         // length and logical values as this relation.
00072 
00073     int length() const;
00074         // Return number of rows and columns in this relation.  The length
00075         // represents the cardinality of the set on which this relation is
00076         // defined.
00077 };
00078 
00079 std::ostream& operator<<(std::ostream& out, const idep_BinRel& rel);
00080    // Output this binary relation in row/column format with the upper left 
00081    // corner as the origin to the specified output stream (out).
00082 
00083 int operator==(const idep_BinRel& left, const idep_BinRel& right);
00084    // Return 1 if two relations are equal, and 0 otherwise (see cmp).
00085 
00086 int operator!=(const idep_BinRel& left, const idep_BinRel& right);
00087    // Return 1 if two relations are not equal, and 0 otherwise (see cmp).
00088 
00089 
00090 // #########################################################################
00091 // The following consists of inline function definitions for this component. 
00092 // #########################################################################
00093 
00094 inline
00095 int idep_BinRel::appendEntry() 
00096 {
00097     if (d_length >= d_size) {
00098         grow();
00099     }
00100     return d_length++;
00101 }
00102 
00103 inline
00104 void idep_BinRel::set(int row, int col, int bit) 
00105 {
00106     d_rel_p[row][col] = !!bit;
00107 }
00108 
00109 inline
00110 void idep_BinRel::set(int row, int col) 
00111 {
00112     d_rel_p[row][col] = 1;
00113 }
00114 
00115 inline
00116 void idep_BinRel::clr(int row, int col) 
00117 {
00118     d_rel_p[row][col] = 0;
00119 }
00120 
00121 inline
00122 int idep_BinRel::get(int row, int col) const
00123 {
00124     return d_rel_p[row][col];
00125 }
00126 
00127 inline
00128 int idep_BinRel::length() const
00129 {
00130     return d_length;
00131 }
00132 
00133 inline
00134 int operator==(const idep_BinRel& left, const idep_BinRel& right) 
00135 {
00136     return left.cmp(right) == 0;
00137 }
00138 
00139 inline
00140 int operator!=(const idep_BinRel& left, const idep_BinRel& right) 
00141 {
00142     return left.cmp(right) != 0;
00143 }
00144 
00145 #endif
00146 

Generated on Mon Feb 15 11:06:48 2010 for loon by  doxygen 1.3.9.1