#ifndef HEAP_H
#define HEAP_H

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>

typedef struct heap heap;

heap  *heap_new(void);                  /* new empty heap */
heap  *heap_build(const int64_t *keys, const int64_t *values, size_t count);
void   heap_free(heap *h);              /* release all memory */

void   heap_push(heap *h, int64_t key, int64_t value);
bool   heap_peek(const heap *h, int64_t *key, int64_t *value);
bool   heap_pop(heap *h, int64_t *key, int64_t *value);
bool   heap_replace(heap *h, int64_t key, int64_t value,
                    int64_t *old_key, int64_t *old_value);
void   heap_push_pop(heap *h, int64_t key, int64_t value,
                     int64_t *out_key, int64_t *out_value);
size_t heap_len(const heap *h);
void   heap_slot(const heap *h, size_t i, int64_t *key, int64_t *value);

#endif /* HEAP_H */
