validate: fix type stack and leaks
[m6w6/ext-psi] / src / plist.h
1 /*******************************************************************************
2 Copyright (c) 2016, Michael Wallner <mike@php.net>.
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7
8 * Redistributions of source code must retain the above copyright notice,
9 this list of conditions and the following disclaimer.
10 * Redistributions in binary form must reproduce the above copyright
11 notice, this list of conditions and the following disclaimer in the
12 documentation and/or other materials provided with the distribution.
13
14 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
18 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
21 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
22 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 *******************************************************************************/
25
26 #ifndef PSI_PLIST_H
27 #define PSI_PLIST_H
28
29 struct psi_plist;
30
31 typedef void (*psi_plist_dtor)(void *);
32
33 struct psi_plist *psi_plist_init(void (*dtor)(void *));
34 struct psi_plist *psi_plist_init_ex(size_t size, void (*dtor)(void *));
35 void psi_plist_clean(struct psi_plist *list);
36 void psi_plist_free(struct psi_plist *list);
37 struct psi_plist *psi_plist_copy(struct psi_plist *list, void (*ctor)(void *));
38
39 size_t psi_plist_count(struct psi_plist *list);
40 void **psi_plist_eles(struct psi_plist *list);
41
42 struct psi_plist *psi_plist_add(struct psi_plist *list, void *ptr);
43 struct psi_plist *psi_plist_add_r(struct psi_plist *list, size_t num_eles, void **eles);
44 bool psi_plist_get(struct psi_plist *list, size_t index, void *ptr);
45 bool psi_plist_del(struct psi_plist *list, size_t index, void *ptr);
46 bool psi_plist_del_r(struct psi_plist *list, size_t offset_start, size_t offset_end, void **eles);
47 struct psi_plist *psi_plist_ins(struct psi_plist *list, size_t index, void *ptr);
48 struct psi_plist *psi_plist_ins_r(struct psi_plist *list, size_t offset_start, size_t num_eles, void **eles);
49
50 bool psi_plist_shift(struct psi_plist *list, void *ptr);
51 bool psi_plist_pop(struct psi_plist *list, void *ptr);
52 bool psi_plist_top(struct psi_plist *list, void *ptr);
53 #define psi_plist_bottom(l, p) psi_plist_get((l), 0, (p))
54
55 #include "Zend/zend.h"
56 #include "Zend/zend_sort.h"
57
58 void psi_plist_sort(struct psi_plist *list, compare_func_t cmp, swap_func_t swp);
59
60 #endif