reactor-c 1.0
C Runtime for Lingua Franca
Loading...
Searching...
No Matches
hashmap.h File Reference

Defines a generic, non-resizing hashmap data type. More...

#include <stddef.h>
#include <assert.h>
#include <stdbool.h>

Go to the source code of this file.

Data Structures

struct  hashmap_entry_t
 A hashmap entry. More...
struct  hashmap_t
 A hashmap. More...

Macros

#define HASH_OF(key)
#define HASHMAP(token)
#define K   void*
#define V   void*

Typedefs

typedef struct hashmap_entry_t hashmap_entry_t
 A hashmap entry.
typedef struct hashmap_t hashmap_t
 A hashmap.

Functions

void hashmap_free (hashmap_t *hashmap)
 Free all memory used by the given hashmap.
void * hashmap_get (hashmap_t *hashmap, void *key)
 Get the value associated with the given key.
static hashmap_entry_thashmap_get_actual_address (hashmap_t *hashmap, void *key)
 Return the actual address of the hashmap entry corresponding to key, or the address of the closest empty entry if no such entry exists.
static hashmap_entry_thashmap_get_ideal_address (hashmap_t *hashmap, void *key)
hashmap_thashmap_new (size_t capacity, void *nothing)
 Construct a new hashmap object.
void hashmap_put (hashmap_t *hashmap, void *key, void *value)
 Associate a value with the given key.

Detailed Description

Defines a generic, non-resizing hashmap data type.

Author
Peter Donovan (peterdonovan@berkeley.edu)

Hashmaps are defined by redefining K, V, HASH_OF, and HASHMAP, and including this file. A default hashmap type is defined here. See pointer_hashmap.h for an example of a hashmap declaration.

  • K and V must be the types of keys and values of the hashmap, respectively.
  • HASH_OF must be the hash of a key.
  • HASHMAP must be a function-like macro that prefixes tokens with the name of the hashmap. For example, the name of the hashmap data type is given by evaluation of the macro HASHMAP(t) so that it is "t" prefixed with the name of the hashmap. The function names associated with the data type are similar.

Macro Definition Documentation

◆ HASH_OF

#define HASH_OF ( key)
Value:
(size_t)key

◆ HASHMAP

#define HASHMAP ( token)
Value:
hashmap##_##token
#define _(c)

◆ K

#define K   void*

◆ V

#define V   void*

Function Documentation

◆ hashmap_get_ideal_address()

hashmap_entry_t * hashmap_get_ideal_address ( hashmap_t * hashmap,
void * key )
static