filedictrb 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 64d09435d5e09d917e12a06932a75ddf365b081a9caa1253a3b11a53a235196c
4
- data.tar.gz: 4cd1fedaa0035da30c2d9572eb28dd190cab901803089b164c36ba4d5776d36c
3
+ metadata.gz: 3c8fd3a6260d33ec56a995b4116af3cdb60ec8b52fa8aee688c7fd0b305b14ae
4
+ data.tar.gz: '0349634431c7e9abde136b1503e4ae23a8855236cdafb21ee9157f946456c16c'
5
5
  SHA512:
6
- metadata.gz: d232d34e3b99221baf055c56ca672b2536d910103a3a4dd6bab1be9005270db86cda72690f1dd56ed230fb0214ef4cecae45a9f8ae5931b7ebcb3288df8492e2
7
- data.tar.gz: de03f2dc36efad352a54f647f3275cc15bae641799e3b2ca258cdbb08100103493ac35e2c37e327f7f39feb2dc92eb80af6fb3c4cd645fad8794612ee0cffcfc
6
+ metadata.gz: 5811b3a6fba572d75e39d9fec5d7e2d6cb1bde1701604d80e0fa040de624b7b7c7edca928293fa9814b91614a3c5d6289f15e55becc7e4b1153d34212216ec39
7
+ data.tar.gz: db8da5021c456578f8654bce8feab2a7f4138f9c3f405423fb441ff3248cc3924b451da94473d5eac1b9d3eccda643d22582b278dbaebb6a7087f819bf896e08
@@ -38,7 +38,7 @@ typedef struct filedict_header_t {
38
38
  } __attribute__ ((__packed__)) filedict_header_t;
39
39
 
40
40
  typedef struct filedict_read_t {
41
- const filedict_t *filedict;
41
+ filedict_t *filedict;
42
42
  const char *key;
43
43
  const char *value;
44
44
  filedict_bucket_t *bucket;
@@ -353,7 +353,7 @@ static int filedict_read_advance_entry(filedict_read_t *read) {
353
353
  * Returns 0 when there are no more hashmaps, or the latest hashmap has no matching entries.
354
354
  */
355
355
  static int filedict_read_advance_hashmap(filedict_read_t *read) {
356
- const filedict_t *filedict = read->filedict;
356
+ filedict_t *filedict = read->filedict;
357
357
 
358
358
  assert(filedict);
359
359
  assert(filedict->data);
@@ -363,6 +363,24 @@ static int filedict_read_advance_hashmap(filedict_read_t *read) {
363
363
  if (read->hashmap_i >= header->hashmap_count) log_return(0);
364
364
 
365
365
  size_t offset = filedict_file_size(header->initial_bucket_count, read->hashmap_i);
366
+
367
+ if (offset >= filedict->data_len) {
368
+ /* Need to resize! */
369
+ size_t computed_size = filedict_file_size(header->initial_bucket_count, header->hashmap_count);
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;
381
+ header = (filedict_header_t*)filedict->data;
382
+ }
383
+
366
384
  filedict_bucket_t *hashmap = filedict->data + offset;
367
385
 
368
386
  read->bucket_count = (size_t)header->initial_bucket_count << read->hashmap_i;
@@ -377,7 +395,7 @@ static int filedict_read_advance_hashmap(filedict_read_t *read) {
377
395
  /*
378
396
  * Returns a "read" at the given key. If there's a hit, <return>.value will have the value.
379
397
  */
380
- static filedict_read_t filedict_get(const filedict_t *filedict, const char *key) {
398
+ static filedict_read_t filedict_get(filedict_t *filedict, const char *key) {
381
399
  filedict_read_t read;
382
400
  read.filedict = filedict;
383
401
  read.key = key;
@@ -3,7 +3,6 @@
3
3
 
4
4
  extern VALUE mFiledict;
5
5
  VALUE cHash;
6
- VALUE mSetExt;
7
6
  VALUE cSet;
8
7
 
9
8
  ID id_add;
@@ -89,7 +88,7 @@ static VALUE fd_set_add(int argc, VALUE *argv, VALUE self) {
89
88
  VALUE fd_hash_ruby_object = rb_ivar_get(self, id_fd_hash);
90
89
 
91
90
  if (fd_hash_ruby_object == Qnil) {
92
- return self;
91
+ return rb_call_super(argc, argv);
93
92
  }
94
93
 
95
94
  fd_hash_t *fd_hash = RTYPEDDATA_DATA(fd_hash_ruby_object);
@@ -124,8 +123,6 @@ static VALUE fd_hash_access(VALUE self, VALUE key) {
124
123
  rb_ivar_set(result, id_fd_hash, self);
125
124
  rb_ivar_set(result, id_fd_key, key);
126
125
 
127
- rb_extend_object(result, mSetExt);
128
-
129
126
  return result;
130
127
  }
131
128
 
@@ -139,9 +136,8 @@ void fdrb_init_hash() {
139
136
 
140
137
  VALUE rb_cSet = rb_define_class("Set", rb_cObject);
141
138
  cSet = rb_define_class_under(mFiledict, "Set", rb_cSet);
142
- mSetExt = rb_define_module_under(mFiledict, "SetExt");
143
139
 
144
- rb_define_method(mSetExt, "add", fd_set_add, -1);
140
+ rb_define_method(cSet, "add", fd_set_add, -1);
145
141
 
146
142
  id_add = rb_intern("add");
147
143
  id_remove = rb_intern("remove");
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Filedict
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.2"
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.1
4
+ version: 0.1.2
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-30 00:00:00.000000000 Z
11
+ date: 2022-03-31 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: