Salad  1.0.15
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
map.h
Go to the documentation of this file.
1 /*
2  * Salad - An assortment of useful C stuff
3  * Copyright (C) 2016 Lloyd Dilley
4  * http://www.dilley.me/
5  *
6  * This file is part of Salad.
7  *
8  * Salad is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation; either version
11  * 3 of the License, or (at your option) any later version.
12  *
13  * Salad is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with Salad. If not, see <http://www.gnu.org/licenses/>.
20  */
21 
24 #ifndef MAP_H
25 #define MAP_H
26 
27 #include "salad/types.h"
28 #include "salad/vector.h"
29 
37 typedef struct sld_map
38 {
39  /* No hashing occurs using two arrays. The key and value pairs are
40  simply mapped to the same index in both arrays. Perhaps a table
41  or map with hashing will be added later... */
42  struct sld_vector *keys;
43  struct sld_vector *values;
44 } sld_map;
45 
57 SLD_SSINT sld_map_init(struct sld_map *map);
58 
69 SLD_UINT sld_map_size(struct sld_map *map);
70 
83 SLD_SSINT sld_map_add(struct sld_map *map, char *key, void *value);
84 
96 SLD_BOOL sld_map_delete(struct sld_map *map, char *key);
97 
110 SLD_BOOL sld_map_has_key(struct sld_map *map, char *key);
111 
123 void *sld_map_get_value(struct sld_map *map, char *key);
124 
136 void *sld_map_key_at(struct sld_map *map, SLD_UINT index);
137 
149 void *sld_map_value_at(struct sld_map *map, SLD_UINT index);
150 
160 void sld_map_free(struct sld_map *map);
161 
164 #endif /* MAP_H */
void * sld_map_get_value(struct sld_map *map, char *key)
Obtains the value from a sld_map using the specified key.
Definition: map.c:136
SLD_BOOL sld_map_delete(struct sld_map *map, char *key)
Removes an object from a sld_map with the specified key.
Definition: map.c:106
SLD_SSINT sld_map_add(struct sld_map *map, char *key, void *value)
Adds an object to a sld_map.
Definition: map.c:85
struct sld_vector * values
Definition: map.h:43
struct sld_map sld_map
void * sld_map_key_at(struct sld_map *map, SLD_UINT index)
Obtains the key from a sld_map at the specified index.
Definition: map.c:149
signed short int SLD_SSINT
Definition: types.h:47
struct sld_vector * keys
Definition: map.h:42
SLD_BOOL sld_map_has_key(struct sld_map *map, char *key)
Checks whether or not a sld_map contains the specified key.
Definition: map.c:123
void * sld_map_value_at(struct sld_map *map, SLD_UINT index)
Obtains the value from a sld_map at the specified index.
Definition: map.c:157
Definition: map.h:37
SLD_USINT SLD_BOOL
Definition: types.h:65
Definition: vector.h:42
unsigned int SLD_UINT
Definition: types.h:56
void sld_map_free(struct sld_map *map)
Frees any memory allocated for an initialized sld_map.
Definition: map.c:165
SLD_UINT sld_map_size(struct sld_map *map)
Returns the size of a sld_map.
Definition: map.c:80
SLD_SSINT sld_map_init(struct sld_map *map)
Initializes a sld_map.
Definition: map.c:33