summaryrefslogtreecommitdiff
path: root/src/testbed/testbed_api_sd.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/testbed/testbed_api_sd.c')
-rw-r--r--src/testbed/testbed_api_sd.c80
1 files changed, 41 insertions, 39 deletions
diff --git a/src/testbed/testbed_api_sd.c b/src/testbed/testbed_api_sd.c
index 2bff246a7..9a40464d7 100644
--- a/src/testbed/testbed_api_sd.c
+++ b/src/testbed/testbed_api_sd.c
@@ -31,7 +31,8 @@
31/** 31/**
32 * An entry to hold data which will be used to calculate SD 32 * An entry to hold data which will be used to calculate SD
33 */ 33 */
34struct SDEntry { 34struct SDEntry
35{
35 /** 36 /**
36 * DLL next pointer 37 * DLL next pointer
37 */ 38 */
@@ -52,7 +53,8 @@ struct SDEntry {
52/** 53/**
53 * Opaque handle for calculating SD 54 * Opaque handle for calculating SD
54 */ 55 */
55struct SDHandle { 56struct SDHandle
57{
56 /** 58 /**
57 * DLL head for storing entries 59 * DLL head for storing entries
58 */ 60 */
@@ -102,12 +104,12 @@ struct SDHandle {
102 * @return the initialized handle 104 * @return the initialized handle
103 */ 105 */
104struct SDHandle * 106struct SDHandle *
105GNUNET_TESTBED_SD_init_(unsigned int max_cnt) 107GNUNET_TESTBED_SD_init_ (unsigned int max_cnt)
106{ 108{
107 struct SDHandle *h; 109 struct SDHandle *h;
108 110
109 GNUNET_assert(1 < max_cnt); 111 GNUNET_assert (1 < max_cnt);
110 h = GNUNET_new(struct SDHandle); 112 h = GNUNET_new (struct SDHandle);
111 h->max_cnt = max_cnt; 113 h->max_cnt = max_cnt;
112 return h; 114 return h;
113} 115}
@@ -119,16 +121,16 @@ GNUNET_TESTBED_SD_init_(unsigned int max_cnt)
119 * @param h the SD handle 121 * @param h the SD handle
120 */ 122 */
121void 123void
122GNUNET_TESTBED_SD_destroy_(struct SDHandle *h) 124GNUNET_TESTBED_SD_destroy_ (struct SDHandle *h)
123{ 125{
124 struct SDEntry *entry; 126 struct SDEntry *entry;
125 127
126 while (NULL != (entry = h->head)) 128 while (NULL != (entry = h->head))
127 { 129 {
128 GNUNET_CONTAINER_DLL_remove(h->head, h->tail, entry); 130 GNUNET_CONTAINER_DLL_remove (h->head, h->tail, entry);
129 GNUNET_free(entry); 131 GNUNET_free (entry);
130 } 132 }
131 GNUNET_free(h); 133 GNUNET_free (h);
132} 134}
133 135
134 136
@@ -139,7 +141,7 @@ GNUNET_TESTBED_SD_destroy_(struct SDHandle *h)
139 * @param amount the reading value 141 * @param amount the reading value
140 */ 142 */
141void 143void
142GNUNET_TESTBED_SD_add_data_(struct SDHandle *h, unsigned int amount) 144GNUNET_TESTBED_SD_add_data_ (struct SDHandle *h, unsigned int amount)
143{ 145{
144 struct SDEntry *entry; 146 struct SDEntry *entry;
145 double sqavg; 147 double sqavg;
@@ -147,25 +149,25 @@ GNUNET_TESTBED_SD_add_data_(struct SDHandle *h, unsigned int amount)
147 149
148 entry = NULL; 150 entry = NULL;
149 if (h->cnt == h->max_cnt) 151 if (h->cnt == h->max_cnt)
150 { 152 {
151 entry = h->head; 153 entry = h->head;
152 GNUNET_CONTAINER_DLL_remove(h->head, h->tail, entry); 154 GNUNET_CONTAINER_DLL_remove (h->head, h->tail, entry);
153 h->sum -= entry->amount; 155 h->sum -= entry->amount;
154 h->sqsum -= 156 h->sqsum -=
155 ((unsigned long)entry->amount) * ((unsigned long)entry->amount); 157 ((unsigned long) entry->amount) * ((unsigned long) entry->amount);
156 h->cnt--; 158 h->cnt--;
157 } 159 }
158 GNUNET_assert(h->cnt < h->max_cnt); 160 GNUNET_assert (h->cnt < h->max_cnt);
159 if (NULL == entry) 161 if (NULL == entry)
160 entry = GNUNET_new(struct SDEntry); 162 entry = GNUNET_new (struct SDEntry);
161 entry->amount = amount; 163 entry->amount = amount;
162 GNUNET_CONTAINER_DLL_insert_tail(h->head, h->tail, entry); 164 GNUNET_CONTAINER_DLL_insert_tail (h->head, h->tail, entry);
163 h->sum += amount; 165 h->sum += amount;
164 h->cnt++; 166 h->cnt++;
165 h->avg = ((float)h->sum) / ((float)h->cnt); 167 h->avg = ((float) h->sum) / ((float) h->cnt);
166 h->sqsum += ((unsigned long)amount) * ((unsigned long)amount); 168 h->sqsum += ((unsigned long) amount) * ((unsigned long) amount);
167 sqsum_avg = ((double)h->sqsum) / ((double)h->cnt); 169 sqsum_avg = ((double) h->sqsum) / ((double) h->cnt);
168 sqavg = ((double)h->avg) * ((double)h->avg); 170 sqavg = ((double) h->avg) * ((double) h->avg);
169 h->vr = sqsum_avg - sqavg; 171 h->vr = sqsum_avg - sqavg;
170} 172}
171 173
@@ -180,8 +182,8 @@ GNUNET_TESTBED_SD_add_data_(struct SDHandle *h, unsigned int amount)
180 * be calculated; GNUNET_OK if the deviation is returned through factor 182 * be calculated; GNUNET_OK if the deviation is returned through factor
181 */ 183 */
182int 184int
183GNUNET_TESTBED_SD_deviation_factor_(struct SDHandle *h, unsigned int amount, 185GNUNET_TESTBED_SD_deviation_factor_ (struct SDHandle *h, unsigned int amount,
184 int *factor) 186 int *factor)
185{ 187{
186 double diff; 188 double diff;
187 int f; 189 int f;
@@ -189,19 +191,19 @@ GNUNET_TESTBED_SD_deviation_factor_(struct SDHandle *h, unsigned int amount,
189 191
190 if (h->cnt < 2) 192 if (h->cnt < 2)
191 return GNUNET_SYSERR; 193 return GNUNET_SYSERR;
192 if (((float)amount) > h->avg) 194 if (((float) amount) > h->avg)
193 { 195 {
194 diff = ((float)amount) - h->avg; 196 diff = ((float) amount) - h->avg;
195 f = 1; 197 f = 1;
196 } 198 }
197 else 199 else
198 { 200 {
199 diff = h->avg - ((float)amount); 201 diff = h->avg - ((float) amount);
200 f = -1; 202 f = -1;
201 } 203 }
202 diff *= diff; 204 diff *= diff;
203 for (n = 1; n < 4; n++) 205 for (n = 1; n < 4; n++)
204 if (diff < (((double)(n * n)) * h->vr)) 206 if (diff < (((double) (n * n)) * h->vr))
205 break; 207 break;
206 *factor = f * n; 208 *factor = f * n;
207 return GNUNET_OK; 209 return GNUNET_OK;