TeoCCl library  0.1.7
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
map.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include "teoccl/map.h"
#include "teoccl/hash.h"
#include "teoccl/memory.h"

Macros

#define _SHOW_RESIZED_MSG_   0
 
#define _USE_PUT_   1
 
#define _USE_HASH_   0
 

Functions

size_t teoMapSize (teoMap *map)
 Get number of elements in TR-UPD map. More...
 
teoMapteoMapNew (size_t size, int auto_resize_f)
 Create new map. More...
 
void teoMapDestroy (teoMap *map)
 Destroy map. More...
 
void teoMapClear (teoMap *map)
 
uint8_t * teoMapGetFirst (teoMap *map, size_t *data_length)
 Get first available element from hash table. More...
 
uint8_t * teoMapAdd (teoMap *map, const uint8_t *key, size_t key_length, const uint8_t *data, size_t data_length)
 Add (or update) key data to the map. More...
 
uint8_t * teoMapGet (teoMap *map, const uint8_t *key, size_t key_length, size_t *data_length)
 Get key data from hash table. More...
 
int teoMapDelete (teoMap *map, const uint8_t *key, size_t key_length)
 Delete keys element from map. More...
 
teoMapIteratorteoMapIteratorNew (teoMap *map)
 Create new map iterator. More...
 
void teoMapIteratorReset (teoMapIterator *map_it, teoMap *map)
 Reset map iterator. More...
 
teoMapIteratorteoMapIteratorReverseNew (teoMap *map)
 Create new map reverse iterator. More...
 
void teoMapIteratorReverseReset (teoMapIterator *map_it, teoMap *map)
 Reset map iterator. More...
 
int teoMapIteratorFree (teoMapIterator *map_it)
 Destroy map iterator. More...
 
teoMapElementDatateoMapIteratorNext (teoMapIterator *map_it)
 Get next maps element. More...
 
teoMapElementDatateoMapIteratorPrev (teoMapIterator *map_it)
 Get previous maps element. More...
 
int teoMapForeach (teoMap *map, teoMapForeachFunction callback, void *user_data)
 Loop through map and call callback function with index and data in parameters. More...
 

Macro Definition Documentation

#define _SHOW_RESIZED_MSG_   0
#define _USE_HASH_   0
#define _USE_PUT_   1

Function Documentation

uint8_t* teoMapAdd ( teoMap map,
const uint8_t *  key,
size_t  key_length,
const uint8_t *  data,
size_t  data_length 
)

Add (or update) key data to the map.

Parameters
mapPointer to teoMapData
keyPointer to key
key_lengthKey length
dataPointer to data
data_lengthData length
Returns
Data of added key or (void*)-1 at error

References ccl_malloc(), teoQueueData::data, teoMapElementData::data, teoMapElementData::data_length, teoMapElementData::hash, teoMapElementData::key_length, teoQueueAdd(), and teoQueueUpdate().

Referenced by teo::Map::add(), and cclLruRefer().

void teoMapClear ( teoMap map)
Parameters
map

References teoMap::hash_map_size, HASH_TABLE_SIZE, teoMap::q, and teoQueueFree().

Referenced by teo::Map::mapClear().

int teoMapDelete ( teoMap map,
const uint8_t *  key,
size_t  key_length 
)

Delete keys element from map.

Parameters
mapPointer to teoMapData
keyPointer to key
key_lengthKey length
Returns
Zero at success, or errors: -1 - keys element not found

References teoMap::auto_resize_f, teoMapElementData::hash, teoMap::hash_map_size, teoMap::length, teoMap::q, and teoQueueDelete().

Referenced by cclLruRefer(), and teo::Map::del().

void teoMapDestroy ( teoMap map)

Destroy map.

Parameters
mapPointer to teoMapData

References teoMap::hash_map_size, teoMap::q, and teoQueueDestroy().

Referenced by teo::Map::~Map().

int teoMapForeach ( teoMap map,
teoMapForeachFunction  callback,
void *  user_data 
)

Loop through map and call callback function with index and data in parameters.

Parameters
mPointer to teoMap
callbackPointer to callback function teoMapForeachFunction
Returns
Number of elements processed

References teoMapIteratorNext(), and teoMapIteratorReset().

Referenced by teo::Map::foreach().

uint8_t* teoMapGet ( teoMap map,
const uint8_t *  key,
size_t  key_length,
size_t *  data_length 
)

