tor  0.4.1.1-alpha-dev
Macros | Functions
map.h File Reference
#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(maptype, keytype, prefix)
 
#define MAP_FREE_AND_NULL(maptype, 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, maptype, 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 (   maptype,
  keytype,
  prefix 
)
Value:
typedef struct maptype maptype; \
typedef struct prefix##entry_t *prefix##iter_t; \
MOCK_DECL(maptype*, prefix##new, (void)); \
void* prefix##set(maptype *map, keytype key, void *val); \
void* prefix##get(const maptype *map, keytype key); \
void* prefix##remove(maptype *map, keytype key); \
MOCK_DECL(void, prefix##free_, (maptype *map, void (*free_val)(void*))); \
int prefix##isempty(const maptype *map); \
int prefix##size(const maptype *map); \
prefix##iter_t *prefix##iter_init(maptype *map); \
prefix##iter_t *prefix##iter_next(maptype *map, prefix##iter_t *iter); \
prefix##iter_t *prefix##iter_next_rmv(maptype *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 maptype *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:121

Definition at line 171 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 153 of file map.h.

◆ DIGESTMAP_FOREACH_END

#define DIGESTMAP_FOREACH_END   MAP_FOREACH_END

Used to end a DIGESTMAP_FOREACH() block.

Definition at line 167 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 164 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 139 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 81 of file map.h.

◆ MAP_FOREACH_END

#define MAP_FOREACH_END   } STMT_END ;

Used to end a MAP_FOREACH() block.

Definition at line 145 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 121 of file map.h.

◆ MAP_FREE_AND_NULL

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

Definition at line 45 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 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().