Ejemplo n.º 1
0
 /**
  * This method compares the specified object with the current object for order.
  *
  * @access public
  * @static
  * @param IHashSet\Type $xs                                 the left operand
  * @param IHashSet\Type $ys                                 the object to be compared
  * @return ITrit\Type                                       whether the current object is less than,
  *                                                          equal to, or greater than the specified
  *                                                          object
  */
 public static function compare(IHashSet\Type $xs, IHashSet\Type $ys) : ITrit\Type
 {
     $x_length = $xs->__size();
     $y_length = $ys->__size();
     if ($x_length == $y_length) {
         $xi = IHashSet\Module::iterator($xs);
         foreach ($xi as $x) {
             if (!$ys->__hasItem($x)) {
                 return ITrit\Type::make(strcmp((string) serialize($xs), (string) serialize($ys)));
                 // order is not "stable"
             }
         }
         return ITrit\Type::zero();
     } else {
         if ($x_length < $y_length) {
             return ITrit\Type::negative();
         } else {
             // ($x_length > $y_length)
             return ITrit\Type::positive();
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * This method tests that a value is of a particular size.
  *
  * @dataProvider dataSize
  */
 public function testSize(array $provided, array $expected)
 {
     //$this->markTestIncomplete();
     $p0 = IHashSet\Type::make($provided)->size();
     $this->assertInstanceOf('\\Saber\\Data\\IInt32\\Type', $p0);
     $p1 = $p0->unbox();
     $e1 = $expected[0];
     $this->assertSame($e1, $p1);
 }
Ejemplo n.º 3
0
 /**
  * This method returns a value as a boxed object.  A value is typically a PHP typed
  * primitive or object.  It is considered type-safe.
  *
  * @access public
  * @static
  * @param mixed ...$xs                                      the value(s) to be boxed
  * @return IHashSet\Type                                    the boxed object
  */
 public static function make2(...$xs) : IHashSet\Type
 {
     return IHashSet\Type::make($xs);
 }
Ejemplo n.º 4
0
 /**
  * This method returns the size of the collection.
  *
  * @access public
  * @final
  * @return int                                              the size of the collection
  */
 public final function count() : int
 {
     return $this->xs->__size();
 }
Ejemplo n.º 5
0
 /**
  * This method returns an array list containing only unique items from the specified
  * array list (i.e. duplicates are removed).
  *
  * @access public
  * @static
  * @param IArrayList\Type $xs                               the array list to be processed
  * @return IArrayList\Type                                  an array list with the duplicates
  *                                                          removed
  */
 public static function nub(IArrayList\Type $xs) : IArrayList\Type
 {
     $zs = IHashSet\Type::empty_();
     return IArrayList\Module::filter($xs, function (Core\Type $x, IInt32\Type $i) use($zs) : IBool\Type {
         if ($zs->__hasItem($x)) {
             return IBool\Type::false();
         }
         $zs->putItem($x);
         return IBool\Type::true();
     });
 }