/* vim: ts=4 sw=4 sts=4 ff=unix fenc=utf-8 :
* =====================================================================
* sc_map.h
* Copyright (c) 2003 - 2011 sys0tem
* LICENSE :
* LGPL (GNU Lesser General Public License - Version 3,29 June 2007)
* http://www.gnu.org/copyleft/lesser.html
* or
* EPL (Eclipse Public License - v1.0)
* http://www.eclipse.org/legal/epl-v10.html
* =====================================================================
*/
#ifndef __SC_MAP_H__
#define __SC_MAP_H__
#include <stddef.h>
#include <sc_stdbool.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* マップエントリ.
*/
typedef struct SC_Map_Entry_ {
char* key; /*< キー */
void* value; /*< 値 */
size_t size; /*< 値のサイズ */
struct SC_Map_Entry_* next; /*< 次のエントリへのポインタ */
} SC_Map_Entry;
/**
* マップ.
* <pre>
* [使用方法]
* char* val;
* SC_Map* map = SC_Map_new(256);
* map->putStr(map, "key1", "value1");
* map->putStr(map, "key2", "value2");
* .
* .
* val = map->getStr(map, "key1");
* .
* .
* SC_Map_delete(map);
* </pre>
*/
typedef struct SC_Map_
{
size_t size;
void* (*put )(struct SC_Map_*, const char* key, const void* obj, size_t size);
void* (*get )(struct SC_Map_*, const char* key, size_t* size);
char* (*putStr)(struct SC_Map_*, const char* key, const char* val);
char* (*getStr)(struct SC_Map_*, const char* key);
void (*remove)(struct SC_Map_*, const char* key);
void (*clear )(struct SC_Map_*);
void (*entries)(struct SC_Map_*, bool (*handler)(char* key, void* val, size_t size));
SC_Map_Entry** _table;
size_t _tblSize;
} SC_Map;
SC_Map* SC_Map_new(size_t cap);
void SC_Map_delete(SC_Map* map);
int SC_Map_hashCode(const char* key);
#ifdef __cplusplus
}
#endif
#endif /* __SC_MAP_H__ */