Algorithms_in_C 1.0.0
Set of algorithms implemented in C.
Loading...
Searching...
No Matches
dict.h
1/*
2 author: Christian Bender
3 public interface for the dictionary.
4
5 The dictionary prepares space for 1000 elements.
6*/
7
8#ifndef __DICT__H
9#define __DICT__H
10
11#define MAXELEMENTS 1000
12
13/*
14 special data type called 'Dictionary'
15 for generic use
16*/
17typedef struct Dict
18{
19 /*
20 void* array for generic use of the dictionary.
21 there actual saves the entries.
22 */
23 void *elements[MAXELEMENTS];
24
25 /* contains the number of elements in this dictionary */
26 int number_of_elements;
27
29
30/*
31 create_dict: is a simple constructor for creating
32 a dictionary and setting up the
33 member field 'number_of_elements'
34 and prepares the inner array 'elements'
35*/
36Dictionary *create_dict(void);
37
38/*
39 add_item_label: adds item (void*) to the dictionary at given label
40 returns 0 if adding was sucessful otherwise -1
41*/
42int add_item_label(Dictionary *, char label[], void *);
43
44/*
45 add_item_index: adds item (void*) to the dictionary at given index (int)
46 returns 0 if adding was sucessful otherwise -1
47*/
48int add_item_index(Dictionary *, int index, void *);
49
50/*
51 get_element: returns the element at given label
52*/
53void *get_element_label(Dictionary *, char[]);
54
55/*
56 get_element: returns the element at given index
57*/
58void *get_element_index(Dictionary *, int);
59
60/*
61 simple destrcutor function
62*/
63void destroy(Dictionary *);
64
65#endif
Definition dict.h:18