4852e7f53824be2c234e07a08d37f1da43b3b69a
[oweals/gnunet.git] / src / testbed / testbed_api_sd.h
1 /*
2       This file is part of GNUnet
3       Copyright (C) 2008--2013 GNUnet e.V.
4
5       GNUnet is free software: you can redistribute it and/or modify it
6       under the terms of the GNU Affero General Public License as published
7       by the Free Software Foundation, either version 3 of the License,
8       or (at your option) any later version.
9
10       GNUnet is distributed in the hope that it will be useful, but
11       WITHOUT ANY WARRANTY; without even the implied warranty of
12       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13       Affero General Public License for more details.
14      
15       You should have received a copy of the GNU Affero General Public License
16       along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18
19 /**
20  * @file testbed/testbed_api_sd.h
21  * @brief functions to calculate standard deviation
22  * @author Sree Harsha Totakura <sreeharsha@totakura.in>
23  */
24
25 #ifndef TESTBED_API_SD_H
26 #define TESTBED_API_SD_H
27
28
29 /**
30  * Opaque handle for calculating SD
31  */
32 struct SDHandle;
33
34
35 /**
36  * Initialize standard deviation calculation handle
37  *
38  * @param max_cnt the maximum number of readings to keep
39  * @return the initialized handle
40  */
41 struct SDHandle *
42 GNUNET_TESTBED_SD_init_ (unsigned int max_cnt);
43
44
45 /**
46  * Frees the memory allocated to the SD handle
47  *
48  * @param h the SD handle
49  */
50 void
51 GNUNET_TESTBED_SD_destroy_ (struct SDHandle *h);
52
53
54 /**
55  * Add a reading to SD
56  *
57  * @param h the SD handle
58  * @param amount the reading value
59  */
60 void
61 GNUNET_TESTBED_SD_add_data_ (struct SDHandle *h, unsigned int amount);
62
63
64 /**
65  * Returns the factor by which the given amount differs from the standard deviation
66  *
67  * @param h the SDhandle
68  * @param amount the value for which the deviation is returned
69  * @param factor the factor by which the given amont differs
70  * @return the deviation from the average; GNUNET_SYSERR if the deviation cannot
71  *           be calculated OR 0 if the deviation is less than the average; a
72  *           maximum of 4 is returned for deviations equal to or larger than 4
73  */
74 int
75 GNUNET_TESTBED_SD_deviation_factor_ (struct SDHandle *h, unsigned int amount,
76                                      int *factor);
77
78 #endif
79 /* end of testbed_api.h */