cfengine  3.15.4
About: CFEngine is a configuration management system for configuring and maintaining Unix-like computers (using an own high level policy language). Community version.
  Fossies Dox: cfengine-3.15.4.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

map.c File Reference
#include <platform.h>
#include <map.h>
#include <alloc.h>
#include <array_map_priv.h>
#include <hash_map_priv.h>
#include <string_lib.h>
Include dependency graph for map.c:

Go to the source code of this file.

Data Structures

struct  Map_
 

Macros

#define DEFAULT_HASHMAP_INIT_SIZE   128
 

Functions

static unsigned IdentityHashFn (const void *ptr, unsigned int seed)
 
static bool IdentityEqualFn (const void *p1, const void *p2)
 
static void NopDestroyFn (void *p1)
 
static bool IsArrayMap (const Map *map)
 
MapMapNew (MapHashFn hash_fn, MapKeyEqualFn equal_fn, MapDestroyDataFn destroy_key_fn, MapDestroyDataFn destroy_value_fn)
 
size_t MapSize (const Map *map)
 
static void ConvertToHashMap (Map *map)
 
bool MapInsert (Map *map, void *key, void *value)
 
static MapKeyValueMapGetRaw (const Map *map, const void *key)
 
bool MapHasKey (const Map *map, const void *key)
 
void * MapGet (Map *map, const void *key)
 
bool MapRemove (Map *map, const void *key)
 
void MapClear (Map *map)
 
void MapSoftDestroy (Map *map)
 
void MapDestroy (Map *map)
 
bool MapContainsSameKeys (const Map *map1, const Map *map2)
 
void MapPrintStats (const Map *map, FILE *f)
 
MapIterator MapIteratorInit (Map *map)
 
MapKeyValueMapIteratorNext (MapIterator *i)
 
StringMapStringMapNew (void)
 
bool StringMapInsert (const StringMap *map, char *key, char *value)
 
bool StringMapHasKey (const StringMap *map, const char *key)
 
char * StringMapGet (const StringMap *map, const char *key)
 
bool StringMapRemove (const StringMap *map, const char *key)
 
void StringMapClear (StringMap *map)
 
size_t StringMapSize (const StringMap *map)
 
void StringMapDestroy (StringMap *map)
 
void StringMapSoftDestroy (StringMap *map)
 
bool StringMapContainsSameKeys (const StringMap *map1, const StringMap *map2)
 
void StringMapPrintStats (const StringMap *map, FILE *f)
 

Macro Definition Documentation

◆ DEFAULT_HASHMAP_INIT_SIZE

#define DEFAULT_HASHMAP_INIT_SIZE   128

Definition at line 43 of file map.c.

Function Documentation

◆ ConvertToHashMap()

◆ IdentityEqualFn()

static bool IdentityEqualFn ( const void *  p1,
const void *  p2 
)
static

Definition at line 61 of file map.c.

Referenced by MapNew().

◆ IdentityHashFn()

static unsigned IdentityHashFn ( const void *  ptr,
unsigned int  seed 
)
static

Definition at line 56 of file map.c.

Referenced by MapNew().

◆ IsArrayMap()

static bool IsArrayMap ( const Map map)
static

◆ MapClear()

void MapClear ( Map map)

Definition at line 240 of file map.c.

References Map_::arraymap, ArrayMapClear(), Map_::hashmap, HashMapClear(), IsArrayMap(), and NULL.

Referenced by SetClear().

◆ MapContainsSameKeys()

bool MapContainsSameKeys ( const Map map1,
const Map map2 
)

Returns whether the two maps contain the same keys. The values DO NOT have to be equal, just the keys.

Definition at line 286 of file map.c.

References MapKeyValue::key, MapHasKey(), MapIteratorInit(), MapIteratorNext(), MapSize(), and NULL.

Referenced by SetIsEqual().

◆ MapDestroy()

void MapDestroy ( Map map)

◆ MapGet()

void* MapGet ( Map map,
const void *  key 
)

Definition at line 213 of file map.c.

References MapGetRaw(), NULL, and MapKeyValue::value.

Referenced by PolicyCheckDuplicateHandles().

◆ MapGetRaw()

static MapKeyValue* MapGetRaw ( const Map map,
const void *  key 
)
static

