-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsampleMap.c
More file actions
84 lines (70 loc) · 1.81 KB
/
sampleMap.c
File metadata and controls
84 lines (70 loc) · 1.81 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/**
* @file
*
* @author Christopher Blöcker
*/
/* -------------------------------------------------------------------------- */
#include <stdlib.h>
#include <assert.h>
/* -------------------------------------------------------------------------- */
#include "sampleMap.h"
#include "vector.h"
/* -------------------------------------------------------------------------- */
/**
* Created a new sample map.
*
* @param[in] size Size of the sample map to create.
*
* @return The new sample map with space for the given number of samples.
*/
extern SampleMap sampleMapMake(int size)
{
SampleMap res;
res.size = size;
res.items = 0;
res.samples = malloc(size * sizeof(Vector));
return res;
}
/**
* Inserts a sample into the sample map.
*
* @param[in] s The sample map.
* @param[in] sample The sample that should be intserted into the sample map.
*
* @return The new sample map containing the new sample.
*/
extern SampleMap sampleMapPut(SampleMap s, Vector sample)
{
assert(s.items < s.size);
s.samples[s.items++] = sample;
return s;
}
/**
* Frees the memory used by the given sample map.
*
* @param[in] s Sample map that should be freed.
*
* @return NULL.
*/
extern SampleMap sampleMapFree(SampleMap s)
{
s.size = 0;
if (s.samples)
free(s.samples);
s.samples = NULL;
return s;
}
/**
* Prints information about the given sample map in stream.
*
* @param[in] s The sample map information should be printed about.
* @param[in] stream Where to print the information.
*/
extern void sampleMapPrint(SampleMap s, FILE * stream)
{
fprintf(stream, "Sample Map ::\n");
fprintf(stream, " size : %i\n", s.size);
fprintf(stream, " items : %i\n", s.items);
for (unsigned i = 0; i < s.items; ++i)
fprintf(stream, " %i : (%lf, %lf)\n", i, s.samples[i].x, s.samples[i].y);
}