当前位置: 首页>>代码示例>>PHP>>正文


PHP Set::add方法代码示例

本文整理汇总了PHP中Set::add方法的典型用法代码示例。如果您正苦于以下问题:PHP Set::add方法的具体用法?PHP Set::add怎么用?PHP Set::add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Set的用法示例。


在下文中一共展示了Set::add方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: whenIteratingOverSet_ThenReturnAllUniqueItems

 /**
  * @test
  */
 public function whenIteratingOverSet_ThenReturnAllUniqueItems()
 {
     $item1 = 'A';
     $item2 = 'B';
     $set = new Set();
     $set->add($item1);
     $set->add($item2);
     $values = array();
     foreach ($set as $key => $value) {
         $values[$key] = $value;
     }
     $this->assertEquals(array(0 => 'A', 1 => 'B'), $values);
 }
开发者ID:roozbehmatloobi,项目名称:php-refactoring-browser,代码行数:16,代码来源:SetTest.php

示例2: add

 /**
  * Unsupported method
  * @throws Exception every time
  */
 public function add($const = '')
 {
     if ($this->inC) {
         return parent::add($const);
     }
     throw new Exception("You are not allowed to modify this set");
 }
开发者ID:sheepguru,项目名称:php-enum-set,代码行数:11,代码来源:ConstSet.php

示例3: testMember

 public function testMember()
 {
     $set = new Set(array(1, 2, 3));
     self::assertFalse($set->member(4));
     self::assertTrue($set->member(1));
     $set->add(4);
     self::assertTrue($set->member(4));
 }
开发者ID:enddering,项目名称:antlr-php-runtime,代码行数:8,代码来源:SetTest.php

示例4: testRemove

 public function testRemove()
 {
     $set1 = new Set();
     $set2 = new Set([100, 200]);
     $set1->add(200);
     $set1->add(300);
     $set2->retainAll($set1);
     $this->assertEquals($set1->toArray(), [200, 300]);
     $this->assertEquals($set2->toArray(), [200]);
     $this->assertFalse($set1->equals($set2));
     $this->assertFalse($set2->equals($set1));
     $set1->remove(300);
     $this->assertTrue($set1->equals($set2));
     $this->assertTrue($set2->equals($set1));
     $set1->removeAll($set2);
     $this->assertTrue($set1->isEmpty());
     $this->assertFalse($set2->isEmpty());
 }
开发者ID:jesseschalken,项目名称:php-set,代码行数:18,代码来源:SetTest.php

示例5: difference

 public function difference(Set $other)
 {
     $difference_set = new Set();
     foreach ($this as $item) {
         if (!$other->contains($item)) {
             $difference_set->add($item);
         }
     }
     return $difference_set;
 }
开发者ID:thumbtack,项目名称:crankshaft,代码行数:10,代码来源:Set.php

示例6: testResumesIterationAfterConvertingToArray

 /**
  * @dataProvider sampleNumbers
  */
 public function testResumesIterationAfterConvertingToArray($numbers)
 {
     $set = new Set(\Cassandra::TYPE_INT);
     foreach ($numbers as $number) {
         $set->add($number);
     }
     $this->assertEquals(1, $set->current());
     $set->next();
     $this->assertEquals(2, $set->current());
     $set->next();
     $this->assertEquals(3, $set->current());
     $set->values();
     $set->next();
     $this->assertEquals(4, $set->current());
     $set->next();
     $this->assertEquals(5, $set->current());
     $set->next();
     $this->assertEquals(6, $set->current());
 }
开发者ID:Dylan1312,项目名称:php-driver,代码行数:22,代码来源:SetTest.php

示例7: testPartialUserType

 /**
  * User type using a partial user type value.
  *
  * This test will ensure that the PHP driver supports the user types. This
  * test uses a partial user type where some values will not be assigned.
  *
  * @test
  * @ticket PHP-57
  */
 public function testPartialUserType()
 {
     // Alias missing from a single number
     $phone = $this->getPhoneUserType();
     $phone->set("number", "000-000-0000");
     $numbers = new Set($phone->type());
     $numbers->add($phone);
     $address = UserTypeIntegrationTest::getAddressUserType();
     $address->set("street", "123 Missing Alias Street");
     $address->set("zip", 00);
     $address->set("phone_numbers", $numbers);
     $key = $this->insertAddress($address);
     $this->assertAddressValue($this->selectAddress($key), $address);
     // Missing/NULL values during insert
     $address = UserTypeIntegrationTest::getAddressUserType();
     $address->set("street", "1 Furzeground Way");
     $key = $this->insertAddress($address);
     $address->set("zip", null);
     // Add null 'zip' to assert properly (Server will default null values)
     $address->set("phone_numbers", null);
     // Add null 'phone_numbers' (same as above)
     $this->assertAddressValue($this->selectAddress($key), $address);
 }
