1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
#ifndef __H_MAP__
#define __H_MAP__
/**
* An SMap is a data structure that holds many mappings of objects to objects:
* say, a string to an other string. This can be likened to the Dict structure
* in python, but not fully.
*
* An SMap is made up of SMapItems, each MapItem holds two pointers to data.
* The first pointer is the key, the secold is the value.
*
* please note that SMaps can be slow and are unordered.
*/
#include "SimpleTypeSystem.h"
#include "baseobject.h"
#include <stdbool.h>
typedef struct _SMapItem SMapItem;
typedef struct _SMap SMap;
typedef struct _SMapClass SMapClass;
typedef struct _SMapPrivate SMapPrivate;
struct _SMapItem {
void * key;
void * value;
};
struct _SMap {
SBaseObjectInstance parent;
SMapPrivate * priv;
};
struct _SMapClass {
SBaseObjectClass parentclass;
bool (* is_equal)(void *, void *); // method to check if items are equal.
};
SMapItem * s_map_item_new (void * key, void * value);
void s_map_item_free (SMapItem * self);
/**
* s_map_new creates a new SMap oject, it takes a CompFunc as an argument.
*
* The compfunc tells the SMap object if the key already exists when
* adding key/value pares or when searching after a key when retrieving a value.
*/
SMap * s_map_new ( CompFunc comp_func );
void s_map_free (SMap * self);
void s_map_add (SMap * self ,void * key, void * value);
void * s_map_get (SMap * self, void * key);
#endif
|