-
Notifications
You must be signed in to change notification settings - Fork 0
/
Structs.h
80 lines (67 loc) · 2.26 KB
/
Structs.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
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
//
// Created by evyat on 10/13/2019.
//
#include "RBTree.h"
#ifndef TA_EX3_STRUCTS_H
#define TA_EX3_STRUCTS_H
#ifdef __cplusplus
extern "C" {
#endif
/**
* Represents a vector. The double* should be dynamically allocated
*/
typedef struct Vector
{
int len;
double *vector;
} Vector;
/**
* CompFunc for strings (assumes strings end with "\0")
* @param a - char* pointer
* @param b - char* pointer
* @return equal to 0 iff a == b. lower than 0 if a < b. Greater than 0 iff b < a. (lexicographic
* order)
*/
int stringCompare(const void *a, const void *b); // implement it in Structs.c
/**
* ForEach function that concatenates the given word to pConcatenated. pConcatenated is already allocated with
* enough space.
* @param word - char* to add to pConcatenated
* @param pConcatenated - char*
* @return 0 on failure, other on success
*/
int concatenate(const void *word, void *pConcatenated); // implement it in Structs.c
/**
* FreeFunc for strings
*/
void freeString(void *s); // implement it in Structs.c
/**
* CompFunc for Vectors, compares element by element, the vector that has the first larger
* element is considered larger. If vectors are of different lengths and identify for the length
* of the shorter vector, the shorter vector is considered smaller.
* @param a - first vector
* @param b - second vector
* @return equal to 0 iff a == b. lower than 0 if a < b. Greater than 0 iff b < a.
*/
int vectorCompare1By1(const void *a, const void *b); // implement it in Structs.c
/**
* FreeFunc for vectors
*/
void freeVector(void *pVector); // implement it in Structs.c
/**
* copy pVector to pMaxVector if : 1. The norm of pVector is greater then the norm of pMaxVector.
* 2. pMaxVector == NULL.
* @param pVector pointer to Vector
* @param pMaxVector pointer to Vector
* @return 1 on success, 0 on failure (if pVector == NULL: failure).
*/
int copyIfNormIsLarger(const void *pVector, void *pMaxVector); // implement it in Structs.c
/**
* @param tree a pointer to a tree of Vectors
* @return pointer to a *copy* of the vector that has the largest norm (L2 Norm).
*/
Vector *findMaxNormVectorInTree(RBTree *tree); // implement it in Structs.c You must use copyIfNormIsLarger in the implementation!
#ifdef __cplusplus
}
#endif
#endif //TA_EX3_STRUCTS_H