-
Notifications
You must be signed in to change notification settings - Fork 0
/
hashmap.h
55 lines (44 loc) · 1.64 KB
/
hashmap.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
arfhttpd: Yet another HTTP server
Copyright (C) 2023 arf20 (Ángel Ruiz Fernandez)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <sys/stat.h>
#include <stddef.h>
/* 10
CS */
#define IS_CACHED_STAT(x) (x & 1)
#define IS_CACHED_CONTENT(x) ((x >> 1) & 1)
#define SET_CACHED_STAT(x) (x |= 1)
#define SET_CACHED_CONTENT(x) (x |= 1 << 1)
#define CLEAR_CACHED_STAT(x) (x &= ~(1))
#define CLEAR_CACHED_CONTENT(x) (x &= ~(1 << 1))
typedef struct nodedata_s {
struct stat stat_data;
char *content_buff;
size_t content_size;
char flags;
int wd; /* inotify watch fd */
} htdata_t;
typedef struct hashtable_node_s {
struct hashtable_node_s *next;
const char *key;
int key_len;
htdata_t data;
} hashtable_node_t;
typedef struct hashtable_s {
hashtable_node_t *table;
int size;
} hashtable_t;
void hashtable_new(hashtable_t *ht, int size);
hashtable_node_t *hashtable_insert(hashtable_t *ht, const char *key, htdata_t value);
htdata_t *hashtable_get(hashtable_t *ht, const char *key);