Get key data from hash table.

Parameters
mapPointer to teoMapData
keyPointer to key
key_lengthKey length
data_length[out] Pointer to data length
Returns
Data of selected key (may be NULL) or (void*)-1 if not found

References teoMapElementData::data, teoMapElementData::data_length, and teoMapElementData::key_length.

Referenced by cclLruRefer(), and teo::Map::get().

uint8_t* teoMapGetFirst ( teoMap map,
size_t *  data_length 
)

Get first available element from hash table.

Parameters
mapPointer to teoHashTdata
data_length[out] Pointer to returned data length (may be NULL)
Returns
Pointer to Data of first available element or (void*)-1 if not found

References teoMapIteratorNext(), and teoMapIteratorReset().

Referenced by teo::Map::getFirst().

int teoMapIteratorFree ( teoMapIterator map_it)

Destroy map iterator.

Parameters
map_itPointer to teoMapIterator
Returns
Zero at success

Referenced by teo::Map::iteratorFree().

teoMapIterator* teoMapIteratorNew ( teoMap map)

Create new map iterator.

Parameters
mapPointer to teoMapData
Returns
Pointer to teoMapIterator or NULL at memory allocate error

References ccl_malloc(), and teoMapIteratorReset().

Referenced by teo::Map::iterator().

teoMapElementData* teoMapIteratorNext ( teoMapIterator map_it)

Get next maps element.

Parameters
map_itPointer to teoMapIterator
Returns
Pointer to map element data teoMapValueData

References teoQueueData::data, teoMap::hash_map_size, teoMapIterator::idx, teoMapIterator::it, teoMapIterator::map, teoMap::q, teoQueueIteratorNext(), teoQueueIteratorReset(), and teoMapIterator::tmv.

Referenced by teo::Map::iteratorNext(), teoMapForeach(), and teoMapGetFirst().

teoMapElementData* teoMapIteratorPrev ( teoMapIterator map_it)

Get previous maps element.

Parameters
map_itPointer to teoMapIterator
Returns
Pointer to map element data teoMapValueData

References teoQueueData::data, teoMapIterator::idx, teoMapIterator::it, teoMapIterator::map, teoMap::q, teoQueueIteratorPrev(), teoQueueIteratorReset(), and teoMapIterator::tmv.

Referenced by teo::Map::iterator_prev().

void teoMapIteratorReset ( teoMapIterator map_it,
teoMap map 
)

Reset map iterator.

Binds iterator to map, set forward iteration direction.

Parameters
map_itPointer to teoMapIterator
mapPointer to teoMapData

References teoMapIterator::idx, teoMapIterator::it, teoMapIterator::map, teoMap::q, teoQueueIteratorReset(), and teoMapIterator::tmv.

Referenced by teoMapForeach(), teoMapGetFirst(), and teoMapIteratorNew().

teoMapIterator* teoMapIteratorReverseNew ( teoMap map)

Create new map reverse iterator.

Parameters
mapPointer to teoMapData
Returns
Pointer to teoMapIterator or NULL at memory allocate error

References ccl_malloc(), and teoMapIteratorReverseReset().

Referenced by teo::Map::iteratorReverse().

void teoMapIteratorReverseReset ( teoMapIterator map_it,
teoMap map 
)

Reset map iterator.

Binds iterator to map, set reverse iteration direction.

Parameters
map_itPointer to teoMapIterator
mapPointer to teoMapData

References teoMap::hash_map_size, teoMapIterator::idx, teoMapIterator::it, teoMapIterator::map, teoMap::q, teoQueueIteratorReset(), and teoMapIterator::tmv.

Referenced by teoMapIteratorReverseNew().

teoMap* teoMapNew ( size_t  size,
int  auto_resize_f 
)

Create new map.

Parameters
sizeSize of hash map (hash map resized automatically)
auto_resize_fAuto resize hash map
Returns
Pointer to teoMapData

References teoMap::auto_resize_f, ccl_malloc(), teoMap::collisions, teoMap::hash_map_size, teoMap::length, teoMap::q, and teoQueueNew().

Referenced by cclLruInit(), and teo::Map::Map().

size_t teoMapSize ( teoMap map)

Get number of elements in TR-UPD map.

Parameters
mapPointer to teoMapData
Returns
Number of elements in TR-UPD map

References teoMap::length.

Referenced by teo::Map::size().