streaming_algorithms  0.0.5
A collection of streaming data algorithms
time_series.h
Go to the documentation of this file.
1 /* -*- Mode: C; tab_width: 8; indent_tabs_mode: nil; c_basic_offset: 2 -*- */
2 /* vim: set ts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4  * License, v. 2.0. If a copy of the MPL was not distributed with this
5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 
7 /** Time series data storage (stripped down circular buffer) @file */
8 
9 #ifndef sa_time_series_h_
10 #define sa_time_series_h_
11 
12 #include <stddef.h>
13 #include <stdint.h>
14 
16 
17 #ifdef __cplusplus
18 extern "C"
19 {
20 #endif
21 
22 /**
23  * Allocates and initializes the data structure.
24  *
25  * @param rows Number of observation slots
26  * @param ns_per_row Nanoseconds represented in each row
27  *
28  * @return Pointer to time_series_int
29  *
30  */
31 sa_time_series_int* sa_create_time_series_int(int rows, uint64_t ns_per_row);
32 
33 /**
34  * Zeros out the time series.
35  *
36  * @param ts Pointer to time_series_int
37  */
39 
40 /**
41  * Adds the specified value to the time series row.
42  *
43  * @param ts Pointer to time_series_int
44  * @param ns Timestamp (nanoseconds since Jan 1 1970) associated with value
45  * @param v Value to add
46  *
47  * @return current value
48  *
49  */
50 int
51 sa_add_time_series_int(sa_time_series_int *ts, uint64_t ns, int v);
52 
53 /**
54  * Sets the time series row to the specified value.
55  *
56  * @param ts Pointer to time_series_int
57  * @param ns Timestamp (nanoseconds since Jan 1 1970) associated with value
58  * @param v Value to set
59  *
60  * @return current value
61  *
62  */
63 int
64 sa_set_time_series_int(sa_time_series_int *ts, uint64_t ns, int v);
65 
66 /**
67  * Gets the value of the time series row.
68  *
69  * @param ts Pointer to time_series_int
70  * @param ns Timestamp (nanoseconds since Jan 1 1970) of the row
71  *
72  * @return current value
73  *
74  */
75 int
77 
78 /**
79  * Returns the timestamp of the most recent row.
80  *
81  * @param ts Pointer to time_series_int
82  *
83  * @return Timestamp (nanoseconds since Jan 1 1970)
84  *
85  */
87 
88 /**
89  * Computes the matrix profile for a time series or sub set of the series. See:
90  * http://www.cs.ucr.edu/~eamonn/MatrixProfile.html
91  *
92  * @param ts Pointer to time_series_int
93  * @param ns The start of the interval to analyze
94  * @param n Sequence length (<= ts->rows)
95  * @param m Sub-sequence length (n / 4 >= m > 3)
96  * @param percent Percentage of data to base the calculation on (0.0 <
97  * percent <= 100). Use less than 100 to produce an estimate
98  * of the matrix profile trading accuracy for speed.
99  * @param mp Returned pointer to the matrix profile array (MUST be freed by the
100  * caller)
101  * @param mpi Returned pointer to the matrix profile index array (MUST be freed
102  * by the caller)
103  * @return int Length of the returned matrix profile arrays (0 on failure). The
104  * mp/i pointers are not modified on failure.
105  */
107  uint64_t ns,
108  int n,
109  int m,
110  double percent,
111  double *mp[],
112  int *mpi[]);
113 
114 /**
115  * Free the associated memory.
116  *
117  * @param ts Pointer to time_series_int
118  *
119  */
121 
122 /**
123  * Serialize the internal state to a buffer.
124  *
125  * @param ts Pointer to time_series_int
126  * @param len Length of the returned buffer
127  *
128  * @return char* Serialized representation MUST be freed by the caller
129  */
130 char* sa_serialize_time_series_int(sa_time_series_int *ts, size_t *len);
131 
132 /**
133  * Restores the internal state from the serialized output.
134  *
135  * @param ts Pointer to time_series_int
136  * @param buf Buffer containing the output of serialize_time_series_int
137  * @param len Length of the buffer
138  *
139  * @return 0 = success
140  * 1 = invalid buffer length
141  * 2 = invalid cnt
142  * 3 = mis-matched dimensions
143  *
144  */
145 int
147  const char *buf,
148  size_t len);
149 
150 #ifdef __cplusplus
151 }
152 #endif
153 
154 #endif
int sa_deserialize_time_series_int(sa_time_series_int *ts, const char *buf, size_t len)
Restores the internal state from the serialized output.
void sa_destroy_time_series_int(sa_time_series_int *ts)
Free the associated memory.
int sa_add_time_series_int(sa_time_series_int *ts, uint64_t ns, int v)
Adds the specified value to the time series row.
void sa_init_time_series_int(sa_time_series_int *ts)
Zeros out the time series.
char * sa_serialize_time_series_int(sa_time_series_int *ts, size_t *len)
Serialize the internal state to a buffer.
int sa_set_time_series_int(sa_time_series_int *ts, uint64_t ns, int v)
Sets the time series row to the specified value.
int sa_mp_time_series_int(sa_time_series_int *ts, uint64_t ns, int n, int m, double percent, double *mp[], int *mpi[])
Computes the matrix profile for a time series or sub set of the series.
struct sa_time_series_int sa_time_series_int
Definition: time_series.h:15
uint64_t sa_timestamp_time_series_int(sa_time_series_int *ts)
Returns the timestamp of the most recent row.
sa_time_series_int * sa_create_time_series_int(int rows, uint64_t ns_per_row)
Allocates and initializes the data structure.
int sa_get_time_series_int(sa_time_series_int *ts, uint64_t ns)
Gets the value of the time series row.