• PHP Video Tutorials

PHP - Set Functions


Advertisements

Set is a sequence of unique values, and this implementation can use the same hash table as Ds\Map where the values are used as keys, and the mapped value is ignored.

Strengths

  • Values can be any type, including objects.
  • Supports array syntax (square brackets).
  • Insertion order is preserved.
  • Automatically frees allocated memory when its size drops low enough.
  • add(), remove() and contains() are all O(1).

Weaknesses

  • Doesn’t support push(), pop(), insert(), shift(), or unshift().
  • get() is O(n) if there are deleted values in the buffer before the accessed index, O(1) otherwise.

Class synopsis

Ds\Set implements Ds\Collection {
   /* Constants */
   const int MIN_CAPACITY = 16 ;

   /* Methods */
   public void add([ mixed $...values ] )
   public void allocate( int $capacity )
   public int capacity( void )
   public void clear( void )
   public bool contains([ mixed $...values ] )
   public Ds\Set copy( void )
   public Ds\Set diff( Ds\Set $set )
   public Ds\Set filter([ callable $callback ] )
   public void first( void )
   public mixed get( int $index )
   public Ds\Set intersect( Ds\Set $set )
   public bool isEmpty( void )
   public string join([ string $glue ] )
   public void last( void )
   public Ds\Set merge( mixed $values )
   public mixed reduce( callable $callback [, mixed $initial ] )
   public void remove([ mixed $...values ] )
   public void reverse( void )
   public Ds\Set reversed( void )
   public Ds\Set slice( int $index [, int $length ] )
   public void sort([ callable $comparator ] )
   public Ds\Set sorted([ callable $comparator ] )
   public number sum( void ) 
   public array toArray( void )
   public Ds\Set union( Ds\Set $set )
   public Ds\Set xor( Ds\Set $set )
}

Predefined Constants

Ds\Set::MIN_CAPACITY

Sr.No Function & Description
1

Ds\Set::allocate()

This Function can allocate enough memory for the required capacity.

2

Ds\Set::add()

This Function can can add values to the set.

3

Ds\Set::capacity()

This Function can return the current capacity.

4

Ds\Set::clear()

This Function can remove the all values.

5

Ds\Set::__construct()

This Function can create a new instance.

6

Ds\Set::contains()

This Function can determine if the set contains all values.

7

Ds\Set::copy()

This Function can return a shallow copy of the set.

8

Ds\Set::count

This Function can be used to count the number of values present in a set, and also referred to as the size of a set instance.

9

Ds\Set::diff()

This Function can create a new set by using the values that aren't in another set.

10

Ds\Sequence::filter()

This Function can create the new set by using a callable to determine which values to include.

11

Ds\Set::first()

This Function can return the first value in a set.

12

Ds\Set::get()

This Function can return the value at a given index.

13

Ds\Set::intersect()

This Function can create a new set by intersecting the values with another set.

14

Ds\Set::isEmpty()

This Function can return whether the set is empty.

15

Ds\Set::join()

This Function can join all values together as a string.

16

Ds\Set::jsonSerialize()

This Function can return a representation that can be converted to JSON.

17

Ds\Set::last()

This Function can return the last value in a set.

18

Ds\Set::merge()

This Function can return the result of adding all given values to a set.

19

Ds\Set::reduce()

This Function can reduce a set to single value by using callback function.

20

Ds\Set::remove()

This Function can remove all given values from the set.

21

Ds\Set::reverse()

This Function can can reverse a set in-place.

22

Ds\Set::reversed()

This Function can return a reversed copy.

23

Ds\Set::slice()

This Function can return the sub-set of a given range.

24

Ds\Set::sort()

This Function can sort a set in-place.

25

Ds\Set::sorted()

This Function can return a sorted copy.

26

Ds\Set::sum()

This Function can return the sum of all values in a set.

27

Ds\Set::toArray()

This Function can convert a set to an array.

28

Ds\Set::union()

This Function can create a new set by using values from the current instance and another set.

29

Ds\Set::xor()

This Function can create a new set by using the values in the current instance and another set but not in both.

php_function_reference.htm

Useful Video Courses


Video

PHP Online Training

45 Lectures 9 hours

Malhar Lathkar

Video

Become PHP Facebook Developer: Password-Less Authentication

34 Lectures 4 hours

Syed Raza

Video

Ultimate PHP & MySQL Web Development Course & OOP Coding

84 Lectures 5.5 hours

Frahaan Hussain

Video

Learn PHP from Scratch

17 Lectures 1 hours

Nivedita Jain

Video

E Commerce Website Development In PHP With PDO

100 Lectures 34 hours

Azaz Patel

Video

PHP in Telugu

43 Lectures 5.5 hours

Vijay Kumar Parvatha Reddy

Advertisements