2017-12-24 19:06:58 +03:00
|
|
|
/*
|
|
|
|
author: Christian Bender
|
2020-05-29 23:23:24 +03:00
|
|
|
public interface for the dictionary.
|
2017-12-24 19:06:58 +03:00
|
|
|
|
|
|
|
The dictionary prepares space for 1000 elements.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __DICT__H
|
|
|
|
#define __DICT__H
|
|
|
|
|
|
|
|
#define MAXELEMENTS 1000
|
|
|
|
|
|
|
|
/*
|
|
|
|
special data type called 'Dictionary'
|
|
|
|
for generic use
|
|
|
|
*/
|
2020-05-29 23:23:24 +03:00
|
|
|
typedef struct Dict
|
2017-12-24 19:06:58 +03:00
|
|
|
{
|
2020-05-29 23:23:24 +03:00
|
|
|
/*
|
2017-12-24 19:06:58 +03:00
|
|
|
void* array for generic use of the dictionary.
|
|
|
|
there actual saves the entries.
|
|
|
|
*/
|
2020-05-29 23:23:24 +03:00
|
|
|
void *elements[MAXELEMENTS];
|
2017-12-24 19:06:58 +03:00
|
|
|
|
|
|
|
/* contains the number of elements in this dictionary */
|
|
|
|
int number_of_elements;
|
|
|
|
|
|
|
|
} Dictionary;
|
|
|
|
|
|
|
|
/*
|
2020-05-29 23:23:24 +03:00
|
|
|
create_dict: is a simple constructor for creating
|
|
|
|
a dictionary and setting up the
|
2017-12-24 19:06:58 +03:00
|
|
|
member field 'number_of_elements'
|
|
|
|
and prepares the inner array 'elements'
|
|
|
|
*/
|
2020-05-29 23:23:24 +03:00
|
|
|
Dictionary *create_dict(void);
|
2017-12-24 19:06:58 +03:00
|
|
|
|
2020-05-29 23:23:24 +03:00
|
|
|
/*
|
|
|
|
add_item_label: adds item (void*) to the dictionary at given label
|
2017-12-24 19:06:58 +03:00
|
|
|
returns 0 if adding was sucessful otherwise -1
|
|
|
|
*/
|
2020-05-29 23:23:24 +03:00
|
|
|
int add_item_label(Dictionary *, char label[], void *);
|
2017-12-24 19:06:58 +03:00
|
|
|
|
2020-05-29 23:23:24 +03:00
|
|
|
/*
|
|
|
|
add_item_index: adds item (void*) to the dictionary at given index (int)
|
2017-12-24 19:06:58 +03:00
|
|
|
returns 0 if adding was sucessful otherwise -1
|
|
|
|
*/
|
|
|
|
int add_item_index(Dictionary *, int index, void *);
|
|
|
|
|
|
|
|
/*
|
2020-05-29 23:23:24 +03:00
|
|
|
get_element: returns the element at given label
|
2017-12-24 19:06:58 +03:00
|
|
|
*/
|
2020-05-29 23:23:24 +03:00
|
|
|
void *get_element_label(Dictionary *, char[]);
|
2017-12-24 19:06:58 +03:00
|
|
|
|
|
|
|
/*
|
2020-05-29 23:23:24 +03:00
|
|
|
get_element: returns the element at given index
|
2017-12-24 19:06:58 +03:00
|
|
|
*/
|
2020-05-29 23:23:24 +03:00
|
|
|
void *get_element_index(Dictionary *, int);
|
2017-12-24 19:06:58 +03:00
|
|
|
|
2020-05-29 23:23:24 +03:00
|
|
|
/*
|
2017-12-24 19:06:58 +03:00
|
|
|
simple destrcutor function
|
|
|
|
*/
|
|
|
|
void destroy(Dictionary *);
|
|
|
|
|
|
|
|
#endif
|