开发者ID:harley84,项目名称:php-driver,代码行数:32,代码来源:UserTypeIntegrationTest.php

示例8: testSupportsRetrievingValues

 public function testSupportsRetrievingValues()
 {
     $values = array(new Varint('1'), new Varint('2'), new Varint('3'), new Varint('4'), new Varint('5'), new Varint('6'), new Varint('7'), new Varint('8'));
     $set = new Set(\Cassandra::TYPE_VARINT);
     for ($i = 0; $i < count($values); $i++) {
         $set->add($values[$i]);
     }
     $this->assertEquals($values, $set->values());
 }
开发者ID:r3nat,项目名称:php-driver,代码行数:9,代码来源:SetTest.php

示例9: addIf

 private function addIf(Set $to, Set $from, callable $f)
 {
     foreach ($from as $value) {
         if ($f($value)) {
             $to->add($value);
         }
     }
 }
开发者ID:pramoddas,项目名称:Ardent,代码行数:8,代码来源:AbstractSet.php

示例10: powerSet

 /**
  * Power set P(S)
  * The set of all subsets of S, including the empty set and S itself.
  *
  * Example:
  *  S = {x, y, z}
  *  P(S) = {Ø, {x}, {y}, {z}, {x,y}, {x,z}, {y,z}, {x,y,z}}
  *
  * Algorithm:
  *  Setup:
  *   - n:     size of the original set
  *   - 2ⁿ:    size of the power set
  *   - A:     original set as an array with numbered indices 0 to n - 1
  *   - P(S):  power set to be created
  *
  *  Iterative loop algorithm:
  *   - Loop i from 0 to < 2ⁿ
  *    - Create empty temporary Set
  *    - Loop j from 0 to < n
  *      - If the jᵗʰ bit of the i counter is set, add A[j] to temporary Set
  *    - Add temporary set to power set
  *
  * Time complexity: O(n2ⁿ)
  * Reference: http://www.geeksforgeeks.org/power-set/
  *
  * @return Set
  */
 public function powerSet() : Set
 {
     // Setup
     $n = count($this->A);
     // Size of the original set
     $2ⁿ = pow(2, $n);
     // Size of the power set
     $A = array_values($this->A);
     //  Original set as an array with numbered indices
     $P⟮S⟯ = new Set();
     //  Power set to be created
     // Populate power set
     for ($i = 0; $i < $2ⁿ; $i++) {
         $member_set = new Set();
         for ($j = 0; $j < $n; $j++) {
             if ($i & 1 << $j) {
                 $member_set->add($A[$j]);
             }
         }
         $P⟮S⟯->add($member_set);
     }
     return $P⟮S⟯;
 }
开发者ID:markrogoyski,项目名称:math-php,代码行数:50,代码来源:Set.php

示例11: testFirst

 public function testFirst()
 {
     $element = $this->items['alpha'];
     $this->object->add($element);
     $this->assertEquals($element, $this->object->first());
 }
开发者ID:versionable,项目名称:common,代码行数:6,代码来源:TreeSetTest.php

示例12: addAppender

 /**
  * @param ILogAppender $appender
  * @return ILoggerCategory
  */
 public function addAppender(ILogAppender $appender)
 {
     $this->appenders->add($appender);
     return $this;
 }
开发者ID:nikelin,项目名称:php-slf4j,代码行数:9,代码来源:logger.php

示例13: difference

 /**
  * Returns the set of values that are in this set, excluding the values that
  * are also in the other set.
  *
  * @param Api\Set|Iterator|array $set
  *
  * @return Api\Set
  */
 public function difference($set)
 {
     $differenceSet = new Set();
     foreach ($this as $value) {
         if ($set->has($value)) {
             $differenceSet->add($value);
         }
     }
     return $differenceSet;
 }
开发者ID:kgodet,项目名称:Aldente,代码行数:18,代码来源:Set.php


注:本文中的Set::add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。