xref: /ext-ds/src/ds/ds_queue.h (revision 76d81488)
1 #ifndef DS_QUEUE_H
2 #define DS_QUEUE_H
3 
4 #include "../common.h"
5 #include "ds_deque.h"
6 
7 #define QUEUE_SIZE(q)     ((q)->deque->size)
8 #define QUEUE_IS_EMPTY(q) ((q)->deque->size == 0)
9 
10 #define QUEUE_FOREACH(queue, value)                 \
11 do {                                                \
12     zval _tmp;                                      \
13     while ( ! DS_DEQUE_IS_EMPTY(queue->deque)) {    \
14         ds_deque_shift(queue->deque, &_tmp);        \
15         value = &_tmp;
16 
17 #define QUEUE_FOREACH_END()     \
18     }                           \
19     zval_ptr_dtor(&_tmp);       \
20 } while (0)                     \
21 
22 typedef struct _ds_queue_t {
23     ds_deque_t    *deque;
24 } ds_queue_t;
25 
26 ds_queue_t *ds_queue_ex(ds_deque_t *deque);
27 ds_queue_t *ds_queue();
28 ds_queue_t *ds_queue_clone(ds_queue_t *queue);
29 
30 void ds_queue_allocate(ds_queue_t *queue, zend_long capacity);
31 zend_long ds_queue_capacity(ds_queue_t *queue);
32 
33 void  ds_queue_push(ds_queue_t *queue, VA_PARAMS);
34 void  ds_queue_push_one(ds_queue_t *queue, zval *value);
35 void  ds_queue_clear(ds_queue_t *queue);
36 void  ds_queue_pop(ds_queue_t *queue, zval *return_value);
37 void  ds_queue_pop_throw(ds_queue_t *queue, zval *return_value);
38 zval *ds_queue_peek(ds_queue_t *queue);
39 zval *ds_queue_peek_throw(ds_queue_t *queue);
40 void  ds_queue_push_all(ds_queue_t *queue, zval *value);
41 void  ds_queue_to_array(ds_queue_t *queue, zval *return_value);
42 void  ds_queue_free(ds_queue_t *queue);
43 
44 int ds_queue_serialize(zval *object, unsigned char **buffer, size_t *length, zend_serialize_data *data);
45 int ds_queue_unserialize(zval *object, zend_class_entry *ce, const unsigned char *buffer, size_t length, zend_unserialize_data *data);
46 
47 #endif
48