Support packets in flight
[samplevnf.git] / VNFs / DPPD-PROX / heap.h
1 /*
2 // Copyright (c) 2010-2017 Intel Corporation
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 */
16
17 #ifndef _HEAP_H_
18 #define _HEAP_H_
19
20 #include <inttypes.h>
21 #include <stdlib.h>
22
23 struct heap_ref {
24         struct heap_elem *elem;   /* timer management */
25 };
26
27 struct heap {
28         uint64_t n_elems;
29         struct heap_elem *top;
30         uint64_t n_avail;
31         struct heap_elem *avail[0];
32 };
33
34 static uint64_t heap_n_elems(const struct heap *h)
35 {
36         return h->n_elems;
37 }
38
39 static int heap_is_empty(const struct heap *h)
40 {
41         return !h->n_elems;
42 }
43
44 int heap_top_is_lower(struct heap *h, uint64_t prio);
45
46 void heap_print(struct heap *h, char *result, size_t buf_len);
47
48 struct heap *heap_create(uint32_t max_elems, int socket_id);
49 void heap_add(struct heap *h, struct heap_ref *ref, uint64_t priority);
50 void heap_del(struct heap *h, struct heap_ref *del);
51 struct heap_ref *heap_pop(struct heap *h);
52
53 #endif /* _HEAP_H_ */