Created
July 15, 2011 19:00
-
-
Save FurryHead/1085293 to your computer and use it in GitHub Desktop.
Dynamic array and map in C (header).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef ARRAY_H | |
#define ARRAY_H | |
#ifdef __cplusplus | |
extern "C" { | |
#endif | |
#define ARRAY_EXPAND_SIZE 10 | |
struct array { | |
void **items; | |
int size; | |
int _num_allocated; | |
int _num_elements; | |
}; | |
struct array *array_new(void); | |
int array_set(struct array *arr, int index, void *item); | |
int array_append(struct array *arr, void *item); | |
void *array_pop(struct array *arr); | |
void *array_get(struct array *arr, int index); | |
void *array_remove(struct array *arr, int index); | |
void array_free(struct array *arr); | |
struct map { | |
struct array *keys; | |
struct array *values; | |
}; | |
struct map *map_new(void); | |
void *map_get(struct map *m, void *key); | |
int map_set(struct map *m, void *key, void *value); | |
void *map_remove(struct map *m, void *key); | |
void map_free(struct map *m); | |
#ifdef __cplusplus | |
} | |
#endif | |
#endif /* ARRAY_H */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment