-
Notifications
You must be signed in to change notification settings - Fork 1
/
Helpers.h
77 lines (67 loc) · 2.21 KB
/
Helpers.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
//
// Created by Tyler Rolfe on 7/11/21.
//
#ifndef P3_HELPERS_H
#define P3_HELPERS_H
#include<cmath>
using namespace std;
enum DataType{ Latitude, Longitude, WaterDepth, OBSVNTop, OBSVNBot, Gravel, Sand, Mud, Clay, GrainSize, Sorting, MunsColr, OrgCarbn, Porosity};
/// Supports int and float types to determine if parameter is undefined per the documentation
///
/// Returns true if the type is undefined
template <typename T>
bool isUndefined(T val) {
if (val == -99 || val == -99.0) {
return true;
} else {
return false;
}
}
/// Genereates the Sedgewick, 1982 Sequence for gaps with worst case time complexity of O(n^4/3)
/// \param size - The size of the array you are attempting to shell sort
/// \return
vector<int> generateSedgewickSequence(int size) {
vector<int> sequence;
int val = 1;
int index = 1;
sequence.push_back(val);
while (val < size) {
val = int(((pow(4, index) + (3*pow(2, index-1) + 1))));
sequence.push_back(val);
index++;
}
return sequence;
}
/// Genereates the Hibbard Sequence for gaps with worst case time complexity of O(n^3/2)
/// \param size - The size of the array you are attempting to shell sort
/// \return
vector<int> generateHibbardSequence(int size) {
vector<int> sequence;
int val = 0;
int index = 1;
while (val < size) {
val = int((pow(2, index) - 1));
sequence.push_back(val);
index++;
}
return sequence;
}
float ArrayType(Sample arr[], int index, DataType& type) {
switch (type) {
case Latitude: return arr[index].latitude;
case Longitude: return arr[index].longitude;
case WaterDepth: return arr[index].waterDepth;
case OBSVNTop: return arr[index].obsvnTop;
case OBSVNBot: return arr[index].obsvnBot;
case Gravel: return arr[index].gravel;
case Sand: return arr[index].sand;
case Mud: return arr[index].mud;
case Clay: return arr[index].clay;
case GrainSize: return arr[index].grainSize;
case Sorting: return arr[index].sorting;
case OrgCarbn: return arr[index].orgCarbn;
case Porosity: return arr[index].porosity;
default: break;
}
}
#endif //P3_HELPERS_H