Last active
February 12, 2019 16:59
-
-
Save morrisonlevi/3a5d6a1c23c0eed69be52f77cce3d6ed to your computer and use it in GitHub Desktop.
Brainstorming the interfaces for Deque, Queue, and Stack.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Spl; | |
/** | |
* Indicates that a structure is designed to operate efficiently at both the | |
* front and the back of a dataset. | |
* @template T | |
*/ | |
interface Deque | |
extends \Countable, \IteratorAggregate | |
{ | |
/** | |
* Prepends the given value to the front of the structure. | |
* @psalm-param T $value | |
*/ | |
function push_front($value); | |
/** | |
* Removes and returns the first value of the structure. | |
* | |
* @psalm-return T The value that was removed from the front of the structure. | |
* | |
* @throws EmptyContainerException if the structure is empty. | |
*/ | |
function pop_front(); | |
/** | |
* Returns the first value of the structure without removing it. | |
* @psalm-return T The value at the front of the structure. | |
* @throws EmptyContainerException if the structure is empty. | |
*/ | |
function front(); | |
/** | |
* Appends the given value to the back of the structure. | |
* @psalm-param T $value | |
*/ | |
function push_back($value); | |
/** | |
* Removes and returns the last value of the structure, the back of the structure. | |
* | |
* @psalm-return T The value that was removed from the back of the structure. | |
* | |
* @throws EmptyContainerException if the structure is empty. | |
*/ | |
function pop_back(); | |
/** | |
* Returns the last value of the structure without removing it. | |
* @psalm-return T The value at the back of the structure. | |
* @throws EmptyContainerException if the structure is empty. | |
*/ | |
function back(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Spl; | |
/** | |
* A structure with First-In, Last-Out (FIFO) behavior. | |
* @template T | |
*/ | |
interface Queue | |
extends \Countable, \IteratorAggregate | |
{ | |
/** | |
* Appends the given value to the back of the structure. | |
* @psalm-param T $value | |
*/ | |
function push_back($value); | |
/** | |
* Removes and returns the first value of the structure. | |
* | |
* @psalm-return T The value that was removed from the front of the structure. | |
* | |
* @throws EmptyContainerException if the structure is empty. | |
*/ | |
function pop_front(); | |
/** | |
* Returns the first value of the structure without removing it. | |
* @psalm-return T The value at the front of the structure. | |
* @throws EmptyContainerException if the structure is empty. | |
*/ | |
function front(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Spl; | |
/** | |
* A structure with First-In, Last-Out (FIFO) behavior. | |
* @template T | |
*/ | |
interface Stack | |
extends \Countable, \IteratorAggregate | |
{ | |
/** | |
* Appends the given value to the back of the structure. | |
* @psalm-param T $value | |
*/ | |
function push_back($value); | |
/** | |
* Removes and returns the last value of the structure, the back of the structure. | |
* | |
* @psalm-return T The value that was removed from the back of the structure. | |
* | |
* @throws EmptyContainerException if the structure is empty. | |
*/ | |
function pop_back(); | |
/** | |
* Returns the last value of the structure without removing it. | |
* @psalm-return T The value at the back of the structure. | |
* @throws EmptyContainerException if the structure is empty. | |
*/ | |
function back(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment