Git Product home page Git Product logo

hmap's Introduction

C Hashmap implementation

Implements a hashmap with string as key. It uses Murmur hash algorithm to generate indexes from keys.

TODO

  • allow custom key generation function
  • allow any type as key
  • add replace option for existing keys

How to use

    typedef struct {
        ...
    } data_t;

    [...]

    // misc data
    data_t *d1 = malloc(sizeof(data_t));
    data_t *d2 = malloc(sizeof(data_t));
    data_t *d3 = malloc(sizeof(data_t));

    // create a hashmap
    hmap_t *h = hmap_new(64);
    if (NULL == h) {
        fprintf(stderr, "hmap_new failed\n");
        return;
    }

    // set somes keys, returns 0 on failure, 1 on success
    hmap_set(h, "key1", d1);
    hmap_set(h, "key2", d2);
    hmap_set(h, "keyX", d3);

    // get some data
    data_t* d = (data_t*)hmap_get(h, "key2");
    if (NULL == d) {
        fprintf(stderr, "hmap_get: key2 not found\n");
        return;
    }

    // unset a key
    hmap_unset(h, "keyX");

    hmap_free(h);

See hmap_test.c for more examples.

hmap's People

Watchers

Cavern 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.