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

Headers for map.c. More...

#include "lib/testsupport/testsupport.h"
#include "lib/cc/torint.h"
#include "ext/siphash.h"

Go to the source code of this file.

Macros

#define DECLARE_MAP_FNS(mapname_t, keytype, prefix)
 
#define MAP_FREE_AND_NULL(mapname_t, map, fn)
 
#define strmap_free(map, fn)   MAP_FREE_AND_NULL(strmap, (map), (fn))
 
#define digestmap_free(map, fn)   MAP_FREE_AND_NULL(digestmap, (map), (fn))
 
#define digest256map_free(map, fn)   MAP_FREE_AND_NULL(digest256map, (map), (fn))
 
#define MAP_FOREACH(prefix, map, keytype, keyvar, valtype, valvar)
 
#define MAP_FOREACH_MODIFY(prefix, map, keytype, keyvar, valtype, valvar)
 
#define MAP_DEL_CURRENT(keyvar)
 
#define MAP_FOREACH_END   } STMT_END ;
 
#define DIGESTMAP_FOREACH(map, keyvar, valtype, valvar)    MAP_FOREACH(digestmap, map, const char *, keyvar, valtype, valvar)
 
#define DIGESTMAP_FOREACH_MODIFY(map, keyvar, valtype, valvar)    MAP_FOREACH_MODIFY(digestmap, map, const char *, keyvar, valtype, valvar)
 
#define DIGESTMAP_FOREACH_END   MAP_FOREACH_END
 
#define DIGEST256MAP_FOREACH(map, keyvar, valtype, valvar)    MAP_FOREACH(digest256map, map, const uint8_t *, keyvar, valtype, valvar)
 
#define DIGEST256MAP_FOREACH_MODIFY(map, keyvar, valtype, valvar)
 
#define DIGEST256MAP_FOREACH_END   MAP_FOREACH_END
 
#define STRMAP_FOREACH(map, keyvar, valtype, valvar)    MAP_FOREACH(strmap, map, const char *, keyvar, valtype, valvar)
 
#define STRMAP_FOREACH_MODIFY(map, keyvar, valtype, valvar)    MAP_FOREACH_MODIFY(strmap, map, const char *, keyvar, valtype, valvar)
 
#define STRMAP_FOREACH_END   MAP_FOREACH_END
 
#define DECLARE_TYPED_DIGESTMAP_FNS(prefix, mapname_t, valtype)
 

Functions

 DECLARE_MAP_FNS (strmap_t, const char *, strmap)
 
 DECLARE_MAP_FNS (digestmap_t, const char *, digestmap)
 
 DECLARE_MAP_FNS (digest256map_t, const uint8_t *, digest256map)
 
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

Headers for map.c.

Definition in file map.h.

Macro Definition Documentation

◆ DECLARE_MAP_FNS

#define DECLARE_MAP_FNS (   mapname_t,
  keytype,
  prefix 
)
Value:
typedef struct mapname_t mapname_t; \
typedef struct prefix##_entry_t *prefix##_iter_t; \
MOCK_DECL(mapname_t*, prefix##_new, (void)); \
void* prefix##_set(mapname_t *map, keytype key, void *val); \
void* prefix##_get(const mapname_t *map, keytype key); \
void* prefix##_remove(mapname_t *map, keytype key); \
MOCK_DECL(void, prefix##_free_, (mapname_t *map, void (*free_val)(void*))); \
int prefix##_isempty(const mapname_t *map); \
int prefix##_size(const mapname_t *map); \
prefix##_iter_t *prefix##_iter_init(mapname_t *map); \
prefix##_iter_t *prefix##_iter_next(mapname_t *map, prefix##_iter_t *iter); \
prefix##_iter_t *prefix##_iter_next_rmv(mapname_t *map, \
prefix##_iter_t *iter); \
void prefix##_iter_get(prefix##_iter_t *iter, keytype *keyp, void **valp); \
int prefix##_iter_done(prefix##_iter_t *iter); \
void prefix##_assert_ok(const mapname_t *map)

Definition at line 20 of file map.h.

◆ DIGEST256MAP_FOREACH_MODIFY

#define DIGEST256MAP_FOREACH_MODIFY (   map,
  keyvar,
  valtype,
  valvar 
)
Value:
MAP_FOREACH_MODIFY(digest256map, map, const uint8_t *, \
keyvar, valtype, valvar)
#define MAP_FOREACH_MODIFY(prefix, map, keytype, keyvar, valtype, valvar)
Definition: map.h:122

Definition at line 172 of file map.h.

◆ DIGESTMAP_FOREACH

#define DIGESTMAP_FOREACH (   map,
  keyvar,
  valtype,
  valvar 
)     MAP_FOREACH(digestmap, map, const char *, keyvar, valtype, valvar)

