tor  0.4.1.1-alpha-dev
Macros | Functions
map.c File Reference
#include "lib/container/map.h"
#include "lib/ctime/di_ops.h"
#include "lib/defs/digest_sizes.h"
#include "lib/string/util_string.h"
#include "lib/malloc/malloc.h"
#include "lib/log/util_bug.h"
#include <stdlib.h>
#include <string.h>
#include "ext/ht.h"

Go to the source code of this file.

Macros

#define DEFINE_MAP_STRUCTS(maptype, keydecl, prefix)
 
#define strmap_entry_free(ent)   FREE_AND_NULL(strmap_entry_t, strmap_entry_free_, (ent))
 
#define digestmap_entry_free(ent)   FREE_AND_NULL(digestmap_entry_t, digestmap_entry_free_, (ent))
 
#define digest256map_entry_free(ent)   FREE_AND_NULL(digest256map_entry_t, digest256map_entry_free_, (ent))
 
#define IMPLEMENT_MAP_FNS(maptype, keytype, prefix)
 

Functions

 DEFINE_MAP_STRUCTS (strmap_t, char *key, strmap_)
 
 DEFINE_MAP_STRUCTS (digestmap_t, char key[DIGEST_LEN], digestmap_)
 
 DEFINE_MAP_STRUCTS (digest256map_t, uint8_t key[DIGEST256_LEN], digest256map_)
 
static int strmap_entries_eq (const strmap_entry_t *a, const strmap_entry_t *b)
 
static unsigned int strmap_entry_hash (const strmap_entry_t *a)
 
static int digestmap_entries_eq (const digestmap_entry_t *a, const digestmap_entry_t *b)
 
static unsigned int digestmap_entry_hash (const digestmap_entry_t *a)
 
static int digest256map_entries_eq (const digest256map_entry_t *a, const digest256map_entry_t *b)
 
static unsigned int digest256map_entry_hash (const digest256map_entry_t *a)
 
 HT_PROTOTYPE (HT_GENERATE2(strmap_impl, HT_GENERATE2(strmap_entry_t, HT_GENERATE2(node, HT_GENERATE2(strmap_entry_hash, HT_GENERATE2(strmap_entries_eq)
 
static void digestmap_entry_free_ (digestmap_entry_t *ent)
 
static void digest256map_entry_free_ (digest256map_entry_t *ent)
 
static void strmap_assign_tmp_key (strmap_entry_t *ent, const char *key)
 
static void digestmap_assign_tmp_key (digestmap_entry_t *ent, const char *key)
 
static void digest256map_assign_tmp_key (digest256map_entry_t *ent, const uint8_t *key)
 
static void strmap_assign_key (strmap_entry_t *ent, const char *key)
 
static void digestmap_assign_key (digestmap_entry_t *ent, const char *key)
 
static void digest256map_assign_key (digest256map_entry_t *ent, const uint8_t *key)
 
void * strmap_set_lc (strmap_t *map, const char *key, void *val)
 
void * strmap_get_lc (const strmap_t *map, const char *key)
 
void * strmap_remove_lc (strmap_t *map, const char *key)
 

Detailed Description

Hash-table implementations of a string-to-void* map, and of a digest-to-void* map.

Definition in file map.c.

Macro Definition Documentation

◆ DEFINE_MAP_STRUCTS

#define DEFINE_MAP_STRUCTS (   maptype,
  keydecl,
  prefix 
)
Value:
typedef struct prefix ## entry_t { \
HT_ENTRY(prefix ## entry_t) node; \
void *val; \
keydecl; \
} prefix ## entry_t; \
struct maptype { \
HT_HEAD(prefix ## impl, prefix ## entry_t) head; \
}

Helper: Declare an entry type and a map type to implement a mapping using ht.h. The map type will be called maptype. The key part of each entry is declared using the C declaration keydecl. All functions and types associated with the map get prefixed with prefix

Definition at line 30 of file map.c.

◆ IMPLEMENT_MAP_FNS

#define IMPLEMENT_MAP_FNS (   maptype,
  keytype,
  prefix 
)

Macro: implement all the functions for a map that are declared in map.h by the DECLARE_MAP_FNS() macro. You must additionally define a prefix_entry_free_() function to free entries (and their keys), a prefix_assign_tmp_key() function to temporarily set a stack-allocated entry to hold a key, and a prefix_assign_key() function to set a heap-allocated entry to hold a key.

Definition at line 167 of file map.c.

Function Documentation

◆ digest256map_entries_eq()

static int digest256map_entries_eq ( const digest256map_entry_t *  a,
const digest256map_entry_t *  b 
)
inlinestatic

Helper: compare digestmap_entry_t objects by key value.

Definition at line 74 of file map.c.

References DIGEST256_LEN, and tor_memeq().

◆ digest256map_entry_hash()

static unsigned int digest256map_entry_hash ( const digest256map_entry_t *  a)
inlinestatic

Helper: return a hash value for a digest_map_t.

Definition at line 82 of file map.c.

References DIGEST256_LEN.

◆ digestmap_entries_eq()

static int digestmap_entries_eq ( const digestmap_entry_t *  a,
const digestmap_entry_t *  b 
)
inlinestatic

Helper: compare digestmap_entry_t objects by key value.

Definition at line 60 of file map.c.

References DIGEST_LEN, and tor_memeq().

◆ digestmap_entry_hash()

static unsigned int digestmap_entry_hash ( const digestmap_entry_t *  a)
inlinestatic

Helper: return a hash value for a digest_map_t.

Definition at line 67 of file map.c.

References DIGEST_LEN.

◆ HT_PROTOTYPE()

HT_PROTOTYPE ( HT_GENERATE2(  channel_idmap,
HT_GENERATE2(  channel_idmap_entry_s,
HT_GENERATE2(  node,
HT_GENERATE2(  channel_idmap_hash,
HT_GENERATE2(  channel_idmap_eq 
)

Indicate whether a given channel state is valid.

Definition at line 87 of file map.c.

◆ strmap_entries_eq()

static int strmap_entries_eq ( const strmap_entry_t *  a,
const strmap_entry_t *  b 
)
inlinestatic

Helper: compare strmap_entry_t objects by key value.

Definition at line 46 of file map.c.

◆ strmap_entry_hash()

static unsigned int strmap_entry_hash ( const strmap_entry_t *  a)
inlinestatic

Helper: return a hash value for a strmap_entry_t.

Definition at line 53 of file map.c.

◆ strmap_get_lc()

void* strmap_get_lc ( const strmap_t *  map,
const char *  key 
)

Same as strmap_get, but first converts key to lowercase.

Definition at line 393 of file map.c.

Referenced by addressmap_have_mapping(), addressmap_match_superdomains(), cache_failure_intro_add(), cache_failure_intro_lookup(), MOCK_IMPL(), rend_cache_failure_remove(), and routerset_contains().

◆ strmap_remove_lc()

void* strmap_remove_lc ( strmap_t *  map,
const char *  key 
)

Same as strmap_remove, but first converts key to lowercase

Definition at line 405 of file map.c.

Referenced by rend_cache_failure_remove().

◆ strmap_set_lc()

void* strmap_set_lc ( strmap_t *  map,
const char *  key,
void *  val 
)

Same as strmap_set, but first converts key to lowercase.

Definition at line 379 of file map.c.

Referenced by cache_failure_intro_add().