Skip to content

Commit 907858b

Browse files
committed
Added some missing documentation and trait refactor
1 parent 914c2c3 commit 907858b

File tree

13 files changed

+351
-330
lines changed

13 files changed

+351
-330
lines changed

src/Collection.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
namespace Ds;
33

44
/**
5-
* Collection Interface
5+
* Collection is the base interface which covers functionality common to all the
6+
* data structures in this library. It guarantees that all structures are
7+
* traversable, countable, and can be converted to json using json_encode().
68
*
79
* @package Ds
810
*/
@@ -23,7 +25,7 @@ function count(): int;
2325
/**
2426
* Returns a shallow copy of the collection.
2527
*
26-
* @return \Ds\Collection a copy of the collection.
28+
* @return Collection a copy of the collection.
2729
*/
2830
function copy(): Collection;
2931

src/Deque.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,19 @@
22
namespace Ds;
33

44
/**
5-
* Deque
5+
* A Deque (pronounced "deck") is a sequence of values in a contiguous buffer
6+
* that grows and shrinks automatically. The name is a common abbreviation of
7+
* "double-ended queue".
8+
*
9+
* While a Deque is very similar to a Vector, it offers constant time operations
10+
* at both ends of the buffer, ie. shift, unshift, push and pop are all O(1).
611
*
712
* @package Ds
813
*/
914
final class Deque implements \IteratorAggregate, \ArrayAccess, Sequence
1015
{
11-
use Traits\Collection;
12-
use Traits\Sequence;
16+
use Traits\GenericCollection;
17+
use Traits\GenericSequence;
1318
use Traits\SquaredCapacity;
1419

1520
const MIN_CAPACITY = 8;

src/Hashable.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,33 @@
22
namespace Ds;
33

44
/**
5-
* Hashable Interface
5+
* Hashable is an interface which allows objects to be used as keys.
6+
*
7+
* It’s an alternative to spl_object_hash(), which determines an object’s hash
8+
* based on its handle: this means that two objects that are considered equal
9+
* by an implicit definition would not treated as equal because they are not
10+
* the same instance.
611
*
712
* @package Ds
813
*/
914
interface Hashable
1015
{
1116
/**
12-
* Produces a scalar value to be used as the object's hash.
17+
* Produces a scalar value to be used as the object's hash, which determines
18+
* where it goes in the hash table. While this value does not have to be
19+
* unique, objects which are equal must have the same hash value.
1320
*
14-
* @return mixed Scalar hash value.
21+
* @return mixed
1522
*/
1623
function hash();
1724

1825
/**
19-
* Returns whether this object is considered equal to another.
26+
* Determines if two objects should be considered equal. Both objects will
27+
* be instances of the same class but may not be the same instance.
2028
*
21-
* @param $obj
29+
* @param $obj An instance of the same class to compare to.
2230
*
23-
* @return bool true if equal, false otherwise.
31+
* @return bool
2432
*/
2533
function equals($obj): bool;
2634
}

0 commit comments

Comments
 (0)