예제 #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();
         }
     }
 }
예제 #2
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();
 }