#ifndef UCX_MAP_H
#define UCX_MAP_H
#include "common.h"
#include "collection.h"
#include "string.h"
#include "hash_key.h"
#ifndef UCX_LIST_H
typedef struct cx_list_s CxList;
#endif
#ifdef __cplusplus
extern "C" {
#endif
typedef struct cx_map_s CxMap;
typedef struct cx_map_entry_s CxMapEntry;
typedef struct cx_map_iterator_s CxMapIterator;
typedef struct cx_map_class_s cx_map_class;
struct cx_map_s {
CX_COLLECTION_BASE;
cx_map_class *cl;
};
struct cx_map_entry_s {
const CxHashKey *key;
void *value;
};
enum cx_map_iterator_type {
CX_MAP_ITERATOR_PAIRS,
CX_MAP_ITERATOR_KEYS,
CX_MAP_ITERATOR_VALUES
};
struct cx_map_iterator_s {
CX_ITERATOR_BASE;
CxMap *map;
void *elem;
CxMapEntry entry;
size_t slot;
size_t index;
size_t elem_size;
size_t elem_count;
enum cx_map_iterator_type type;
};
struct cx_map_class_s {
void (*deallocate)(
struct cx_map_s *map);
void (*clear)(
struct cx_map_s *map);
void *(*put)(CxMap *map, CxHashKey key,
void *value);
void *(*get)(
const CxMap *map, CxHashKey key);
int (*remove)(CxMap *map, CxHashKey key,
void *targetbuf);
CxMapIterator (*iterator)(
const CxMap *map,
enum cx_map_iterator_type type);
};
CX_EXPORT extern CxMap *
const cxEmptyMap;
CX_EXPORT void cxMapFree(CxMap *map);
cx_attr_nonnull
CX_EXPORT void cxMapClear(CxMap *map);
cx_attr_nonnull
CX_EXPORT size_t cxMapSize(
const CxMap *map);
cx_attr_nodiscard
CX_EXPORT CxMapIterator cxMapIteratorValues(
const CxMap *map);
cx_attr_nodiscard
CX_EXPORT CxMapIterator cxMapIteratorKeys(
const CxMap *map);
cx_attr_nodiscard
CX_EXPORT CxMapIterator cxMapIterator(
const CxMap *map);
cx_attr_nonnull
CX_EXPORT int cx_map_put(CxMap *map, CxHashKey key,
void *value);
#define cxMapPut(map, key, value) cx_map_put(map,
CX_HASH_KEY(key), value)
cx_attr_nonnull
CX_EXPORT void *cx_map_emplace(CxMap *map, CxHashKey key);
#define cxMapEmplace(map, key) cx_map_emplace(map,
CX_HASH_KEY(key))
cx_attr_nonnull cx_attr_nodiscard
CX_EXPORT void *cx_map_get(
const CxMap *map, CxHashKey key);
#define cxMapGet(map, key) cx_map_get(map,
CX_HASH_KEY(key))
#define cxMapContains(map, key) (cxMapGet(map, key) !=
NULL)
cx_attr_nonnull_arg(
1)
CX_EXPORT int cx_map_remove(CxMap *map, CxHashKey key,
void *targetbuf);
#define cxMapRemove(map, key) cx_map_remove(map,
CX_HASH_KEY(key),
NULL)
#define cxMapRemoveAndGet(map, key, targetbuf) cx_map_remove(map,
CX_HASH_KEY(key), targetbuf)
cx_attr_nonnull_arg(
1,
2,
3)
CX_EXPORT int cxMapClone(CxMap *dst,
const CxMap *src,
cx_clone_func clone_func,
const CxAllocator *clone_allocator,
void *data);
cx_attr_nonnull_arg(
1,
2,
3,
4)
CX_EXPORT int cxMapDifference(CxMap *dst,
const CxMap *minuend,
const CxMap *subtrahend,
cx_clone_func clone_func,
const CxAllocator *clone_allocator,
void *data);
cx_attr_nonnull_arg(
1,
2,
3,
4)
CX_EXPORT int cxMapListDifference(CxMap *dst,
const CxMap *src,
const CxList *keys,
cx_clone_func clone_func,
const CxAllocator *clone_allocator,
void *data);
cx_attr_nonnull_arg(
1,
2,
3,
4)
CX_EXPORT int cxMapIntersection(CxMap *dst,
const CxMap *src,
const CxMap *other,
cx_clone_func clone_func,
const CxAllocator *clone_allocator,
void *data);
cx_attr_nonnull_arg(
1,
2,
3,
4)
CX_EXPORT int cxMapListIntersection(CxMap *dst,
const CxMap *src,
const CxList *keys,
cx_clone_func clone_func,
const CxAllocator *clone_allocator,
void *data);
cx_attr_nonnull_arg(
1,
2,
3)
CX_EXPORT int cxMapUnion(CxMap *dst,
const CxMap *src,
cx_clone_func clone_func,
const CxAllocator *clone_allocator,
void *data);
cx_attr_nonnull
CX_EXPORT int cxMapCloneSimple(CxMap *dst,
const CxMap *src);
cx_attr_nonnull
CX_EXPORT int cxMapDifferenceSimple(CxMap *dst,
const CxMap *minuend,
const CxMap *subtrahend);
cx_attr_nonnull
CX_EXPORT int cxMapListDifferenceSimple(CxMap *dst,
const CxMap *src,
const CxList *keys);
cx_attr_nonnull
CX_EXPORT int cxMapIntersectionSimple(CxMap *dst,
const CxMap *src,
const CxMap *other);
cx_attr_nonnull
CX_EXPORT int cxMapListIntersectionSimple(CxMap *dst,
const CxMap *src,
const CxList *keys);
cx_attr_nonnull
CX_EXPORT int cxMapUnionSimple(CxMap *dst,
const CxMap *src);
#ifdef __cplusplus
}
#endif
#endif