Definition at line 189 of file map.c.

References Map_::arraymap, ArrayMapGet(), Map_::hashmap, HashMapGet(), IsArrayMap(), and NULL.

Referenced by MapGet(), and MapHasKey().

◆ MapHasKey()

bool MapHasKey ( const Map map,
const void *  key 
)

Definition at line 203 of file map.c.

References MapGetRaw(), and NULL.

Referenced by MapContainsSameKeys(), and SetContains().

◆ MapInsert()

bool MapInsert ( Map map,
void *  key,
void *  value 
)

Insert a key-value pair in the map. If the key is in the map, value get replaced. Old value is destroyed.

Return values
trueif key exists already.

Definition at line 161 of file map.c.

References Map_::arraymap, ArrayMapInsert(), ConvertToHashMap(), Map_::hashmap, HashMapInsert(), IsArrayMap(), and NULL.

Referenced by PolicyCheckDuplicateHandles(), and SetAdd().

◆ MapIteratorInit()

◆ MapIteratorNext()

◆ MapNew()

Map* MapNew ( MapHashFn  hash_fn,
MapKeyEqualFn  equal_fn,
MapDestroyDataFn  destroy_key_fn,
MapDestroyDataFn  destroy_value_fn 
)

◆ MapPrintStats()

void MapPrintStats ( const Map map,
FILE *  f 
)

Definition at line 305 of file map.c.

References Map_::hashmap, HashMapPrintStats(), IsArrayMap(), and NULL.

◆ MapRemove()

bool MapRemove ( Map map,
const void *  key 
)

Definition at line 226 of file map.c.

References Map_::arraymap, ArrayMapRemove(), Map_::hashmap, HashMapRemove(), IsArrayMap(), and NULL.

Referenced by SetRemove().

◆ MapSize()

size_t MapSize ( const Map map)

Definition at line 112 of file map.c.

References Map_::arraymap, IsArrayMap(), MapIteratorInit(), MapIteratorNext(), NULL, and ArrayMap::size.

Referenced by MapContainsSameKeys(), and SetSize().

◆ MapSoftDestroy()

void MapSoftDestroy ( Map map)

◆ NopDestroyFn()

static void NopDestroyFn ( void *  p1)
static

Definition at line 66 of file map.c.

Referenced by MapNew().

◆ StringMapClear()

void StringMapClear ( StringMap map)

Definition at line 359 of file map.c.

◆ StringMapContainsSameKeys()

bool StringMapContainsSameKeys ( const StringMap map1,
const StringMap map2 
)

Definition at line 359 of file map.c.

◆ StringMapDestroy()

void StringMapDestroy ( StringMap map)

Definition at line 359 of file map.c.

Referenced by ClearAuthAndACLs(), LoadPolicy(), PolicyDestroy(), and ScanLastSeenQuality().

◆ StringMapGet()

char* StringMapGet ( const StringMap map,
const char *  key 
)

Definition at line 359 of file map.c.

Referenced by PolicyGetPolicyFileHash(), ScanLastSeenQuality(), and ShortcutsExpand().

◆ StringMapHasKey()

bool StringMapHasKey ( const StringMap map,
const char *  key 
)

Definition at line 359 of file map.c.

Referenced by AccessPromise_AddAccessConstraints(), and LoadPolicyFile().

◆ StringMapInsert()

bool StringMapInsert ( const StringMap map,
char *  key,
char *  value 
)

◆ StringMapNew()

StringMap* StringMapNew ( void  )

Definition at line 359 of file map.c.

Referenced by KeepPromises(), LoadDatabaseToStringMap(), and LoadPolicy().

◆ StringMapPrintStats()

void StringMapPrintStats ( const StringMap map,
FILE *  f 
)

Definition at line 359 of file map.c.

◆ StringMapRemove()

bool StringMapRemove ( const StringMap map,
const char *  key 
)

Definition at line 359 of file map.c.

◆ StringMapSize()

size_t StringMapSize ( const StringMap map)

Definition at line 359 of file map.c.

◆ StringMapSoftDestroy()

void StringMapSoftDestroy ( StringMap map)

Definition at line 359 of file map.c.

Referenced by PolicyMerge().