Skip to content

Commit b4c356b

Browse files
committed
Add implementation of isEmpty()
1 parent 84a8134 commit b4c356b

File tree

4 files changed

+34
-3
lines changed

4 files changed

+34
-3
lines changed

ext/spl/spl_deque.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,15 @@ PHP_METHOD(Deque, count)
458458
RETURN_LONG(intern->array.size);
459459
}
460460

461+
/* Returns true if there are 0 elements in this Deque. */
462+
PHP_METHOD(Deque, isEmpty)
463+
{
464+
ZEND_PARSE_PARAMETERS_NONE();
465+
466+
const spl_deque *intern = Z_DEQUE_P(ZEND_THIS);
467+
RETURN_BOOL(intern->array.size == 0);
468+
}
469+
461470
/* Free elements and backing storage of this deque */
462471
PHP_METHOD(Deque, clear)
463472
{

ext/spl/spl_deque.stub.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,11 @@ public function __construct(iterable $iterator = []) {}
2828
* use `for ($i = 0; $i < count($deque); $i++) { process($deque[$i]); }`.
2929
*/
3030
public function getIterator(): InternalIterator {}
31-
/** Returns the number of elements in the Deque */
31+
/** Returns the number of elements in the Deque. */
3232
public function count(): int {}
33-
/** Removes all elements from the Deque */
33+
/** Returns true if there are 0 elements in the Deque. */
34+
public function isEmpty(): bool {}
35+
/** Removes all elements from the Deque. */
3436
public function clear(): void {}
3537

3638
public function __serialize(): array {}

ext/spl/spl_deque_arginfo.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: dcf42677a611cc6712ea1ad40e5730943486c305 */
2+
* Stub hash: 41b3f16290517e41a55e052b96bbcf8ea65c6e8a */
33

44
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Deque___construct, 0, 0, 0)
55
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, iterator, IS_ITERABLE, 0, "[]")
@@ -11,6 +11,9 @@ ZEND_END_ARG_INFO()
1111
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Deque_count, 0, 0, IS_LONG, 0)
1212
ZEND_END_ARG_INFO()
1313

14+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Deque_isEmpty, 0, 0, _IS_BOOL, 0)
15+
ZEND_END_ARG_INFO()
16+
1417
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Deque_clear, 0, 0, IS_VOID, 0)
1518
ZEND_END_ARG_INFO()
1619

@@ -74,6 +77,7 @@ ZEND_END_ARG_INFO()
7477
ZEND_METHOD(Deque, __construct);
7578
ZEND_METHOD(Deque, getIterator);
7679
ZEND_METHOD(Deque, count);
80+
ZEND_METHOD(Deque, isEmpty);
7781
ZEND_METHOD(Deque, clear);
7882
ZEND_METHOD(Deque, __serialize);
7983
ZEND_METHOD(Deque, __unserialize);
@@ -98,6 +102,7 @@ static const zend_function_entry class_Deque_methods[] = {
98102
ZEND_ME(Deque, __construct, arginfo_class_Deque___construct, ZEND_ACC_PUBLIC)
99103
ZEND_ME(Deque, getIterator, arginfo_class_Deque_getIterator, ZEND_ACC_PUBLIC)
100104
ZEND_ME(Deque, count, arginfo_class_Deque_count, ZEND_ACC_PUBLIC)
105+
ZEND_ME(Deque, isEmpty, arginfo_class_Deque_isEmpty, ZEND_ACC_PUBLIC)
101106
ZEND_ME(Deque, clear, arginfo_class_Deque_clear, ZEND_ACC_PUBLIC)
102107
ZEND_ME(Deque, __serialize, arginfo_class_Deque___serialize, ZEND_ACC_PUBLIC)
103108
ZEND_ME(Deque, __unserialize, arginfo_class_Deque___unserialize, ZEND_ACC_PUBLIC)

ext/spl/tests/Deque/isEmpty.phpt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
Deque isEmpty()
3+
--FILE--
4+
<?php
5+
$it = new Deque();
6+
var_dump($it->isEmpty());
7+
$it->push(123);
8+
var_dump($it->isEmpty());
9+
$it->push('other');
10+
var_dump($it->isEmpty());
11+
?>
12+
--EXPECT--
13+
bool(true)
14+
bool(false)
15+
bool(false)

0 commit comments

Comments
 (0)