isomorfeus-iodine 0.7.47 → 0.7.50
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/ISSUE_TEMPLATE/bug_report.md +1 -1
- data/.github/workflows/ruby.yml +2 -1
- data/.gitlab-ci.yml +8 -0
- data/CHANGELOG.md +1052 -1038
- data/Gemfile +10 -11
- data/Rakefile +1 -9
- data/bin/console +18 -22
- data/bitbucket-pipelines.yml +9 -0
- data/examples/etag.ru +16 -0
- data/ext/{iodine → iodine_ext}/extconf.rb +1 -1
- data/ext/{iodine → iodine_ext}/fio.c +0 -0
- data/ext/{iodine → iodine_ext}/fio.h +0 -0
- data/ext/{iodine → iodine_ext}/fio_cli.c +0 -0
- data/ext/{iodine → iodine_ext}/fio_cli.h +189 -189
- data/ext/{iodine → iodine_ext}/fio_json_parser.h +687 -687
- data/ext/{iodine → iodine_ext}/fio_siphash.c +157 -157
- data/ext/{iodine → iodine_ext}/fio_siphash.h +37 -37
- data/ext/{iodine → iodine_ext}/fio_tls.h +129 -129
- data/ext/{iodine → iodine_ext}/fio_tls_missing.c +0 -0
- data/ext/{iodine → iodine_ext}/fio_tls_openssl.c +0 -0
- data/ext/{iodine → iodine_ext}/fio_tmpfile.h +0 -0
- data/ext/{iodine → iodine_ext}/fiobj.h +44 -44
- data/ext/{iodine → iodine_ext}/fiobj4fio.h +21 -21
- data/ext/{iodine → iodine_ext}/fiobj_ary.c +333 -333
- data/ext/{iodine → iodine_ext}/fiobj_ary.h +139 -139
- data/ext/{iodine → iodine_ext}/fiobj_data.c +0 -0
- data/ext/{iodine → iodine_ext}/fiobj_data.h +0 -0
- data/ext/{iodine → iodine_ext}/fiobj_hash.c +0 -0
- data/ext/{iodine → iodine_ext}/fiobj_hash.h +176 -176
- data/ext/{iodine → iodine_ext}/fiobj_json.c +622 -622
- data/ext/{iodine → iodine_ext}/fiobj_json.h +68 -68
- data/ext/{iodine → iodine_ext}/fiobj_mem.h +71 -71
- data/ext/{iodine → iodine_ext}/fiobj_mustache.c +0 -0
- data/ext/{iodine → iodine_ext}/fiobj_mustache.h +62 -62
- data/ext/{iodine → iodine_ext}/fiobj_numbers.c +0 -0
- data/ext/{iodine → iodine_ext}/fiobj_numbers.h +127 -127
- data/ext/{iodine → iodine_ext}/fiobj_str.c +0 -0
- data/ext/{iodine → iodine_ext}/fiobj_str.h +172 -172
- data/ext/{iodine → iodine_ext}/fiobject.c +0 -0
- data/ext/{iodine → iodine_ext}/fiobject.h +0 -0
- data/ext/{iodine → iodine_ext}/hpack.h +1923 -1923
- data/ext/{iodine → iodine_ext}/http.c +14 -27
- data/ext/{iodine → iodine_ext}/http.h +1002 -1002
- data/ext/{iodine → iodine_ext}/http1.c +0 -0
- data/ext/{iodine → iodine_ext}/http1.h +29 -29
- data/ext/{iodine → iodine_ext}/http1_parser.h +873 -873
- data/ext/{iodine → iodine_ext}/http_internal.c +0 -0
- data/ext/{iodine → iodine_ext}/http_internal.h +0 -0
- data/ext/{iodine → iodine_ext}/http_mime_parser.h +350 -350
- data/ext/{iodine → iodine_ext}/iodine.c +1 -1
- data/ext/{iodine → iodine_ext}/iodine.h +0 -0
- data/ext/{iodine → iodine_ext}/iodine_caller.c +0 -0
- data/ext/{iodine → iodine_ext}/iodine_caller.h +0 -0
- data/ext/{iodine → iodine_ext}/iodine_connection.c +0 -0
- data/ext/{iodine → iodine_ext}/iodine_connection.h +55 -55
- data/ext/{iodine → iodine_ext}/iodine_defer.c +0 -0
- data/ext/{iodine → iodine_ext}/iodine_defer.h +6 -6
- data/ext/{iodine → iodine_ext}/iodine_fiobj2rb.h +120 -120
- data/ext/{iodine → iodine_ext}/iodine_helpers.c +282 -282
- data/ext/{iodine → iodine_ext}/iodine_helpers.h +12 -12
- data/ext/{iodine → iodine_ext}/iodine_http.c +0 -2
- data/ext/{iodine → iodine_ext}/iodine_http.h +23 -23
- data/ext/{iodine → iodine_ext}/iodine_json.c +302 -302
- data/ext/{iodine → iodine_ext}/iodine_json.h +6 -6
- data/ext/{iodine → iodine_ext}/iodine_mustache.c +0 -0
- data/ext/{iodine → iodine_ext}/iodine_mustache.h +6 -6
- data/ext/{iodine → iodine_ext}/iodine_pubsub.c +0 -0
- data/ext/{iodine → iodine_ext}/iodine_pubsub.h +26 -26
- data/ext/{iodine → iodine_ext}/iodine_rack_io.c +0 -8
- data/ext/{iodine → iodine_ext}/iodine_rack_io.h +20 -20
- data/ext/{iodine → iodine_ext}/iodine_store.c +0 -0
- data/ext/{iodine → iodine_ext}/iodine_store.h +20 -20
- data/ext/{iodine → iodine_ext}/iodine_tcp.c +0 -0
- data/ext/{iodine → iodine_ext}/iodine_tcp.h +0 -0
- data/ext/{iodine → iodine_ext}/iodine_tls.c +0 -0
- data/ext/{iodine → iodine_ext}/iodine_tls.h +13 -13
- data/ext/{iodine → iodine_ext}/mustache_parser.h +0 -0
- data/ext/{iodine → iodine_ext}/redis_engine.c +0 -0
- data/ext/{iodine → iodine_ext}/redis_engine.h +0 -0
- data/ext/{iodine → iodine_ext}/resp_parser.h +0 -0
- data/ext/{iodine → iodine_ext}/websocket_parser.h +505 -505
- data/ext/{iodine → iodine_ext}/websockets.c +0 -0
- data/ext/{iodine → iodine_ext}/websockets.h +185 -185
- data/isomorfeus-iodine.gemspec +1 -2
- data/lib/iodine/version.rb +1 -1
- data/lib/iodine.rb +1 -1
- metadata +82 -79
@@ -1,139 +1,139 @@
|
|
1
|
-
#ifndef FIOBJ_ARRAY_H
|
2
|
-
/*
|
3
|
-
Copyright: Boaz Segev, 2017-2019
|
4
|
-
License: MIT
|
5
|
-
*/
|
6
|
-
|
7
|
-
/**
|
8
|
-
A dynamic Array type for the fiobj_s dynamic type system.
|
9
|
-
*/
|
10
|
-
#define FIOBJ_ARRAY_H
|
11
|
-
|
12
|
-
#include <fiobject.h>
|
13
|
-
|
14
|
-
#ifdef __cplusplus
|
15
|
-
extern "C" {
|
16
|
-
#endif
|
17
|
-
|
18
|
-
/* *****************************************************************************
|
19
|
-
Array creation API
|
20
|
-
***************************************************************************** */
|
21
|
-
|
22
|
-
/** Creates a mutable empty Array object. Use `fiobj_free` when done. */
|
23
|
-
FIOBJ fiobj_ary_new(void);
|
24
|
-
|
25
|
-
/** Creates a mutable empty Array object with the requested capacity. */
|
26
|
-
FIOBJ fiobj_ary_new2(size_t capa);
|
27
|
-
|
28
|
-
/* *****************************************************************************
|
29
|
-
Array direct entry access API
|
30
|
-
***************************************************************************** */
|
31
|
-
|
32
|
-
/** Returns the number of elements in the Array. */
|
33
|
-
size_t fiobj_ary_count(FIOBJ ary);
|
34
|
-
|
35
|
-
/** Returns the current, temporary, array capacity (it's dynamic). */
|
36
|
-
size_t fiobj_ary_capa(FIOBJ ary);
|
37
|
-
|
38
|
-
/**
|
39
|
-
* Returns a TEMPORARY pointer to the beginning of the array.
|
40
|
-
*
|
41
|
-
* This pointer can be used for sorting and other direct access operations as
|
42
|
-
* long as no other actions (insertion/deletion) are performed on the array.
|
43
|
-
*/
|
44
|
-
FIOBJ *fiobj_ary2ptr(FIOBJ ary);
|
45
|
-
|
46
|
-
/**
|
47
|
-
* Returns a temporary object owned by the Array.
|
48
|
-
*
|
49
|
-
* Wrap this function call within `fiobj_dup` to get a persistent handle. i.e.:
|
50
|
-
*
|
51
|
-
* fiobj_dup(fiobj_ary_index(array, 0));
|
52
|
-
*
|
53
|
-
* Negative values are retrieved from the end of the array. i.e., `-1`
|
54
|
-
* is the last item.
|
55
|
-
*/
|
56
|
-
FIOBJ fiobj_ary_index(FIOBJ ary, int64_t pos);
|
57
|
-
/** alias for `fiobj_ary_index` */
|
58
|
-
#define fiobj_ary_entry(a, p) fiobj_ary_index((a), (p))
|
59
|
-
|
60
|
-
/**
|
61
|
-
* Sets an object at the requested position.
|
62
|
-
*/
|
63
|
-
void fiobj_ary_set(FIOBJ ary, FIOBJ obj, int64_t pos);
|
64
|
-
|
65
|
-
/* *****************************************************************************
|
66
|
-
Array push / shift API
|
67
|
-
***************************************************************************** */
|
68
|
-
|
69
|
-
/**
|
70
|
-
* Pushes an object to the end of the Array.
|
71
|
-
*/
|
72
|
-
void fiobj_ary_push(FIOBJ ary, FIOBJ obj);
|
73
|
-
|
74
|
-
/** Pops an object from the end of the Array. */
|
75
|
-
FIOBJ fiobj_ary_pop(FIOBJ ary);
|
76
|
-
|
77
|
-
/**
|
78
|
-
* Unshifts an object to the beginning of the Array. This could be
|
79
|
-
* expensive.
|
80
|
-
*/
|
81
|
-
void fiobj_ary_unshift(FIOBJ ary, FIOBJ obj);
|
82
|
-
|
83
|
-
/** Shifts an object from the beginning of the Array. */
|
84
|
-
FIOBJ fiobj_ary_shift(FIOBJ ary);
|
85
|
-
|
86
|
-
/* *****************************************************************************
|
87
|
-
Array Find / Remove / Replace
|
88
|
-
***************************************************************************** */
|
89
|
-
|
90
|
-
/**
|
91
|
-
* Replaces the object at a specific position, returning the old object -
|
92
|
-
* remember to `fiobj_free` the old object.
|
93
|
-
*/
|
94
|
-
FIOBJ fiobj_ary_replace(FIOBJ ary, FIOBJ obj, int64_t pos);
|
95
|
-
|
96
|
-
/**
|
97
|
-
* Finds the index of a specifide object (if any). Returns -1 if the object
|
98
|
-
* isn't found.
|
99
|
-
*/
|
100
|
-
int64_t fiobj_ary_find(FIOBJ ary, FIOBJ data);
|
101
|
-
|
102
|
-
/**
|
103
|
-
* Removes the object at the index (if valid), changing the index of any
|
104
|
-
* following objects.
|
105
|
-
*
|
106
|
-
* Returns 0 on success or -1 (if no object or out of bounds).
|
107
|
-
*/
|
108
|
-
int fiobj_ary_remove(FIOBJ ary, int64_t pos);
|
109
|
-
|
110
|
-
/**
|
111
|
-
* Removes the first instance of an object from the Array (if any), changing the
|
112
|
-
* index of any following objects.
|
113
|
-
*
|
114
|
-
* Returns 0 on success or -1 (if the object wasn't found).
|
115
|
-
*/
|
116
|
-
int fiobj_ary_remove2(FIOBJ ary, FIOBJ data);
|
117
|
-
|
118
|
-
/* *****************************************************************************
|
119
|
-
Array compacting (untested)
|
120
|
-
***************************************************************************** */
|
121
|
-
|
122
|
-
/**
|
123
|
-
* Removes any NULL *pointers* from an Array, keeping all Objects (including
|
124
|
-
* explicit NULL objects) in the array.
|
125
|
-
*
|
126
|
-
* This action is O(n) where n in the length of the array.
|
127
|
-
* It could get expensive.
|
128
|
-
*/
|
129
|
-
void fiobj_ary_compact(FIOBJ ary);
|
130
|
-
|
131
|
-
#if DEBUG
|
132
|
-
void fiobj_test_array(void);
|
133
|
-
#endif
|
134
|
-
|
135
|
-
#ifdef __cplusplus
|
136
|
-
} /* extern "C" */
|
137
|
-
#endif
|
138
|
-
|
139
|
-
#endif
|
1
|
+
#ifndef FIOBJ_ARRAY_H
|
2
|
+
/*
|
3
|
+
Copyright: Boaz Segev, 2017-2019
|
4
|
+
License: MIT
|
5
|
+
*/
|
6
|
+
|
7
|
+
/**
|
8
|
+
A dynamic Array type for the fiobj_s dynamic type system.
|
9
|
+
*/
|
10
|
+
#define FIOBJ_ARRAY_H
|
11
|
+
|
12
|
+
#include <fiobject.h>
|
13
|
+
|
14
|
+
#ifdef __cplusplus
|
15
|
+
extern "C" {
|
16
|
+
#endif
|
17
|
+
|
18
|
+
/* *****************************************************************************
|
19
|
+
Array creation API
|
20
|
+
***************************************************************************** */
|
21
|
+
|
22
|
+
/** Creates a mutable empty Array object. Use `fiobj_free` when done. */
|
23
|
+
FIOBJ fiobj_ary_new(void);
|
24
|
+
|
25
|
+
/** Creates a mutable empty Array object with the requested capacity. */
|
26
|
+
FIOBJ fiobj_ary_new2(size_t capa);
|
27
|
+
|
28
|
+
/* *****************************************************************************
|
29
|
+
Array direct entry access API
|
30
|
+
***************************************************************************** */
|
31
|
+
|
32
|
+
/** Returns the number of elements in the Array. */
|
33
|
+
size_t fiobj_ary_count(FIOBJ ary);
|
34
|
+
|
35
|
+
/** Returns the current, temporary, array capacity (it's dynamic). */
|
36
|
+
size_t fiobj_ary_capa(FIOBJ ary);
|
37
|
+
|
38
|
+
/**
|
39
|
+
* Returns a TEMPORARY pointer to the beginning of the array.
|
40
|
+
*
|
41
|
+
* This pointer can be used for sorting and other direct access operations as
|
42
|
+
* long as no other actions (insertion/deletion) are performed on the array.
|
43
|
+
*/
|
44
|
+
FIOBJ *fiobj_ary2ptr(FIOBJ ary);
|
45
|
+
|
46
|
+
/**
|
47
|
+
* Returns a temporary object owned by the Array.
|
48
|
+
*
|
49
|
+
* Wrap this function call within `fiobj_dup` to get a persistent handle. i.e.:
|
50
|
+
*
|
51
|
+
* fiobj_dup(fiobj_ary_index(array, 0));
|
52
|
+
*
|
53
|
+
* Negative values are retrieved from the end of the array. i.e., `-1`
|
54
|
+
* is the last item.
|
55
|
+
*/
|
56
|
+
FIOBJ fiobj_ary_index(FIOBJ ary, int64_t pos);
|
57
|
+
/** alias for `fiobj_ary_index` */
|
58
|
+
#define fiobj_ary_entry(a, p) fiobj_ary_index((a), (p))
|
59
|
+
|
60
|
+
/**
|
61
|
+
* Sets an object at the requested position.
|
62
|
+
*/
|
63
|
+
void fiobj_ary_set(FIOBJ ary, FIOBJ obj, int64_t pos);
|
64
|
+
|
65
|
+
/* *****************************************************************************
|
66
|
+
Array push / shift API
|
67
|
+
***************************************************************************** */
|
68
|
+
|
69
|
+
/**
|
70
|
+
* Pushes an object to the end of the Array.
|
71
|
+
*/
|
72
|
+
void fiobj_ary_push(FIOBJ ary, FIOBJ obj);
|
73
|
+
|
74
|
+
/** Pops an object from the end of the Array. */
|
75
|
+
FIOBJ fiobj_ary_pop(FIOBJ ary);
|
76
|
+
|
77
|
+
/**
|
78
|
+
* Unshifts an object to the beginning of the Array. This could be
|
79
|
+
* expensive.
|
80
|
+
*/
|
81
|
+
void fiobj_ary_unshift(FIOBJ ary, FIOBJ obj);
|
82
|
+
|
83
|
+
/** Shifts an object from the beginning of the Array. */
|
84
|
+
FIOBJ fiobj_ary_shift(FIOBJ ary);
|
85
|
+
|
86
|
+
/* *****************************************************************************
|
87
|
+
Array Find / Remove / Replace
|
88
|
+
***************************************************************************** */
|
89
|
+
|
90
|
+
/**
|
91
|
+
* Replaces the object at a specific position, returning the old object -
|
92
|
+
* remember to `fiobj_free` the old object.
|
93
|
+
*/
|
94
|
+
FIOBJ fiobj_ary_replace(FIOBJ ary, FIOBJ obj, int64_t pos);
|
95
|
+
|
96
|
+
/**
|
97
|
+
* Finds the index of a specifide object (if any). Returns -1 if the object
|
98
|
+
* isn't found.
|
99
|
+
*/
|
100
|
+
int64_t fiobj_ary_find(FIOBJ ary, FIOBJ data);
|
101
|
+
|
102
|
+
/**
|
103
|
+
* Removes the object at the index (if valid), changing the index of any
|
104
|
+
* following objects.
|
105
|
+
*
|
106
|
+
* Returns 0 on success or -1 (if no object or out of bounds).
|
107
|
+
*/
|
108
|
+
int fiobj_ary_remove(FIOBJ ary, int64_t pos);
|
109
|
+
|
110
|
+
/**
|
111
|
+
* Removes the first instance of an object from the Array (if any), changing the
|
112
|
+
* index of any following objects.
|
113
|
+
*
|
114
|
+
* Returns 0 on success or -1 (if the object wasn't found).
|
115
|
+
*/
|
116
|
+
int fiobj_ary_remove2(FIOBJ ary, FIOBJ data);
|
117
|
+
|
118
|
+
/* *****************************************************************************
|
119
|
+
Array compacting (untested)
|
120
|
+
***************************************************************************** */
|
121
|
+
|
122
|
+
/**
|
123
|
+
* Removes any NULL *pointers* from an Array, keeping all Objects (including
|
124
|
+
* explicit NULL objects) in the array.
|
125
|
+
*
|
126
|
+
* This action is O(n) where n in the length of the array.
|
127
|
+
* It could get expensive.
|
128
|
+
*/
|
129
|
+
void fiobj_ary_compact(FIOBJ ary);
|
130
|
+
|
131
|
+
#if DEBUG
|
132
|
+
void fiobj_test_array(void);
|
133
|
+
#endif
|
134
|
+
|
135
|
+
#ifdef __cplusplus
|
136
|
+
} /* extern "C" */
|
137
|
+
#endif
|
138
|
+
|
139
|
+
#endif
|
File without changes
|
File without changes
|
File without changes
|
@@ -1,176 +1,176 @@
|
|
1
|
-
/*
|
2
|
-
Copyright: Boaz Segev, 2017-2019
|
3
|
-
License: MIT
|
4
|
-
*/
|
5
|
-
#ifndef H_FIOBJ_HASH_H
|
6
|
-
/**
|
7
|
-
* The facil.io Hash object is an ordered Hash Table implementation.
|
8
|
-
*
|
9
|
-
* By compromising some of the HashMap's collision resistance (comparing only
|
10
|
-
* the Hash values rather than comparing key data), memory comparison can be
|
11
|
-
* avoided and performance increased.
|
12
|
-
*
|
13
|
-
* By being ordered it's possible to iterate over key-value pairs in the order
|
14
|
-
* in which they were added to the Hash table, making it possible to output JSON
|
15
|
-
* in a controlled manner.
|
16
|
-
*/
|
17
|
-
#define H_FIOBJ_HASH_H
|
18
|
-
|
19
|
-
#include <fiobject.h>
|
20
|
-
|
21
|
-
#include <fio_siphash.h>
|
22
|
-
#include <fiobj_str.h>
|
23
|
-
|
24
|
-
#include <errno.h>
|
25
|
-
|
26
|
-
#ifdef __cplusplus
|
27
|
-
extern "C" {
|
28
|
-
#endif
|
29
|
-
|
30
|
-
/* MUST be a power of 2 */
|
31
|
-
#define HASH_INITIAL_CAPACITY 16
|
32
|
-
|
33
|
-
/** attempts to rehash the hashmap. */
|
34
|
-
void fiobj_hash_rehash(FIOBJ h);
|
35
|
-
|
36
|
-
/* *****************************************************************************
|
37
|
-
Hash Creation
|
38
|
-
***************************************************************************** */
|
39
|
-
|
40
|
-
/**
|
41
|
-
* Creates a mutable empty Hash object. Use `fiobj_free` when done.
|
42
|
-
*
|
43
|
-
* Notice that these Hash objects are optimized for smaller collections and
|
44
|
-
* retain order of object insertion.
|
45
|
-
*/
|
46
|
-
FIOBJ fiobj_hash_new(void);
|
47
|
-
|
48
|
-
/**
|
49
|
-
* Creates a mutable empty Hash object with an initial capacity of `capa`. Use
|
50
|
-
* `fiobj_free` when done.
|
51
|
-
*
|
52
|
-
* This allows optimizations for larger (or smaller) collections.
|
53
|
-
*/
|
54
|
-
FIOBJ fiobj_hash_new2(size_t capa);
|
55
|
-
|
56
|
-
/* *****************************************************************************
|
57
|
-
Hash properties and state
|
58
|
-
***************************************************************************** */
|
59
|
-
|
60
|
-
/**
|
61
|
-
* Returns a temporary theoretical Hash map capacity.
|
62
|
-
* This could be used for testing performance and memory consumption.
|
63
|
-
*/
|
64
|
-
size_t fiobj_hash_capa(const FIOBJ hash);
|
65
|
-
|
66
|
-
/** Returns the number of elements in the Hash. */
|
67
|
-
size_t fiobj_hash_count(const FIOBJ hash);
|
68
|
-
|
69
|
-
/** Returns the key for the object in the current `fiobj_each` loop (if any). */
|
70
|
-
FIOBJ fiobj_hash_key_in_loop(void);
|
71
|
-
|
72
|
-
/* *****************************************************************************
|
73
|
-
Populating the Hash
|
74
|
-
***************************************************************************** */
|
75
|
-
|
76
|
-
/**
|
77
|
-
* Sets a key-value pair in the Hash, duplicating the Symbol and **moving**
|
78
|
-
* the ownership of the object to the Hash.
|
79
|
-
*
|
80
|
-
* Returns -1 on error.
|
81
|
-
*/
|
82
|
-
int fiobj_hash_set(FIOBJ hash, FIOBJ key, FIOBJ obj);
|
83
|
-
|
84
|
-
/**
|
85
|
-
* Allows the Hash to be used as a stack.
|
86
|
-
*
|
87
|
-
* If a pointer `key` is provided, it will receive ownership of the key
|
88
|
-
* (remember to free).
|
89
|
-
*
|
90
|
-
* Returns FIOBJ_INVALID on error.
|
91
|
-
*
|
92
|
-
* Returns and object if successful (remember to free).
|
93
|
-
*/
|
94
|
-
FIOBJ fiobj_hash_pop(FIOBJ hash, FIOBJ *key);
|
95
|
-
|
96
|
-
/**
|
97
|
-
* Replaces the value in a key-value pair, returning the old value (and it's
|
98
|
-
* ownership) to the caller.
|
99
|
-
*
|
100
|
-
* A return value of FIOBJ_INVALID indicates that no previous object existed
|
101
|
-
* (but a new key-value pair was created.
|
102
|
-
*
|
103
|
-
* Errors are silently ignored.
|
104
|
-
*
|
105
|
-
* Remember to free the returned object.
|
106
|
-
*/
|
107
|
-
FIOBJ fiobj_hash_replace(FIOBJ hash, FIOBJ key, FIOBJ obj);
|
108
|
-
|
109
|
-
/**
|
110
|
-
* Removes a key-value pair from the Hash, if it exists, returning the old
|
111
|
-
* object (instead of freeing it).
|
112
|
-
*/
|
113
|
-
FIOBJ fiobj_hash_remove(FIOBJ hash, FIOBJ key);
|
114
|
-
|
115
|
-
/**
|
116
|
-
* Removes a key-value pair from the Hash, if it exists, returning the old
|
117
|
-
* object (instead of freeing it).
|
118
|
-
*/
|
119
|
-
FIOBJ fiobj_hash_remove2(FIOBJ hash, uint64_t key_hash);
|
120
|
-
|
121
|
-
/**
|
122
|
-
* Deletes a key-value pair from the Hash, if it exists, freeing the
|
123
|
-
* associated object.
|
124
|
-
*
|
125
|
-
* Returns -1 on type error or if the object never existed.
|
126
|
-
*/
|
127
|
-
int fiobj_hash_delete(FIOBJ hash, FIOBJ key);
|
128
|
-
|
129
|
-
/**
|
130
|
-
* Deletes a key-value pair from the Hash, if it exists, freeing the
|
131
|
-
* associated object.
|
132
|
-
*
|
133
|
-
* This function takes a `uint64_t` Hash value (see `fio_siphash`) to
|
134
|
-
* perform a lookup in the HashMap, which is slightly faster than the other
|
135
|
-
* variations.
|
136
|
-
*
|
137
|
-
* Returns -1 on type error or if the object never existed.
|
138
|
-
*/
|
139
|
-
int fiobj_hash_delete2(FIOBJ hash, uint64_t key_hash);
|
140
|
-
|
141
|
-
/**
|
142
|
-
* Returns a temporary handle to the object associated with the Symbol,
|
143
|
-
* FIOBJ_INVALID if none.
|
144
|
-
*/
|
145
|
-
FIOBJ fiobj_hash_get(const FIOBJ hash, FIOBJ key);
|
146
|
-
|
147
|
-
/**
|
148
|
-
* Returns a temporary handle to the object associated hashed key value.
|
149
|
-
*
|
150
|
-
* This function takes a `uint64_t` Hash value (see `fio_siphash`) to
|
151
|
-
* perform a lookup in the HashMap, which is slightly faster than the other
|
152
|
-
* variations.
|
153
|
-
*
|
154
|
-
* Returns FIOBJ_INVALID if no object is associated with this hashed key value.
|
155
|
-
*/
|
156
|
-
FIOBJ fiobj_hash_get2(const FIOBJ hash, uint64_t key_hash);
|
157
|
-
|
158
|
-
/**
|
159
|
-
* Returns 1 if the key (Symbol) exists in the Hash, even if it's value is NULL.
|
160
|
-
*/
|
161
|
-
int fiobj_hash_haskey(const FIOBJ hash, FIOBJ key);
|
162
|
-
|
163
|
-
/**
|
164
|
-
* Empties the Hash.
|
165
|
-
*/
|
166
|
-
void fiobj_hash_clear(const FIOBJ hash);
|
167
|
-
|
168
|
-
#if DEBUG
|
169
|
-
void fiobj_test_hash(void);
|
170
|
-
#endif
|
171
|
-
|
172
|
-
#ifdef __cplusplus
|
173
|
-
} /* extern "C" */
|
174
|
-
#endif
|
175
|
-
|
176
|
-
#endif
|
1
|
+
/*
|
2
|
+
Copyright: Boaz Segev, 2017-2019
|
3
|
+
License: MIT
|
4
|
+
*/
|
5
|
+
#ifndef H_FIOBJ_HASH_H
|
6
|
+
/**
|
7
|
+
* The facil.io Hash object is an ordered Hash Table implementation.
|
8
|
+
*
|
9
|
+
* By compromising some of the HashMap's collision resistance (comparing only
|
10
|
+
* the Hash values rather than comparing key data), memory comparison can be
|
11
|
+
* avoided and performance increased.
|
12
|
+
*
|
13
|
+
* By being ordered it's possible to iterate over key-value pairs in the order
|
14
|
+
* in which they were added to the Hash table, making it possible to output JSON
|
15
|
+
* in a controlled manner.
|
16
|
+
*/
|
17
|
+
#define H_FIOBJ_HASH_H
|
18
|
+
|
19
|
+
#include <fiobject.h>
|
20
|
+
|
21
|
+
#include <fio_siphash.h>
|
22
|
+
#include <fiobj_str.h>
|
23
|
+
|
24
|
+
#include <errno.h>
|
25
|
+
|
26
|
+
#ifdef __cplusplus
|
27
|
+
extern "C" {
|
28
|
+
#endif
|
29
|
+
|
30
|
+
/* MUST be a power of 2 */
|
31
|
+
#define HASH_INITIAL_CAPACITY 16
|
32
|
+
|
33
|
+
/** attempts to rehash the hashmap. */
|
34
|
+
void fiobj_hash_rehash(FIOBJ h);
|
35
|
+
|
36
|
+
/* *****************************************************************************
|
37
|
+
Hash Creation
|
38
|
+
***************************************************************************** */
|
39
|
+
|
40
|
+
/**
|
41
|
+
* Creates a mutable empty Hash object. Use `fiobj_free` when done.
|
42
|
+
*
|
43
|
+
* Notice that these Hash objects are optimized for smaller collections and
|
44
|
+
* retain order of object insertion.
|
45
|
+
*/
|
46
|
+
FIOBJ fiobj_hash_new(void);
|
47
|
+
|
48
|
+
/**
|
49
|
+
* Creates a mutable empty Hash object with an initial capacity of `capa`. Use
|
50
|
+
* `fiobj_free` when done.
|
51
|
+
*
|
52
|
+
* This allows optimizations for larger (or smaller) collections.
|
53
|
+
*/
|
54
|
+
FIOBJ fiobj_hash_new2(size_t capa);
|
55
|
+
|
56
|
+
/* *****************************************************************************
|
57
|
+
Hash properties and state
|
58
|
+
***************************************************************************** */
|
59
|
+
|
60
|
+
/**
|
61
|
+
* Returns a temporary theoretical Hash map capacity.
|
62
|
+
* This could be used for testing performance and memory consumption.
|
63
|
+
*/
|
64
|
+
size_t fiobj_hash_capa(const FIOBJ hash);
|
65
|
+
|
66
|
+
/** Returns the number of elements in the Hash. */
|
67
|
+
size_t fiobj_hash_count(const FIOBJ hash);
|
68
|
+
|
69
|
+
/** Returns the key for the object in the current `fiobj_each` loop (if any). */
|
70
|
+
FIOBJ fiobj_hash_key_in_loop(void);
|
71
|
+
|
72
|
+
/* *****************************************************************************
|
73
|
+
Populating the Hash
|
74
|
+
***************************************************************************** */
|
75
|
+
|
76
|
+
/**
|
77
|
+
* Sets a key-value pair in the Hash, duplicating the Symbol and **moving**
|
78
|
+
* the ownership of the object to the Hash.
|
79
|
+
*
|
80
|
+
* Returns -1 on error.
|
81
|
+
*/
|
82
|
+
int fiobj_hash_set(FIOBJ hash, FIOBJ key, FIOBJ obj);
|
83
|
+
|
84
|
+
/**
|
85
|
+
* Allows the Hash to be used as a stack.
|
86
|
+
*
|
87
|
+
* If a pointer `key` is provided, it will receive ownership of the key
|
88
|
+
* (remember to free).
|
89
|
+
*
|
90
|
+
* Returns FIOBJ_INVALID on error.
|
91
|
+
*
|
92
|
+
* Returns and object if successful (remember to free).
|
93
|
+
*/
|
94
|
+
FIOBJ fiobj_hash_pop(FIOBJ hash, FIOBJ *key);
|
95
|
+
|
96
|
+
/**
|
97
|
+
* Replaces the value in a key-value pair, returning the old value (and it's
|
98
|
+
* ownership) to the caller.
|
99
|
+
*
|
100
|
+
* A return value of FIOBJ_INVALID indicates that no previous object existed
|
101
|
+
* (but a new key-value pair was created.
|
102
|
+
*
|
103
|
+
* Errors are silently ignored.
|
104
|
+
*
|
105
|
+
* Remember to free the returned object.
|
106
|
+
*/
|
107
|
+
FIOBJ fiobj_hash_replace(FIOBJ hash, FIOBJ key, FIOBJ obj);
|
108
|
+
|
109
|
+
/**
|
110
|
+
* Removes a key-value pair from the Hash, if it exists, returning the old
|
111
|
+
* object (instead of freeing it).
|
112
|
+
*/
|
113
|
+
FIOBJ fiobj_hash_remove(FIOBJ hash, FIOBJ key);
|
114
|
+
|
115
|
+
/**
|
116
|
+
* Removes a key-value pair from the Hash, if it exists, returning the old
|
117
|
+
* object (instead of freeing it).
|
118
|
+
*/
|
119
|
+
FIOBJ fiobj_hash_remove2(FIOBJ hash, uint64_t key_hash);
|
120
|
+
|
121
|
+
/**
|
122
|
+
* Deletes a key-value pair from the Hash, if it exists, freeing the
|
123
|
+
* associated object.
|
124
|
+
*
|
125
|
+
* Returns -1 on type error or if the object never existed.
|
126
|
+
*/
|
127
|
+
int fiobj_hash_delete(FIOBJ hash, FIOBJ key);
|
128
|
+
|
129
|
+
/**
|
130
|
+
* Deletes a key-value pair from the Hash, if it exists, freeing the
|
131
|
+
* associated object.
|
132
|
+
*
|
133
|
+
* This function takes a `uint64_t` Hash value (see `fio_siphash`) to
|
134
|
+
* perform a lookup in the HashMap, which is slightly faster than the other
|
135
|
+
* variations.
|
136
|
+
*
|
137
|
+
* Returns -1 on type error or if the object never existed.
|
138
|
+
*/
|
139
|
+
int fiobj_hash_delete2(FIOBJ hash, uint64_t key_hash);
|
140
|
+
|
141
|
+
/**
|
142
|
+
* Returns a temporary handle to the object associated with the Symbol,
|
143
|
+
* FIOBJ_INVALID if none.
|
144
|
+
*/
|
145
|
+
FIOBJ fiobj_hash_get(const FIOBJ hash, FIOBJ key);
|
146
|
+
|
147
|
+
/**
|
148
|
+
* Returns a temporary handle to the object associated hashed key value.
|
149
|
+
*
|
150
|
+
* This function takes a `uint64_t` Hash value (see `fio_siphash`) to
|
151
|
+
* perform a lookup in the HashMap, which is slightly faster than the other
|
152
|
+
* variations.
|
153
|
+
*
|
154
|
+
* Returns FIOBJ_INVALID if no object is associated with this hashed key value.
|
155
|
+
*/
|
156
|
+
FIOBJ fiobj_hash_get2(const FIOBJ hash, uint64_t key_hash);
|
157
|
+
|
158
|
+
/**
|
159
|
+
* Returns 1 if the key (Symbol) exists in the Hash, even if it's value is NULL.
|
160
|
+
*/
|
161
|
+
int fiobj_hash_haskey(const FIOBJ hash, FIOBJ key);
|
162
|
+
|
163
|
+
/**
|
164
|
+
* Empties the Hash.
|
165
|
+
*/
|
166
|
+
void fiobj_hash_clear(const FIOBJ hash);
|
167
|
+
|
168
|
+
#if DEBUG
|
169
|
+
void fiobj_test_hash(void);
|
170
|
+
#endif
|
171
|
+
|
172
|
+
#ifdef __cplusplus
|
173
|
+
} /* extern "C" */
|
174
|
+
#endif
|
175
|
+
|
176
|
+
#endif
|