filedictrb 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/filedict/filedict.h +34 -17
- data/lib/filedict/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aad965d1fb0dd25c74c20f917b2f71e0d48fc7d6dea59bab8ad2c5990b3fb8fe
|
4
|
+
data.tar.gz: cd8c479f17d113b19d5ef89d565aeab6c51305e1e0f81dab3d8d6a538555009b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2dc64caded0eadba4cb03da2dfb926b3c488d6773df59087752953371e5dfabeeac4625478f0ac33a26c4a60f76105a8026ee49aa6e2c700437c0e992ba6a6fe
|
7
|
+
data.tar.gz: 7e392f4e734fbe940fb4d86c7a04700edcad3cbab286d4103f6846dbcadb1f2fd01ac8a6a272dd31e542ded3fb919fcfa6b566919161ab1cc3782a56692a2281
|
data/ext/filedict/filedict.h
CHANGED
@@ -27,6 +27,7 @@ typedef size_t (*filedict_hash_function_t)(const char *);
|
|
27
27
|
typedef struct filedict_t {
|
28
28
|
const char *error;
|
29
29
|
int fd;
|
30
|
+
int flags;
|
30
31
|
void *data;
|
31
32
|
size_t data_len;
|
32
33
|
filedict_hash_function_t hash_function;
|
@@ -96,6 +97,7 @@ static size_t filedict_copy_string(char *dest, const char *src, size_t max_len)
|
|
96
97
|
static void filedict_init(filedict_t *filedict) {
|
97
98
|
filedict->error = NULL;
|
98
99
|
filedict->fd = 0;
|
100
|
+
filedict->flags = 0;
|
99
101
|
filedict->data_len = 0;
|
100
102
|
filedict->data = NULL;
|
101
103
|
filedict->hash_function = filedict_default_hash_function;
|
@@ -110,6 +112,7 @@ static void filedict_deinit(filedict_t *filedict) {
|
|
110
112
|
if (filedict->fd) {
|
111
113
|
close(filedict->fd);
|
112
114
|
filedict->fd = 0;
|
115
|
+
filedict->flags = 0;
|
113
116
|
}
|
114
117
|
}
|
115
118
|
|
@@ -146,6 +149,7 @@ static void filedict_open_f(
|
|
146
149
|
int flags,
|
147
150
|
unsigned int initial_bucket_count
|
148
151
|
) {
|
152
|
+
filedict->flags = flags;
|
149
153
|
filedict->fd = open(filename, flags, 0666);
|
150
154
|
if (filedict->fd == -1) { filedict->error = strerror(errno); return; }
|
151
155
|
|
@@ -154,7 +158,7 @@ static void filedict_open_f(
|
|
154
158
|
filedict->data = mmap(
|
155
159
|
NULL,
|
156
160
|
filedict->data_len,
|
157
|
-
PROT_READ | PROT_WRITE,
|
161
|
+
PROT_READ | ((flags & O_RDWR) ? PROT_WRITE : 0),
|
158
162
|
MAP_SHARED,
|
159
163
|
filedict->fd,
|
160
164
|
0
|
@@ -163,8 +167,11 @@ static void filedict_open_f(
|
|
163
167
|
|
164
168
|
filedict_header_t *data = (filedict_header_t *)filedict->data;
|
165
169
|
assert(initial_bucket_count <= UINT_MAX);
|
166
|
-
|
167
|
-
data->
|
170
|
+
|
171
|
+
if (data->initial_bucket_count == 0) {
|
172
|
+
data->initial_bucket_count = initial_bucket_count;
|
173
|
+
data->hashmap_count = 1;
|
174
|
+
}
|
168
175
|
}
|
169
176
|
|
170
177
|
/*
|
@@ -272,7 +279,7 @@ try_again:
|
|
272
279
|
filedict->data = mmap(
|
273
280
|
filedict->data,
|
274
281
|
new_data_len,
|
275
|
-
PROT_READ | PROT_WRITE,
|
282
|
+
PROT_READ | ((filedict->flags & O_RDWR) ? PROT_WRITE : 0),
|
276
283
|
MAP_SHARED,
|
277
284
|
filedict->fd,
|
278
285
|
0
|
@@ -286,6 +293,27 @@ try_again:
|
|
286
293
|
goto try_again;
|
287
294
|
}
|
288
295
|
|
296
|
+
/*
|
297
|
+
* Resizes the filedict based on the header hashmap count and initial bucket count.
|
298
|
+
* Naturally, your pointers into the map will become invalid after calling this.
|
299
|
+
*/
|
300
|
+
static void filedict_resize(filedict_t *filedict) {
|
301
|
+
filedict_header_t *header = (filedict_header_t*)filedict->data;
|
302
|
+
size_t computed_size = filedict_file_size(header->initial_bucket_count, header->hashmap_count);
|
303
|
+
|
304
|
+
munmap(filedict->data, filedict->data_len);
|
305
|
+
filedict->data = mmap(
|
306
|
+
filedict->data,
|
307
|
+
computed_size,
|
308
|
+
PROT_READ | ((filedict->flags & O_RDWR) ? PROT_WRITE : 0),
|
309
|
+
MAP_SHARED,
|
310
|
+
filedict->fd,
|
311
|
+
0
|
312
|
+
);
|
313
|
+
if (filedict->data == MAP_FAILED) { filedict->error = strerror(errno); return; }
|
314
|
+
filedict->data_len = computed_size;
|
315
|
+
}
|
316
|
+
|
289
317
|
/*
|
290
318
|
* There are 3 "levels" to a filedict. From top to bottom:
|
291
319
|
* 1. Hashmap - which hashmap are we looking at? We create additional hashmaps to handle overflow.
|
@@ -365,19 +393,8 @@ static int filedict_read_advance_hashmap(filedict_read_t *read) {
|
|
365
393
|
size_t offset = filedict_file_size(header->initial_bucket_count, read->hashmap_i);
|
366
394
|
|
367
395
|
if (offset >= filedict->data_len) {
|
368
|
-
|
369
|
-
|
370
|
-
munmap(filedict->data, filedict->data_len);
|
371
|
-
filedict->data = mmap(
|
372
|
-
filedict->data,
|
373
|
-
computed_size,
|
374
|
-
PROT_READ | PROT_WRITE,
|
375
|
-
MAP_SHARED,
|
376
|
-
filedict->fd,
|
377
|
-
0
|
378
|
-
);
|
379
|
-
if (filedict->data == MAP_FAILED) { filedict->error = strerror(errno); return 0; }
|
380
|
-
filedict->data_len = computed_size;
|
396
|
+
filedict_resize(filedict);
|
397
|
+
if (filedict->error) log_return(0);
|
381
398
|
header = (filedict_header_t*)filedict->data;
|
382
399
|
}
|
383
400
|
|
data/lib/filedict/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: filedictrb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nigel Baillie
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-03
|
11
|
+
date: 2022-04-03 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
@@ -58,7 +58,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
58
58
|
- !ruby/object:Gem::Version
|
59
59
|
version: '0'
|
60
60
|
requirements: []
|
61
|
-
rubygems_version: 3.
|
61
|
+
rubygems_version: 3.1.6
|
62
62
|
signing_key:
|
63
63
|
specification_version: 4
|
64
64
|
summary: Uses filedict to emulate a file-backed Hash<Set<String>>
|