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