/*1* nghttp2 - HTTP/2 C Library2*3* Copyright (c) 2012 Tatsuhiro Tsujikawa4*5* Permission is hereby granted, free of charge, to any person obtaining6* a copy of this software and associated documentation files (the7* "Software"), to deal in the Software without restriction, including8* without limitation the rights to use, copy, modify, merge, publish,9* distribute, sublicense, and/or sell copies of the Software, and to10* permit persons to whom the Software is furnished to do so, subject to11* the following conditions:12*13* The above copyright notice and this permission notice shall be14* included in all copies or substantial portions of the Software.15*16* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,17* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF18* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND19* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE20* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION21* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION22* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.23*/24#ifndef NGHTTP2_PQ_H25#define NGHTTP2_PQ_H2627#ifdef HAVE_CONFIG_H28# include <config.h>29#endif /* HAVE_CONFIG_H */3031#include <nghttp2/nghttp2.h>32#include "nghttp2_int.h"33#include "nghttp2_mem.h"3435/* Implementation of priority queue */3637typedef struct {38size_t index;39} nghttp2_pq_entry;4041typedef struct {42/* The pointer to the pointer to the item stored */43nghttp2_pq_entry **q;44/* Memory allocator */45nghttp2_mem *mem;46/* The number of items stored */47size_t length;48/* The maximum number of items this pq can store. This is49automatically extended when length is reached to this value. */50size_t capacity;51/* The less function between items */52nghttp2_less less;53} nghttp2_pq;5455/*56* Initializes priority queue |pq| with compare function |cmp|.57*/58void nghttp2_pq_init(nghttp2_pq *pq, nghttp2_less less, nghttp2_mem *mem);5960/*61* Deallocates any resources allocated for |pq|. The stored items are62* not freed by this function.63*/64void nghttp2_pq_free(nghttp2_pq *pq);6566/*67* Adds |item| to the priority queue |pq|.68*69* This function returns 0 if it succeeds, or one of the following70* negative error codes:71*72* NGHTTP2_ERR_NOMEM73* Out of memory.74*/75int nghttp2_pq_push(nghttp2_pq *pq, nghttp2_pq_entry *item);7677/*78* Returns item at the top of the queue |pq|. If the queue is empty,79* this function returns NULL.80*/81nghttp2_pq_entry *nghttp2_pq_top(nghttp2_pq *pq);8283/*84* Pops item at the top of the queue |pq|. The popped item is not85* freed by this function.86*/87void nghttp2_pq_pop(nghttp2_pq *pq);8889/*90* Returns nonzero if the queue |pq| is empty.91*/92int nghttp2_pq_empty(nghttp2_pq *pq);9394/*95* Returns the number of items in the queue |pq|.96*/97size_t nghttp2_pq_size(nghttp2_pq *pq);9899typedef int (*nghttp2_pq_item_cb)(nghttp2_pq_entry *item, void *arg);100101/*102* Updates each item in |pq| using function |fun| and re-construct103* priority queue. The |fun| must return non-zero if it modifies the104* item in a way that it affects ordering in the priority queue. The105* |arg| is passed to the 2nd parameter of |fun|.106*/107void nghttp2_pq_update(nghttp2_pq *pq, nghttp2_pq_item_cb fun, void *arg);108109/*110* Applies |fun| to each item in |pq|. The |arg| is passed as arg111* parameter to callback function. This function must not change the112* ordering key. If the return value from callback is nonzero, this113* function returns 1 immediately without iterating remaining items.114* Otherwise this function returns 0.115*/116int nghttp2_pq_each(nghttp2_pq *pq, nghttp2_pq_item_cb fun, void *arg);117118/*119* Removes |item| from priority queue.120*/121void nghttp2_pq_remove(nghttp2_pq *pq, nghttp2_pq_entry *item);122123#endif /* NGHTTP2_PQ_H */124125126