Example #1
0
 /**
  * Tests whether this set is equal to the specified set.
  * It is assumed that the specified set is an instance of
  * the <code>SetAsBitVector</code> class.
  *
  * @param object ISet $set The set to compare with this set.
  * @return boolean True if the sets are equal; false otherwise.
  */
 public function eq(IComparable $set)
 {
     if ($this->getClass() != $set->getClass()) {
         throw new TypeError();
     }
     if ($this->universeSize != $set->universeSize) {
         throw new ArgumentError();
     }
     for ($i = 0; $i < $this->vector->getLength(); ++$i) {
         if ($this->vector[$i] != $set->vector[$i]) {
             return false;
         }
     }
     return true;
 }
 /**
  * Compares this object with the given object.
  *
  * @param object IComparable $object A comparable object.
  * @return integer A number less than zero
  * if this object is less than the given object,
  * zero if this object equals the given object, and
  * a number greater than zero
  * if this object is greater than the given object.
  */
 public function compare(IComparable $object)
 {
     $result = 0;
     if ($this->getClass() == $object->getClass()) {
         $result = $this->compareTo($object);
     } else {
         $result = strcmp($this->getClass()->getName(), $object->getClass()->getName());
     }
     return $result;
 }
Example #3
0
 /**
  * Tests whether this set is equal to the specified set.
  * It is assumed that the specified set is an instance of
  * the SetAsArray class.
  *
  * @param object ISet $set The set to compare with this set.
  * @return boolean True if the sets are equal; false otherwise.
  */
 public function eq(IComparable $set)
 {
     if ($this->getClass() != $set->getClass()) {
         throw new TypeError();
     }
     if ($this->universeSize != $set->universeSize) {
         throw new ArgumentError();
     }
     for ($item = 0; $item < $this->universeSize; ++$item) {
         if ($this->array[$item] != $set->array[$item]) {
             return false;
         }
     }
     return true;
 }
 /**
  * Tests whether this multiset is equal to the specified multiset.
  * It is assumed that the specified multiset is an instance of
  * the MultisetAsLinkedList class.
  *
  * @param IMultiset $multiset The multiset to compare with this multiset.
  * @return boolean True if the multisets are equal; false otherwise.
  */
 public function eq(IComparable $set)
 {
     if ($this->getClass() != $set->getClass()) {
         throw new TypeError();
     }
     if ($this->universeSize != $set->universeSize) {
         throw new ArgumentError();
     }
     $p = $this->list->getHead();
     $q = $set->list->getHead();
     while ($p !== NULL && $q !== NULL) {
         if (ne($p->getDatum(), $q->getDatum())) {
             return false;
         }
         $p = $p->getNext();
         $q = $q->getNext();
     }
     if ($p !== NULL || $q !== NULL) {
         return false;
     } else {
         return true;
     }
 }