Concord - C Discord API library
A Discord API wrapper library written in C
anomap.h
Go to the documentation of this file.
1// MIT License
2// Copyright (c) 2022 Anotra
3// https://github.com/Anotra/anomap
4
5#pragma once
6
7#ifndef ANOMAP_H
8#define ANOMAP_H
9
10#include <stddef.h>
11#include <stdbool.h>
12
13#define ANOMAP_DECLARE_COMPARE_FUNCTION(function_name, data_type) \
14 static int \
15 function_name(const void *a, const void *b) { \
16 if (*(data_type *)a == *(data_type *)b) return 0; \
17 return *(data_type *)a > *(data_type *)b ? 1 : -1; \
18 }
19
21 anomap_insert = 1 << 0,
22 anomap_update = 1 << 1,
24 anomap_delete = 1 << 2,
25 anomap_getval = 1 << 3,
26};
27
28struct anomap;
29
30struct anomap *anomap_create(size_t key_size, size_t val_size,
31 int (*cmp)(const void *, const void *));
32void anomap_destroy(struct anomap *map);
33
35 void *data;
37 void *key;
38 struct {
39 void *prev;
40 void *now;
41 } val;
42};
43
45 struct anomap *map, struct anomap_item_changed *item_changed);
46
48 struct anomap *map, anomap_on_item_changed *on_changed, void *data);
49
50size_t anomap_length(struct anomap *map);
51void anomap_clear(struct anomap *map);
52
53bool anomap_index_of(struct anomap *map, void *key, size_t *index);
54bool anomap_at_index(struct anomap *map, size_t index, void *key, void *val);
55
56enum anomap_operation anomap_do(struct anomap *map,
57 enum anomap_operation operation,
58 void *key, void *val);
59
60size_t anomap_copy_range(struct anomap *map,
61 size_t from_index, size_t to_index,
62 void *keys, void *vals);
63size_t anomap_delete_range(struct anomap *map,
64 size_t from_index, size_t to_index,
65 void *keys, void *vals);
66
67#endif // !ANOMAP_H
size_t anomap_copy_range(struct anomap *map, size_t from_index, size_t to_index, void *keys, void *vals)
anomap_operation
Definition: anomap.h:20
@ anomap_update
Definition: anomap.h:22
@ anomap_insert
Definition: anomap.h:21
@ anomap_delete
Definition: anomap.h:24
@ anomap_getval
Definition: anomap.h:25
@ anomap_upsert
Definition: anomap.h:23
void anomap_on_item_changed(struct anomap *map, struct anomap_item_changed *item_changed)
Definition: anomap.h:44
bool anomap_at_index(struct anomap *map, size_t index, void *key, void *val)
enum anomap_operation anomap_do(struct anomap *map, enum anomap_operation operation, void *key, void *val)
size_t anomap_length(struct anomap *map)
bool anomap_index_of(struct anomap *map, void *key, size_t *index)
void anomap_set_on_item_changed(struct anomap *map, anomap_on_item_changed *on_changed, void *data)
void anomap_clear(struct anomap *map)
size_t anomap_delete_range(struct anomap *map, size_t from_index, size_t to_index, void *keys, void *vals)
struct anomap * anomap_create(size_t key_size, size_t val_size, int(*cmp)(const void *, const void *))
void anomap_destroy(struct anomap *map)
Definition: anomap.h:34
void * key
Definition: anomap.h:37
void * now
Definition: anomap.h:40
void * prev
Definition: anomap.h:39
void * data
Definition: anomap.h:35
struct anomap_item_changed::@12 val
enum anomap_operation op
Definition: anomap.h:36