-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetLib.h
48 lines (37 loc) · 1.33 KB
/
setLib.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/* C library for working with sets
* Author: Alexander Chekalin
* Created: 12.01.2021
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
// hash table for implementing set will be using open addressing scheme
// that's the most convient approch for a simple library IMHO
typedef struct node {
int key;
int value;
} Node;
typedef struct set {
Node** data; // array of pointers to Nodes
int size; // maximum number of elements in set (capacity)
int nOfElements; // number of elements currently stored in a set
int step;
} Set;
// new set initialization
Set *newSet(const int size);
// adding a single element to a set
void addElement(Set *set, const int n);
// printing a set
void printSet(const Set *set);
// test whether an element is in a set
int isElement(const int n, const Set *set);
// function tests whether one set is a subset of another
int isSubset(const Set *A, const Set *B);
// function tests two sets for equality
// it is possible to combine functions isSubset and isEqual into one function without any
// loss of functionality, but the general solution might become slower and the code
// using it less explicit
int isEqual(const Set *A, const Set *B);
// populating a set with n arbitrary integers in the range [min..max)
void populateSet(Set *set, const int n, const int min, const int max);