コード例 #1
0
ファイル: Association.php プロジェクト: EdenChan/Instances
 /**
  * Compares this association with the specified comparable object.
  * The specified comparable object is assumed to be an Association instance.
  * The two associations are compared by comparing just their keys.
  *
  * @param object IComparable $obj
  * The object with which this object is compared.
  * @return integer A number less than zero if the key of this association
  * is less than the key of the specified one;
  * a number greater than zero if the key of this association
  * is greater than the key of the specified one;
  * zero if the keys of both associations are equal.
  */
 protected function compareTo(IComparable $obj)
 {
     return $this->key->compare($obj->getKey());
 }
コード例 #2
0
ファイル: BinaryTree.php プロジェクト: EdenChan/Instances
 /**
  * Compares this binary tree with the specified comparable object.
  * The specified comparable object is assumed to be a BinaryTree instance.
  *
  * @param object IComparable $obj
  * The comparable object with which to compare this
  * binary tree.
  * @return integer A number less than zero if this binary tree is less
  * than the specified binary tree;
  * greater than zero if this binary tree is greater
  * than the specified binary tree;
  * zero if the two trees are identical.
  */
 protected function compareTo(IComparable $obj)
 {
     if ($this->isEmpty()) {
         return $obj->isEmpty() ? 0 : -1;
     } elseif ($obj->isEmpty()) {
         return 1;
     } else {
         $result = $this->getKey()->compare($obj->getKey());
         if ($result == 0) {
             $result = $this->getLeft()->compare($obj->getLeft());
         }
         if ($result == 0) {
             $result = $this->getRight()->compare($obj->getRight());
         }
         return $result;
     }
 }