Coder Social home page Coder Social logo

julstrat / strmap Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 1.62 MB

Simple alternative to hcreate_r, hsearch_r, hdestroy_r GNU extensions

License: The Unlicense

Makefile 0.13% C 10.49% C++ 89.23% Python 0.15%
hash-map string linear-probing open-addressing hash-table backshift-deletion hashmap hashtable c

strmap's Introduction

C/C++ CI Build status GitHub license

strmap

strmap - simple alternative to hcreate_r, hdestroy_r, hsearch_r GNU extensions.

Implementation

  • Open addressing with linear probing for collision resolution.
  • Auto grow feature.
  • Back shift key deletion algorithm.
  • STRMAP *sm_create_from() - creates new strmap from existing.
  • foreach read-only keys iterator.
  • Probes mean, variance statistics.
  • String polynomial hash function

hash(sn) = s[0]*257n-1 + s[1]*257n-2 + s[2]*257n-3 + ... + s[n-1]*2570

Benchmark

  • robin_hood: strmap vs robin-hood-hashing. ASCII letters and digits permutations - 8000000 keys.

Load factor: 0.7
Mean: 1.16595
Variance: 9.43266

Load factor: 0.7
Mean: 1.32653
Variance: 14.8107

  • bench: ASCII letters and digits permutations - 3700000 keys.

Load factor: 0.7
Mean: 1.26022
Variance: 11.3293

API

    STRMAP *sm_create(size_t size);

Create a string map which can contain at least size elements.


    STRMAP *sm_create_from(const STRMAP * sm, size_t size);

Create strmap from existing.


    SM_RESULT sm_lookup(const STRMAP * sm, const char *key,
                        SM_ENTRY * item);

Retrieves user associated data for given key.


    SM_RESULT sm_insert(STRMAP * sm, const char *key, const void *data,
                        SM_ENTRY * item);

Insert key and user data.


    SM_RESULT sm_update(STRMAP * sm, const char *key, const void *data,
                        SM_ENTRY * item);

Update user data for given key.


    SM_RESULT sm_upsert(STRMAP * sm, const char *key, const void *data,
                        SM_ENTRY * item);

Update user data for given key or insert if key not exists.


    SM_RESULT sm_remove(STRMAP * sm, const char *key, SM_ENTRY * item);

Remove key

Based on M. A. Kolosovskiy, "Simple implementation of deletion from open-address hash table".


    void sm_foreach(const STRMAP * sm, void (*action) (SM_ENTRY item, void *ctx), void *ctx);

For each callback.


    void sm_clear(STRMAP * sm);

Remove all keys.


    size_t sm_size(const STRMAP * sm);

Return number of keys.


    double sm_probes_mean(const STRMAP * sm);
    double sm_probes_var(const STRMAP * sm);

Probes mean, variance.


    double sm_load_factor(const STRMAP * sm);

Load factor.


    void sm_free(STRMAP * sm);

Remove all keys and free memory allocated for the map structure.


    size_t poly_hashs(const char *key);

String hash.

strmap's People

Contributors

julstrat avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.