filedictrb 0.1.3 → 0.1.4
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 +4 -4
 - data/ext/filedict/filedict.h +32 -23
 - data/lib/filedict/version.rb +1 -1
 - metadata +2 -2
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: f023c0d5acca6fc0f6355bae7c34f61eb5682f9f4652f83dd8befefac6f2c050
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: de7ba4f1fcf57e21771312bf9bb8daacdfc39a044e9ef263a81494bb6e976dca
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 2cb1f1f1a43a0494aa95f8d31d0b1b490f63ce07c57bcc1e6af2003064656784034064cebefd8247b886174e3e57c600c4464e2eba69a61cf7720c6cee9fcc1e
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 3f4f4dbf014f9af21ad104a3282f09ce7d07c22f70c60e5e33b43c58159bb403567e42116896091062a527bd881524d15db9b8724a16065395b0cdd6cdb715c1
         
     | 
    
        data/ext/filedict/filedict.h
    CHANGED
    
    | 
         @@ -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.
         
     | 
    
        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.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- 
     | 
| 
      
 11 
     | 
    
         
            +
            date: 2022-04-04 00:00:00.000000000 Z
         
     | 
| 
       12 
12 
     | 
    
         
             
            dependencies: []
         
     | 
| 
       13 
13 
     | 
    
         
             
            description:
         
     | 
| 
       14 
14 
     | 
    
         
             
            email:
         
     |