Пример #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 <code>SetAsBitVector</code> class.
  *
  * @param object ISet $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(ISet $set)
 {
     if ($this->getClass() != $set->getClass()) {
         throw new TypeError();
     }
     if ($this->universeSize != $set->universeSize) {
         throw new ArgumentError();
     }
     for ($i = 0; $i < $this->vector->length(); ++$i) {
         if (($this->vector[$i] & ~$set->vector[$i]) != 0) {
             return false;
         }
     }
     return true;
 }
Пример #2
0
 /**
  * Set test method.
  *
  * @param object ISet $s1 A set to test.
  * @param object ISet $s2 A set to test.
  * @param object ISet $s3 A set to test.
  */
 public static function test(ISet $s1, ISet $s2, ISet $s3)
 {
     printf("AbstractSet test program.\n");
     for ($i = 0; $i < 4; ++$i) {
         $s1->insert(box($i));
     }
     for ($i = 2; $i < 6; ++$i) {
         $s2->insert(box($i));
     }
     $s3->insert(box(0));
     $s3->insert(box(2));
     printf("%s\n", str($s1));
     printf("%s\n", str($s2));
     printf("%s\n", str($s3));
     printf("%s\n", str($s1->union($s2)));
     # union
     printf("%s\n", str($s1->intersection($s3)));
     # intersection
     printf("%s\n", str($s1->difference($s3)));
     # difference
     printf("Using foreach\n");
     foreach ($s3 as $obj) {
         printf("%s\n", str($obj));
     }
     printf("Using reduce\n");
     $s3->reduce(create_function('$sum,$obj', 'printf("%s\\n", str($obj));'), '');
 }
Пример #3
0
 /**
  * Tests whether this set is a subset of 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 this set is a subset of the specified set;
  * false otherwise.
  */
 public function isSubset(ISet $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;
 }
Пример #4
0
 public function copyAll(ISet $set)
 {
     $this->addAll($set->getAll());
 }