bzr branch
http://gegoxaren.bato24.eu/bzr/simpletypesystem/trunk
|
5.2.4
by Gustav Hartvigsson
Finished documenting the SMap and SMapItem interfaces. |
1 |
/*
|
|
5.2.7
by Gustav Hartvigsson
* Switched licence to a more permisive one. |
2 |
Copyright (c) 2013-2014 Gustav Hartvigsson
|
3 |
||
4 |
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5 |
of this software and associated documentation files (the "Software"), to deal
|
|
6 |
in the Software without restriction, including without limitation the rights
|
|
7 |
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8 |
copies of the Software, and to permit persons to whom the Software is
|
|
9 |
furnished to do so, subject to the following conditions:
|
|
10 |
||
11 |
The above copyright notice and this permission notice shall be included in
|
|
12 |
all copies or substantial portions of the Software.
|
|
13 |
||
14 |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15 |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16 |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17 |
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18 |
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19 |
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
20 |
THE SOFTWARE.
|
|
|
5.2.4
by Gustav Hartvigsson
Finished documenting the SMap and SMapItem interfaces. |
21 |
*/
|
22 |
||
|
5.2.1
by Gustav Hartvigsson
Started work on the Map (SMap) data structure. |
23 |
#ifndef __H_MAP__
|
24 |
#define __H_MAP__
|
|
25 |
||
|
44
by Gustav Hartvigsson
* Started to structuce the dectumentation a little better. |
26 |
#include "Func.h" |
27 |
#include "defs.h" |
|
28 |
#include "utils.h" |
|
|
53
by Gustav Hartvigsson
* Finnished up s_map_add () ??? |
29 |
#include "hash.h" |
30 |
#include "DynamicArray.h" |
|
|
44
by Gustav Hartvigsson
* Started to structuce the dectumentation a little better. |
31 |
|
32 |
BEGIN_DECLS
|
|
33 |
||
|
52
by Gustav Hartvigsson
* Reorderd CMakeLists.txt list of files |
34 |
#define S_MAP_DEFAULT_NUMBER_OF_BUCKETS 128
|
35 |
||
|
5.2.1
by Gustav Hartvigsson
Started work on the Map (SMap) data structure. |
36 |
/**
|
|
44
by Gustav Hartvigsson
* Started to structuce the dectumentation a little better. |
37 |
* @file
|
38 |
* @defgroup SMap SMap
|
|
39 |
* @addtogroup SMap
|
|
40 |
* @{
|
|
|
5.2.1
by Gustav Hartvigsson
Started work on the Map (SMap) data structure. |
41 |
* An SMap is a data structure that holds many mappings of objects to objects:
|
42 |
* say, a string to an other string. This can be likened to the Dict structure
|
|
43 |
* in python, but not fully.
|
|
44 |
*
|
|
45 |
* An SMap is made up of SMapItems, each MapItem holds two pointers to data.
|
|
46 |
* The first pointer is the key, the secold is the value.
|
|
47 |
*
|
|
48 |
* please note that SMaps can be slow and are unordered.
|
|
|
5.2.4
by Gustav Hartvigsson
Finished documenting the SMap and SMapItem interfaces. |
49 |
*
|
|
44
by Gustav Hartvigsson
* Started to structuce the dectumentation a little better. |
50 |
* TODO: Total rewrite.
|
|
5.2.1
by Gustav Hartvigsson
Started work on the Map (SMap) data structure. |
51 |
*/
|
52 |
||
|
22
by Gustav Hartvigsson
* Made code compile |
53 |
|
|
5.2.4
by Gustav Hartvigsson
Finished documenting the SMap and SMapItem interfaces. |
54 |
/** @brief
|
55 |
* SMapItem holds the mapping of a key to a value.
|
|
56 |
*/
|
|
|
44
by Gustav Hartvigsson
* Started to structuce the dectumentation a little better. |
57 |
typedef struct SMapItem SMapItem; |
|
5.2.4
by Gustav Hartvigsson
Finished documenting the SMap and SMapItem interfaces. |
58 |
|
59 |
/** @brief
|
|
60 |
* An SMap is a map many SMapItems. Mapping between a key and a value.
|
|
61 |
*
|
|
|
46
by Gustav Hartvigsson
* Renamed DynamicArray to SDynamicArray. |
62 |
* An SMap is not dependent on SObject, because it should be more generic
|
63 |
* and have the ability to be used more easily in other SObject based classes
|
|
64 |
* without causing circular dependencies.
|
|
65 |
*
|
|
66 |
* @sa SDynamicArray
|
|
67 |
* @sa SLinkedList
|
|
|
5.2.4
by Gustav Hartvigsson
Finished documenting the SMap and SMapItem interfaces. |
68 |
*/
|
|
44
by Gustav Hartvigsson
* Started to structuce the dectumentation a little better. |
69 |
typedef struct SMap SMap; |
70 |
||
71 |
||
72 |
typedef struct SMapClass SMapClass; |
|
73 |
||
74 |
||
75 |
typedef struct SMapPrivate SMapPrivate; |
|
|
5.2.1
by Gustav Hartvigsson
Started work on the Map (SMap) data structure. |
76 |
|
|
5.2.4
by Gustav Hartvigsson
Finished documenting the SMap and SMapItem interfaces. |
77 |
/**
|
78 |
* Data structure representing an SMapItem
|
|
79 |
*/
|
|
|
44
by Gustav Hartvigsson
* Started to structuce the dectumentation a little better. |
80 |
struct SMapItem { |
|
11
by Gustav Hartvigsson
* Finnished up a the inheritance documentation. |
81 |
void * key; /**< The Key */ |
82 |
void * value; /**< The Value */ |
|
|
5.2.1
by Gustav Hartvigsson
Started work on the Map (SMap) data structure. |
83 |
};
|
84 |
||
|
5.2.4
by Gustav Hartvigsson
Finished documenting the SMap and SMapItem interfaces. |
85 |
/** @brief
|
86 |
* Data structure representing an SMap
|
|
87 |
*/
|
|
|
44
by Gustav Hartvigsson
* Started to structuce the dectumentation a little better. |
88 |
struct SMap { |
|
53
by Gustav Hartvigsson
* Finnished up s_map_add () ??? |
89 |
SMapClass * klass; |
|
11
by Gustav Hartvigsson
* Finnished up a the inheritance documentation. |
90 |
SMapPrivate * priv; /**< Private data pointer */ |
|
5.2.1
by Gustav Hartvigsson
Started work on the Map (SMap) data structure. |
91 |
};
|
92 |
||
|
44
by Gustav Hartvigsson
* Started to structuce the dectumentation a little better. |
93 |
struct SMapClass { |
|
13
by Gustav Hartvigsson
* Fixed two compile errors in SSTS |
94 |
CompFunc is_equal; /** method to check if items are equal. */ |
|
53
by Gustav Hartvigsson
* Finnished up s_map_add () ??? |
95 |
HashFunc key_hash_func; |
|
22
by Gustav Hartvigsson
* Made code compile |
96 |
FuncPointer free_key; |
97 |
FuncPointer free_value; |
|
|
5.2.1
by Gustav Hartvigsson
Started work on the Map (SMap) data structure. |
98 |
};
|
99 |
||
|
5.2.4
by Gustav Hartvigsson
Finished documenting the SMap and SMapItem interfaces. |
100 |
/* -------------------------------
|
101 |
* The SMapItem functions.
|
|
102 |
* -------------------------------
|
|
103 |
*/
|
|
104 |
||
105 |
/** @breif
|
|
106 |
* create a new SMapItem.
|
|
107 |
*
|
|
108 |
* @param key The key to be added to the item.
|
|
109 |
* @param value The value to be added to the item.
|
|
110 |
*/
|
|
|
5.2.1
by Gustav Hartvigsson
Started work on the Map (SMap) data structure. |
111 |
SMapItem * s_map_item_new (void * key, void * value); |
112 |
||
|
5.2.4
by Gustav Hartvigsson
Finished documenting the SMap and SMapItem interfaces. |
113 |
/** @breif
|
114 |
* Frees a SMapItem.
|
|
115 |
*
|
|
116 |
* @param self the item to be freed.
|
|
|
18
by Gustav Hartvigsson
* Made the includation graphs look sane. |
117 |
* @param free_key The function to be used to free the key.
|
118 |
* @param free_value The function to be used to free the value.
|
|
|
5.2.4
by Gustav Hartvigsson
Finished documenting the SMap and SMapItem interfaces. |
119 |
*/
|
|
22
by Gustav Hartvigsson
* Made code compile |
120 |
void s_map_item_free (SMapItem * self, FuncPointer free_key, |
121 |
FuncPointer free_value); |
|
|
5.2.1
by Gustav Hartvigsson
Started work on the Map (SMap) data structure. |
122 |
|
|
5.2.4
by Gustav Hartvigsson
Finished documenting the SMap and SMapItem interfaces. |
123 |
/* -------------------------------
|
124 |
* The SMap functions.
|
|
125 |
* -------------------------------
|
|
126 |
*/
|
|
127 |
||
128 |
/** @brief
|
|
129 |
* s_map_new creates a new SMap object, it takes a CompFunc as an argument.
|
|
|
5.2.1
by Gustav Hartvigsson
Started work on the Map (SMap) data structure. |
130 |
*
|
|
5.2.4
by Gustav Hartvigsson
Finished documenting the SMap and SMapItem interfaces. |
131 |
* @param comp_func tells the SMap object if the key already exists when
|
|
5.2.1
by Gustav Hartvigsson
Started work on the Map (SMap) data structure. |
132 |
* adding key/value pares or when searching after a key when retrieving a value.
|
|
5.2.4
by Gustav Hartvigsson
Finished documenting the SMap and SMapItem interfaces. |
133 |
*
|
|
14
by Gustav Hartvigsson
* Think I am 70% done with SMap now... |
134 |
* The @c CompFunc returns true if the first and second parameters are equal,
|
|
5.2.4
by Gustav Hartvigsson
Finished documenting the SMap and SMapItem interfaces. |
135 |
* otherwise false.
|
|
14
by Gustav Hartvigsson
* Think I am 70% done with SMap now... |
136 |
*
|
|
16
by Gustav Hartvigsson
* Made sure the code compiled |
137 |
* @todo
|
|
14
by Gustav Hartvigsson
* Think I am 70% done with SMap now... |
138 |
* Check if free_key and/or free_value is null and set them to something
|
139 |
* appropriate.
|
|
|
5.2.1
by Gustav Hartvigsson
Started work on the Map (SMap) data structure. |
140 |
*/
|
|
53
by Gustav Hartvigsson
* Finnished up s_map_add () ??? |
141 |
SMap * s_map_new (CompFunc comp_func, |
142 |
HashFunc key_hash_func, |
|
143 |
FuncPointer free_key, |
|
144 |
FuncPointer free_value); |
|
|
5.2.1
by Gustav Hartvigsson
Started work on the Map (SMap) data structure. |
145 |
|
|
5.2.4
by Gustav Hartvigsson
Finished documenting the SMap and SMapItem interfaces. |
146 |
/** @breif
|
147 |
* This function frees an instance of an SMap.
|
|
148 |
*
|
|
149 |
* @param self the object to free.
|
|
150 |
*/
|
|
|
5.2.1
by Gustav Hartvigsson
Started work on the Map (SMap) data structure. |
151 |
void s_map_free (SMap * self); |
152 |
||
|
5.2.4
by Gustav Hartvigsson
Finished documenting the SMap and SMapItem interfaces. |
153 |
/** @breif
|
154 |
* This function adds a key/value pair to an SMap.
|
|
155 |
*
|
|
156 |
* @param self the SMap to add the key/value pair to.
|
|
|
15
by Gustav Hartvigsson
* Added some notes... bah |
157 |
* @param key the key that is used to
|
158 |
*
|
|
|
16
by Gustav Hartvigsson
* Made sure the code compiled |
159 |
* @todo
|
|
18
by Gustav Hartvigsson
* Made the includation graphs look sane. |
160 |
* make it return false on failure, or some other nastiness.
|
|
5.2.4
by Gustav Hartvigsson
Finished documenting the SMap and SMapItem interfaces. |
161 |
*/
|
|
53
by Gustav Hartvigsson
* Finnished up s_map_add () ??? |
162 |
void s_map_add (SMap * self, spointer key, spointer value); |
|
5.2.1
by Gustav Hartvigsson
Started work on the Map (SMap) data structure. |
163 |
|
|
5.2.4
by Gustav Hartvigsson
Finished documenting the SMap and SMapItem interfaces. |
164 |
/** @breif
|
165 |
* Get a value using using a key.
|
|
166 |
*
|
|
167 |
* @param self the SMap that you want to retrieve a value from.
|
|
168 |
* @param key the key that you use to retrieve the value from the SMap from
|
|
169 |
* with.
|
|
170 |
*/
|
|
|
54
by Gustav Hartvigsson
void * -> spointer |
171 |
spointer s_map_get (SMap * self, spointer key); |
|
5.2.1
by Gustav Hartvigsson
Started work on the Map (SMap) data structure. |
172 |
|
|
15
by Gustav Hartvigsson
* Added some notes... bah |
173 |
/**
|
|
16
by Gustav Hartvigsson
* Made sure the code compiled |
174 |
* @todo
|
|
15
by Gustav Hartvigsson
* Added some notes... bah |
175 |
*/
|
|
54
by Gustav Hartvigsson
void * -> spointer |
176 |
void s_map_remove (SMap * self, spointer key); |
|
15
by Gustav Hartvigsson
* Added some notes... bah |
177 |
|
|
22
by Gustav Hartvigsson
* Made code compile |
178 |
/**
|
179 |
*
|
|
180 |
*/
|
|
181 |
int s_map_ref (SMap * self); |
|
182 |
||
183 |
/**
|
|
184 |
*
|
|
185 |
*/
|
|
186 |
int s_map_unref (SMap * self); |
|
187 |
||
|
44
by Gustav Hartvigsson
* Started to structuce the dectumentation a little better. |
188 |
/** @} */
|
189 |
||
|
22
by Gustav Hartvigsson
* Made code compile |
190 |
END_DECLS
|
191 |
||
|
5.2.1
by Gustav Hartvigsson
Started work on the Map (SMap) data structure. |
192 |
#endif
|