filedictrb 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aad965d1fb0dd25c74c20f917b2f71e0d48fc7d6dea59bab8ad2c5990b3fb8fe
4
- data.tar.gz: cd8c479f17d113b19d5ef89d565aeab6c51305e1e0f81dab3d8d6a538555009b
3
+ metadata.gz: f023c0d5acca6fc0f6355bae7c34f61eb5682f9f4652f83dd8befefac6f2c050
4
+ data.tar.gz: de7ba4f1fcf57e21771312bf9bb8daacdfc39a044e9ef263a81494bb6e976dca
5
5
  SHA512:
6
- metadata.gz: 2dc64caded0eadba4cb03da2dfb926b3c488d6773df59087752953371e5dfabeeac4625478f0ac33a26c4a60f76105a8026ee49aa6e2c700437c0e992ba6a6fe
7
- data.tar.gz: 7e392f4e734fbe940fb4d86c7a04700edcad3cbab286d4103f6846dbcadb1f2fd01ac8a6a272dd31e542ded3fb919fcfa6b566919161ab1cc3782a56692a2281
6
+ metadata.gz: 2cb1f1f1a43a0494aa95f8d31d0b1b490f63ce07c57bcc1e6af2003064656784034064cebefd8247b886174e3e57c600c4464e2eba69a61cf7720c6cee9fcc1e
7
+ data.tar.gz: 3f4f4dbf014f9af21ad104a3282f09ce7d07c22f70c60e5e33b43c58159bb403567e42116896091062a527bd881524d15db9b8724a16065395b0cdd6cdb715c1
@@ -131,6 +131,28 @@ static size_t filedict_file_size(size_t initial_bucket_count, size_t hashmap_cou
131
131
  return result;
132
132
  }
133
133
 
134
+ /*
135
+ * Resizes the filedict based on the header hashmap count and initial bucket count.
136
+ * Naturally, your pointers into the map will become invalid after calling this.
137
+ */
138
+ static void filedict_resize(filedict_t *filedict) {
139
+ filedict_header_t *header = (filedict_header_t*)filedict->data;
140
+ size_t computed_size = filedict_file_size(header->initial_bucket_count, header->hashmap_count);
141
+ if (computed_size <= filedict->data_len) return;
142
+
143
+ munmap(filedict->data, filedict->data_len);
144
+ filedict->data = mmap(
145
+ filedict->data,
146
+ computed_size,
147
+ PROT_READ | ((filedict->flags & O_RDWR) ? PROT_WRITE : 0),
148
+ MAP_SHARED,
149
+ filedict->fd,
150
+ 0
151
+ );
152
+ if (filedict->data == MAP_FAILED) { filedict->error = strerror(errno); return; }
153
+ filedict->data_len = computed_size;
154
+ }
155
+
134
156
  /*
135
157
  * This opens a new file for reading and writing, optionally letting you specify the initial bucket count.
136
158
  */
@@ -149,12 +171,20 @@ static void filedict_open_f(
149
171
  int flags,
150
172
  unsigned int initial_bucket_count
151
173
  ) {
174
+ struct stat info;
175
+
152
176
  filedict->flags = flags;
153
177
  filedict->fd = open(filename, flags, 0666);
154
178
  if (filedict->fd == -1) { filedict->error = strerror(errno); return; }
179
+ if (fstat(filedict->fd, &info) != 0) { filedict->error = strerror(errno); return; }
180
+
181
+ if (info.st_size == 0 && (flags & O_RDWR)) {
182
+ filedict->data_len = filedict_file_size(initial_bucket_count, 1);
183
+ ftruncate(filedict->fd, filedict->data_len);
184
+ } else {
185
+ filedict->data_len = info.st_size;
186
+ }
155
187
 
156
- filedict->data_len = filedict_file_size(initial_bucket_count, 1);
157
- ftruncate(filedict->fd, filedict->data_len);
158
188
  filedict->data = mmap(
159
189
  NULL,
160
190
  filedict->data_len,
@@ -293,27 +323,6 @@ try_again:
293
323
  goto try_again;
294
324
  }
295
325
 
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
-
317
326
  /*
318
327
  * There are 3 "levels" to a filedict. From top to bottom:
319
328
  * 1. Hashmap - which hashmap are we looking at? We create additional hashmaps to handle overflow.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Filedict
4
- VERSION = "0.1.3"
4
+ VERSION = "0.1.4"
5
5
  end
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.3
4
+ version: 0.1.4
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-04-03 00:00:00.000000000 Z
11
+ date: 2022-04-04 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: