2017 © Pedro Peláez
 

library set

java.utils.Set for PHP implementing ArrayAccess, Countable and IteratorAggregate with O(1) conversion to/from array keys

image

jesseschalken/set

java.utils.Set for PHP implementing ArrayAccess, Countable and IteratorAggregate with O(1) conversion to/from array keys

  • Tuesday, March 29, 2016
  • by jesseschalken
  • Repository
  • 1 Watchers
  • 0 Stars
  • 6,338 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 7 % Grown

The README.md

php-set

java.utils.Set for PHP implementing ArrayAccess, Countable, IteratorAggregate with O(1) conversion to/from array keys., (*1)

Uses array_replace(), array_intersect_key() and array_diff_key() for fast union, intersection and difference (addAll(), retainAll(), removeAll())., (*2)

use JesseSchalken\Set;

// Create a set from an array, Set or Traversable
$set = new Set([1, 2, 3]);
$set = new Set($set);
$set = new Set(new \ArrayIterator($set->toArray()));

// Add and remove elements
$set->add(4);
$set->remove(2);
var_export($set->contains(4)); // true
var_export($set->contains(2)); // false

// Clear and check if empty
$set->clear();
var_export($set->isEmpty()); // true

// Add and remove other arrays, Sets or Traversables 
$set->addAll(['red', 'green', 'blue', 54]);
$set->removeAll(new \ArrayObject(['green', 54]));

// Check subset/superset
var_export($set->containsAll(new Set(['red', 'blue']))); // true
var_export($set->toArray()); // ['red', 'blue']

// Intersect another array, Set or Traversable
$set->retainAll(['blue', 'green']);
var_export($set->toArray()); // ['blue']
var_export($set->size()); // 1
var_export($set->equals(['blue'])); // true

// Convert to array keys
$set = new Set([1, 2]);
var_export($set->toArrayKeys()); // [1 => true, 2 => true]

// Convert from array keys
$set = Set::fromArrayKeys([7 => true, 3 => 'string']);
var_export($set->toArray()); // [7, 3]

// Use ArrayAccess
$set = new Set();
$set['red']   = true; // add
$set['green'] = true; // add
$set['red']   = false; // remove
var_export($set['green']); // true
var_export($set['blue']); // false
var_export($set['red']); // false

// Use IteratorAggregate
foreach ($set as $v) {
    var_export($v); // blue
}

// Use Countable
var_export(count($set)); // 1

The Versions

29/03 2016

dev-master

9999999-dev

java.utils.Set for PHP implementing ArrayAccess, Countable and IteratorAggregate with O(1) conversion to/from array keys

  Sources   Download

MIT

The Development Requires

by Jesse Schalken

18/01 2016

v1.0.2

1.0.2.0

java.utils.Set for PHP implementing ArrayAccess, Countable and IteratorAggregate with O(1) conversion to/from array keys

  Sources   Download

MIT

The Development Requires

by Jesse Schalken

15/01 2016

v1.0.1

1.0.1.0

java.utils.Set for PHP implementing ArrayAccess, Countable and IteratorAggregate with O(1) conversion to/from array keys

  Sources   Download

MIT

The Development Requires

by Jesse Schalken

15/01 2016

v1.0

1.0.0.0

java.utils.Set for PHP implementing ArrayAccess, Countable and IteratorAggregate with O(1) conversion to/from array keys

  Sources   Download

MIT

The Requires

 

by Jesse Schalken