Coder Social home page Coder Social logo

hash's Introduction

hash

C hash implementation based on khash.

Installation

Install with clib:

$ clib install clibs/hash

Example

hash_t *hash = hash_new();
hash_set(hash, "name", "tobi");
hash_set(hash, "species", "ferret");
hash_set(hash, "age", "2");

hash_each(hash, {
  printf("%s: %s\n", key, (char *) val);
});

hash_free(hash);

yields:

species: ferret
age: 2
name: tobi

API

hash_t

The hash type.

hash_t *hash_new()

Allocate and initialize a new hash.

hash_free(hash_t *self)

Free the hash, you must free values appropriately.

unsigned int hash_size(hash_t *self)

Return the number of values in the hash table.

void hash_clear(hash_t *self)

Remove all values from the hash.

void hash_set(hash_t *self, char *key, void *val);

Set key to val.

void *hash_get(hash_t *self, char *key);

Get value for key or NULL.

int hash_has(hash_t *self, char *key);

Check if the hash contains key.

void hash_del(hash_t *self, char *key);

Remove key from the hash.

hash_each(hash_t *self, block)

A macro for iterating key/value pairs.

hash_each(users, {
  printf("%s: %s\n", key, (char *) val);
})

hash_each_key(hash_t *self, block)

A macro for iterating keys only.

hash_each_key(users, {
  printf("%s\n", key);
})

hash_each_val(hash_t *self, block)

A macro for iterating values only.

hash_each_val(users, {
  printf("%s\n", (char *) val);
})

hash's People

Contributors

jonathanmarvens avatar msiemens avatar tj avatar

Watchers

 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.