Skip to content

Commit 18ebb48

Browse files
authored
add Interface Set. (#13)
* Add Deque Interface and Corresponding Tests - Created Deque interface extending Queue interface to define additional methods for double-ended queues. - Added methods: addFirst, removeLast, and peekLast to the Deque interface. - Implemented unit tests for Deque interface to ensure proper contract implementation. Interface: - KaririCode\Contract\DataStructure\Deque Tests: - KaririCode\Contract\Tests\DataStructure\DequeTest * add Interface Set * nomalize to PSR * adjust comments
1 parent f8a776c commit 18ebb48

File tree

3 files changed

+66
-3
lines changed

3 files changed

+66
-3
lines changed

src/DataStructure/Behavioral/IterableCollection.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
namespace KaririCode\Contract\DataStructure\Behavioral;
66

7-
use KaririCode\Contract\DataStructure\Behavioral\Iterator;
8-
97
/**
108
* Interface IterableCollection.
119
*

src/DataStructure/DequeTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ public function testPeekLast(): void
5959

6060
public function testIsEmpty(): void
6161
{
62-
6362
$mock = $this->createMock(Deque::class);
6463
$mock->method('isEmpty')->willReturn(true);
6564

src/DataStructure/Set.php

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace KaririCode\Contract\DataStructure;
6+
7+
/**
8+
* Interface Set.
9+
*
10+
* Defines the contract for set data structures, which do not allow duplicate elements.
11+
*
12+
* @category Interfaces
13+
*
14+
* @author Walmir Silva <walmir.silva@kariricode.org>
15+
* @license MIT
16+
*
17+
* @see https://kariricode.org/
18+
*/
19+
interface Set
20+
{
21+
/**
22+
* Adds an element to the set.
23+
*
24+
* @param mixed $element The element to add
25+
*
26+
* @return bool True if the element was added, false if it was already present
27+
*/
28+
public function add(mixed $element): bool;
29+
30+
/**
31+
* Removes an element from the set.
32+
*
33+
* @param mixed $element The element to remove
34+
*
35+
* @return bool True if the element was removed, false if it was not present
36+
*/
37+
public function remove(mixed $element): bool;
38+
39+
/**
40+
* Checks if the set contains a specific element.
41+
*
42+
* @param mixed $element The element to check for
43+
*
44+
* @return bool True if the element is present, false otherwise
45+
*/
46+
public function contains(mixed $element): bool;
47+
48+
/**
49+
* Removes all elements from the set.
50+
*/
51+
public function clear(): void;
52+
53+
/**
54+
* Returns the number of elements in the set.
55+
*
56+
* @return int The number of elements in the set
57+
*/
58+
public function size(): int;
59+
60+
/**
61+
* Checks if the set is empty.
62+
*
63+
* @return bool True if the set is empty, false otherwise
64+
*/
65+
public function isEmpty(): bool;
66+
}

0 commit comments

Comments
 (0)