
- PHP Tutorial
- PHP - Home
- PHP - Introduction
- PHP - Environment Setup
- PHP - Syntax Overview
- PHP - Variable Types
- PHP - Constants
- PHP - Operator Types
- PHP - Decision Making
- PHP - Loop Types
- PHP - Arrays
- PHP - Strings
- PHP - Web Concepts
- PHP - GET & POST
- PHP - File Inclusion
- PHP - Files & I/O
- PHP - Functions
- PHP - Cookies
- PHP - Sessions
- PHP - Sending Emails
- PHP - File Uploading
- PHP - Coding Standard
- Advanced PHP
- PHP - Predefined Variables
- PHP - Regular Expression
- PHP - Error Handling
- PHP - Bugs Debugging
- PHP - Date & Time
- PHP & MySQL
- PHP & AJAX
- PHP & XML
- PHP - Object Oriented
- PHP - For C Developers
- PHP - For PERL Developers
- PHP Form Examples
- PHP - Form Introduction
- PHP - Validation Example
- PHP - Complete Form
- PHP login Examples
- PHP - Login Example
- PHP - Facebook Login
- PHP - Paypal Integration
- PHP - MySQL Login
- PHP AJAX Examples
- PHP - AJAX Search
- PHP - AJAX XML Parser
- PHP - AJAX Auto Complete Search
- PHP - AJAX RSS Feed Example
- PHP XML Example
- PHP - XML Introduction
- PHP - Simple XML
- PHP - Simple XML GET
- PHP - SAX Parser Example
- PHP - DOM Parser Example
- PHP Frame Works
- PHP - Frame Works
- PHP - Core PHP vs Frame Works
- PHP Design Patterns
- PHP - Design Patterns
- PHP Function Reference
- PHP - Built-In Functions
- PHP Useful Resources
- PHP - Questions & Answers
- PHP - Useful Resources
- PHP - Discussion
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
PHP - Set Functions
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 |
This Function can allocate enough memory for the required capacity. |
2 |
This Function can can add values to the set. |
3 |
This Function can return the current capacity. |
4 |
This Function can remove the all values. |
5 |
This Function can create a new instance. |
6 |
This Function can determine if the set contains all values. |
7 |
This Function can return a shallow copy of the set. |
8 |
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 |
This Function can create a new set by using the values that aren't in another set. |
10 |
This Function can create the new set by using a callable to determine which values to include. |
11 |
This Function can return the first value in a set. |
12 |
This Function can return the value at a given index. |
13 |
This Function can create a new set by intersecting the values with another set. |
14 |
This Function can return whether the set is empty. |
15 |
This Function can join all values together as a string. |
16 |
This Function can return a representation that can be converted to JSON. |
17 |
This Function can return the last value in a set. |
18 |
This Function can return the result of adding all given values to a set. |
19 |
This Function can reduce a set to single value by using callback function. |
20 |
This Function can remove all given values from the set. |
21 |
This Function can can reverse a set in-place. |
22 |
This Function can return a reversed copy. |
23 |
This Function can return the sub-set of a given range. |
24 |
This Function can sort a set in-place. |
25 |
This Function can return a sorted copy. |
26 |
This Function can return the sum of all values in a set. |
27 |
This Function can convert a set to an array. |
28 |
This Function can create a new set by using values from the current instance and another set. |
29 |
This Function can create a new set by using the values in the current instance and another set but not in both. |