As MAP_FOREACH, but does not require declaration of prefix or keytype. Example use: DIGESTMAP_FOREACH(m, k, routerinfo_t *, r) { // use k and r } DIGESTMAP_FOREACH_END.

Definition at line 154 of file map.h.

◆ DIGESTMAP_FOREACH_END

#define DIGESTMAP_FOREACH_END   MAP_FOREACH_END

Used to end a DIGESTMAP_FOREACH() block.

Definition at line 168 of file map.h.

◆ DIGESTMAP_FOREACH_MODIFY

#define DIGESTMAP_FOREACH_MODIFY (   map,
  keyvar,
  valtype,
  valvar 
)     MAP_FOREACH_MODIFY(digestmap, map, const char *, keyvar, valtype, valvar)

As MAP_FOREACH_MODIFY, but does not require declaration of prefix or keytype. Example use: DIGESTMAP_FOREACH_MODIFY(m, k, routerinfo_t *, r) { if (is_very_old(r)) MAP_DEL_CURRENT(k); } DIGESTMAP_FOREACH_END.

Definition at line 165 of file map.h.

◆ MAP_DEL_CURRENT

#define MAP_DEL_CURRENT (   keyvar)
Value:
STMT_BEGIN \
keyvar##_del = 1; \
STMT_END

Used with MAP_FOREACH_MODIFY to remove the currently-iterated-upon member of the map.

Definition at line 140 of file map.h.

◆ MAP_FOREACH

#define MAP_FOREACH (   prefix,
  map,
  keytype,
  keyvar,
  valtype,
  valvar 
)
Value:
STMT_BEGIN \
prefix##_iter_t *keyvar##_iter; \
for (keyvar##_iter = prefix##_iter_init(map); \
!prefix##_iter_done(keyvar##_iter); \
keyvar##_iter = prefix##_iter_next(map, keyvar##_iter)) { \
keytype keyvar; \
void *valvar##_voidp; \
valtype valvar; \
prefix##_iter_get(keyvar##_iter, &keyvar, &valvar##_voidp); \
valvar = valvar##_voidp;

Iterates over the key-value pairs in a map map in order. prefix is as for DECLARE_MAP_FNS (i.e., strmap or digestmap). The map's keys and values are of type keytype and valtype respectively; each iteration assigns them to keyvar and valvar.

Example use: MAP_FOREACH(digestmap, m, const char *, k, routerinfo_t *, r) { // use k and r } MAP_FOREACH_END.

Definition at line 82 of file map.h.

◆ MAP_FOREACH_END

#define MAP_FOREACH_END   } STMT_END ;

Used to end a MAP_FOREACH() block.

Definition at line 146 of file map.h.

◆ MAP_FOREACH_MODIFY

#define MAP_FOREACH_MODIFY (   prefix,
  map,
  keytype,
  keyvar,
  valtype,
  valvar 
)
Value:
STMT_BEGIN \
prefix##_iter_t *keyvar##_iter; \
int keyvar##_del=0; \
for (keyvar##_iter = prefix##_iter_init(map); \
!prefix##_iter_done(keyvar##_iter); \
keyvar##_iter = keyvar##_del ? \
prefix##_iter_next_rmv(map, keyvar##_iter) : \
prefix##_iter_next(map, keyvar##_iter)) { \
keytype keyvar; \
void *valvar##_voidp; \
valtype valvar; \
keyvar##_del=0; \
prefix##_iter_get(keyvar##_iter, &keyvar, &valvar##_voidp); \
valvar = valvar##_voidp;

As MAP_FOREACH, except allows members to be removed from the map during the iteration via MAP_DEL_CURRENT. Example use:

Example use: MAP_FOREACH(digestmap, m, const char *, k, routerinfo_t *, r) { if (is_very_old(r)) MAP_DEL_CURRENT(k); } MAP_FOREACH_END.

Definition at line 122 of file map.h.

◆ MAP_FREE_AND_NULL

#define MAP_FREE_AND_NULL (   mapname_t,
  map,
  fn 
)
Value:
do { \
mapname_t ## _free_((map), (fn)); \
(map) = NULL; \
} while (0)

Definition at line 46 of file map.h.

Function Documentation

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