1 #include "../../common.h"
2
3 #include "../parameters.h"
4 #include "../arginfo.h"
5
6 #include "../iterators/php_priority_queue_iterator.h"
7 #include "../handlers/php_priority_queue_handlers.h"
8 #include "../objects/php_priority_queue.h"
9
10 #include "php_collection_ce.h"
11 #include "php_priority_queue_ce.h"
12
13 #define METHOD(name) PHP_METHOD(PriorityQueue, name)
14
15 zend_class_entry *php_ds_priority_queue_ce;
16
METHOD(__construct)17 METHOD(__construct)
18 {
19 PARSE_NONE;
20 }
21
METHOD(allocate)22 METHOD(allocate)
23 {
24 PARSE_LONG(capacity);
25 ds_priority_queue_allocate(THIS_DS_PRIORITY_QUEUE(), capacity);
26 }
27
METHOD(capacity)28 METHOD(capacity)
29 {
30 PARSE_NONE;
31 RETURN_LONG(ds_priority_queue_capacity(THIS_DS_PRIORITY_QUEUE()));
32 }
33
METHOD(copy)34 METHOD(copy)
35 {
36 PARSE_NONE;
37 RETURN_OBJ(php_ds_priority_queue_create_clone(THIS_DS_PRIORITY_QUEUE()));
38 }
39
METHOD(push)40 METHOD(push)
41 {
42 PARSE_ZVAL_ZVAL(value, priority);
43 ds_priority_queue_push(THIS_DS_PRIORITY_QUEUE(), value, priority);
44 }
45
METHOD(pop)46 METHOD(pop)
47 {
48 PARSE_NONE;
49 ds_priority_queue_pop(THIS_DS_PRIORITY_QUEUE(), return_value);
50 }
51
METHOD(peek)52 METHOD(peek)
53 {
54 PARSE_NONE;
55 RETURN_ZVAL_COPY(ds_priority_queue_peek(THIS_DS_PRIORITY_QUEUE()));
56 }
57
METHOD(isEmpty)58 METHOD(isEmpty)
59 {
60 PARSE_NONE;
61 RETURN_BOOL(DS_PRIORITY_QUEUE_IS_EMPTY(THIS_DS_PRIORITY_QUEUE()));
62 }
63
METHOD(toArray)64 METHOD(toArray)
65 {
66 PARSE_NONE;
67 ds_priority_queue_to_array(THIS_DS_PRIORITY_QUEUE(), return_value);
68 }
69
METHOD(count)70 METHOD(count)
71 {
72 PARSE_NONE;
73 RETURN_LONG(DS_PRIORITY_QUEUE_SIZE(THIS_DS_PRIORITY_QUEUE()));
74 }
75
METHOD(clear)76 METHOD(clear)
77 {
78 PARSE_NONE;
79 ds_priority_queue_clear(THIS_DS_PRIORITY_QUEUE());
80 }
81
METHOD(jsonSerialize)82 METHOD(jsonSerialize)
83 {
84 PARSE_NONE;
85 ds_priority_queue_to_array(THIS_DS_PRIORITY_QUEUE(), return_value);
86 }
87
METHOD(getIterator)88 METHOD(getIterator) {
89 PARSE_NONE;
90 ZVAL_COPY(return_value, getThis());
91 }
92
php_ds_register_priority_queue()93 void php_ds_register_priority_queue()
94 {
95 zend_class_entry ce;
96
97 zend_function_entry methods[] = {
98 PHP_DS_ME(PriorityQueue, __construct)
99 PHP_DS_ME(PriorityQueue, allocate)
100 PHP_DS_ME(PriorityQueue, capacity)
101 PHP_DS_ME(PriorityQueue, peek)
102 PHP_DS_ME(PriorityQueue, pop)
103 PHP_DS_ME(PriorityQueue, push)
104 PHP_DS_ME(PriorityQueue, getIterator)
105
106 PHP_DS_COLLECTION_ME_LIST(PriorityQueue)
107 PHP_FE_END
108 };
109
110 INIT_CLASS_ENTRY(ce, PHP_DS_NS(PriorityQueue), methods);
111
112 php_ds_priority_queue_ce = zend_register_internal_class(&ce);
113 php_ds_priority_queue_ce->ce_flags |= ZEND_ACC_FINAL;
114 php_ds_priority_queue_ce->create_object = php_ds_priority_queue_create_object;
115 php_ds_priority_queue_ce->get_iterator = php_ds_priority_queue_get_iterator;
116 php_ds_priority_queue_ce->serialize = php_ds_priority_queue_serialize;
117 php_ds_priority_queue_ce->unserialize = php_ds_priority_queue_unserialize;
118
119 zend_declare_class_constant_long(
120 php_ds_priority_queue_ce,
121 STR_AND_LEN("MIN_CAPACITY"),
122 DS_PRIORITY_QUEUE_MIN_CAPACITY
123 );
124
125 zend_class_implements(php_ds_priority_queue_ce, 1, collection_ce);
126 php_ds_register_priority_queue_handlers();
127 }
128