note 126832 added to intro.ds
| From: | immemosol at main dot php dot net | Date: | Mon, 07 Feb 2022 14:36:00 +0000 |
| Subject: | note 126832 added to intro.ds | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-217587@lists.php.net to get a copy of this message | ||
A summary of the namespace.
Known big O notations
ClassName | add | contains | get | hasKey | insert | pop | push | put | remove | set |
shift | unshift |
Vector | _ | ? | O(1) | _ | O(n) | O(1) | O(1) | _ | O(n) | O(1) |
O(n) | O(n) |
Stack | _ | _ | _ | _ | _ | ? | _ | _ | _ | _ |
_ | _ |
Set | O(1) | O(1) | O(n OR 1) | _ | _ | _ | _ | _ | O(1) | _ |
_ | _ |
Queue | _ | _ | _ | _ | _ | ? | ? | _ | _ | _ |
_ | _ |
PriorityQueue | _ | _ | _ | _ | _ | ? | ? | _ | _ | _ |
_ | _ |
Map | _ | _ | O(1) | O(1) | _ | _ | _ | O(1) | O(1) | _ |
_ | _ |
Deque | _ | ? | O(1) | ? | ? | O(1) | O(1) | _ | ? | O(1) |
O(1) | O(1) |
? = method is available and big O is unknown.
_ = method is unavailable, although comparable behavior could be available
For example:
$object[] = ''; as an alternative to
$object->push('');.
Except for PriorityQueue, all other classes
(Deque, Map, Queue, Set, Stack, Vector) implement ArrayAccess,
Main:
- interface Sequence: Collection + ArrayAccess
- interface Collection: Traversable, Countable, JsonSerializable
- Vector: Sequential structure, low memory usage
- Stack: Destructive Iteration; LIFO (Last In, First Out)
note: can only access the item at the top of the stack
- Set: Hashable, Unique Values
- Queue: Destructive Iteration; FIFO (First In, First Out)
note: can only access the item at the front of the stack
- PriorityQueue: Destructive Iteration; FIFO + Priority
Like Queue but priority determines order first, FIFO when equal priority
- Map: Hashable, Key Value Sequence (like array in comparable context)
memory usage: like array, clears memory more often
note: can use objects as keys, but that inhibits array conversion
- Deque: Double Ended Queue, low memory usage
note: buffer capacity must be ^2 (a power of 2)
Supporting:
- interface Hashable: allows objects to be used as keys (->hash() &
->equals(), falls back to spl_object_hash())
- class Pair: JsonSerializable, Key Value Pair, used by Map
- and some more.
----
Server IP: 45.112.84.4
Probable Submitter: 80.90.5.135 (proxied: 213.136.12.151)
----
Manual Page -- https://php.net/manual/en/intro.ds.php
Edit -- https://main.php.net/note/edit/126832
Del: integrated -- https://main.php.net/note/delete/126832/integrated
Del: useless -- https://main.php.net/note/delete/126832/useless
Del: bad code -- https://main.php.net/note/delete/126832/bad+code
Del: spam -- https://main.php.net/note/delete/126832/spam
Del: non-english -- https://main.php.net/note/delete/126832/non-english
Del: in docs -- https://main.php.net/note/delete/126832/in+docs
Del: other reasons-- https://main.php.net/note/delete/126832
Reject -- https://main.php.net/note/reject/126832
Search -- https://main.php.net/manage/user-notes.php