Ejemplo n.º 1
0
 /**
  * Tests whether this set is a subset of the specified set.
  * It is assumed that the specified set is an instance of
  * the MultisetAsArray class.
  *
  * @param object IMultiset $set The set to compare with this set.
  * @return boolean True if the this set is a subset of the specified set;
  * false otherwise.
  */
 public function isSubset(IMultiset $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;
 }
Ejemplo n.º 2
0
 /**
  * Tests whether this multiset is a subset of 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 this multiset is a subset of the specified multiset;
  * false otherwise.
  */
 public function isSubset(IMultiset $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) {
         $diff = $p->getDatum() . compare($q->getDatum());
         if ($diff == 0) {
             $p = $p->getNext();
             $q = $q->getNext();
         } elseif ($diff > 0) {
             $q = $q->getNext();
         } else {
             return false;
         }
     }
     if ($p !== NULL) {
         return false;
     } else {
         return true;
     }
 }