Tor  0.4.7.0-alpha-dev
Macros | Functions
map.c File Reference

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

#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 (strmap_impl, strmap_entry_t, node, strmap_entry_hash, strmap_entries_eq)
 
 HT_GENERATE2 (strmap_impl, strmap_entry_t, node, strmap_entry_hash, strmap_entries_eq, 0.6, tor_reallocarray_, tor_free_)
 
 HT_PROTOTYPE (digestmap_impl, digestmap_entry_t, node, digestmap_entry_hash, digestmap_entries_eq)
 
 HT_GENERATE2 (digestmap_impl, digestmap_entry_t, node, digestmap_entry_hash, digestmap_entries_eq, 0.6, tor_reallocarray_, tor_free_)
 
 HT_PROTOTYPE (digest256map_impl, digest256map_entry_t, node, digest256map_entry_hash, digest256map_entries_eq)
 
 HT_GENERATE2 (digest256map_impl, digest256map_entry_t, node, digest256map_entry_hash, digest256map_entries_eq, 0.6, tor_reallocarray_, tor_free_)
 
static void strmap_entry_free_ (strmap_entry_t *ent)
 
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.

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

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

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

◆ 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 360 of file map.c.

Referenced by addressmap_have_mapping(), addressmap_match_superdomains(), geoip_get_country(), or_state_remove_obsolete_lines(), and routerset_contains2().

◆ 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 372 of file map.c.

◆ 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 346 of file map.c.

Referenced by or_state_remove_obsolete_lines().