@@ 19-86 (lines=68) @@ | ||
16 | /** |
|
17 | * Set of edges. |
|
18 | */ |
|
19 | class Set extends AbstractSet |
|
20 | { |
|
21 | /** |
|
22 | * Sets the optional contained edges. |
|
23 | * |
|
24 | * @param EdgeInterface[] $edges |
|
25 | */ |
|
26 | public function __construct(EdgeInterface ...$edges) |
|
27 | { |
|
28 | $this->data = $edges; |
|
29 | } |
|
30 | ||
31 | /** |
|
32 | * Sets the contained edges. |
|
33 | * |
|
34 | * @param EdgeInterface[] $edges |
|
35 | */ |
|
36 | public function set(EdgeInterface ...$edges) |
|
37 | { |
|
38 | $this->data = $edges; |
|
39 | } |
|
40 | ||
41 | /** |
|
42 | * Adds some edges. |
|
43 | * |
|
44 | * @param EdgeInterface[] $edges |
|
45 | */ |
|
46 | public function add(EdgeInterface ...$edges) |
|
47 | { |
|
48 | $this->data = array_merge($this->data, $edges); |
|
49 | } |
|
50 | ||
51 | /** |
|
52 | * Checks if all the edges are contained. |
|
53 | * |
|
54 | * @param EdgeInterface[] $edges |
|
55 | * |
|
56 | * @return bool |
|
57 | */ |
|
58 | public function has(EdgeInterface ...$edges): bool |
|
59 | { |
|
60 | $intersection = array_uintersect( |
|
61 | $this->data, |
|
62 | $edges, |
|
63 | function (EdgeInterface $a, EdgeInterface $b) { |
|
64 | return $a !== $b; |
|
65 | } |
|
66 | ); |
|
67 | ||
68 | return count($intersection) === count($edges); |
|
69 | } |
|
70 | ||
71 | /** |
|
72 | * Removes some edges. |
|
73 | * |
|
74 | * @param EdgeInterface[] $edges |
|
75 | */ |
|
76 | public function remove(EdgeInterface ...$edges) |
|
77 | { |
|
78 | $this->data = array_udiff( |
|
79 | $this->data, |
|
80 | $edges, |
|
81 | function (EdgeInterface $a, EdgeInterface $b) { |
|
82 | return $a !== $b; |
|
83 | } |
|
84 | ); |
|
85 | } |
|
86 | } |
|
87 |
@@ 19-86 (lines=68) @@ | ||
16 | /** |
|
17 | * Set of vertices. |
|
18 | */ |
|
19 | class Set extends AbstractSet |
|
20 | { |
|
21 | /** |
|
22 | * Sets the optional contained vertices. |
|
23 | * |
|
24 | * @param VertexInterface[] $vertices |
|
25 | */ |
|
26 | public function __construct(VertexInterface ...$vertices) |
|
27 | { |
|
28 | $this->data = $vertices; |
|
29 | } |
|
30 | ||
31 | /** |
|
32 | * Sets the contained vertices. |
|
33 | * |
|
34 | * @param VertexInterface[] $vertices |
|
35 | */ |
|
36 | public function set(VertexInterface ...$vertices) |
|
37 | { |
|
38 | $this->data = $vertices; |
|
39 | } |
|
40 | ||
41 | /** |
|
42 | * Adds some vertices. |
|
43 | * |
|
44 | * @param VertexInterface[] $vertices |
|
45 | */ |
|
46 | public function add(VertexInterface ...$vertices) |
|
47 | { |
|
48 | $this->data = array_merge($this->data, $vertices); |
|
49 | } |
|
50 | ||
51 | /** |
|
52 | * Checks if all the vertices are contained. |
|
53 | * |
|
54 | * @param VertexInterface[] $vertices |
|
55 | * |
|
56 | * @return bool |
|
57 | */ |
|
58 | public function has(VertexInterface ...$vertices): bool |
|
59 | { |
|
60 | $intersection = array_uintersect( |
|
61 | $this->data, |
|
62 | $vertices, |
|
63 | function (VertexInterface $a, VertexInterface $b) { |
|
64 | return $a !== $b; |
|
65 | } |
|
66 | ); |
|
67 | ||
68 | return count($intersection) === count($vertices); |
|
69 | } |
|
70 | ||
71 | /** |
|
72 | * Removes some vertices. |
|
73 | * |
|
74 | * @param VertexInterface[] $vertices |
|
75 | */ |
|
76 | public function remove(VertexInterface ...$vertices) |
|
77 | { |
|
78 | $this->data = array_udiff( |
|
79 | $this->data, |
|
80 | $vertices, |
|
81 | function (VertexInterface $a, VertexInterface $b) { |
|
82 | return $a !== $b; |
|
83 | } |
|
84 | ); |
|
85 | } |
|
86 | } |
|
87 |