diff --git a/include/villas/hist.h b/include/villas/hist.h index 477470956..b3043deb8 100644 --- a/include/villas/hist.h +++ b/include/villas/hist.h @@ -79,34 +79,34 @@ void hist_reset(struct hist *h); void hist_put(struct hist *h, double value); /** Calcluate the variance of all counted values. */ -double hist_var(struct hist *h); +double hist_var(const struct hist *h); /** Calculate the mean average of all counted values. */ -double hist_mean(struct hist *h); +double hist_mean(const struct hist *h); /** Calculate the standard derivation of all counted values. */ -double hist_stddev(struct hist *h); +double hist_stddev(const struct hist *h); /** Print all statistical properties of distribution including a graphilcal plot of the histogram. */ -void hist_print(struct hist *h, int details); +void hist_print(const struct hist *h, int details); /** Print ASCII style plot of histogram */ -void hist_plot(struct hist *h); +void hist_plot(const struct hist *h); /** Dump histogram data in Matlab format. * * @return The string containing the dump. The caller is responsible to free() the buffer. */ -char * hist_dump(struct hist *h); +char * hist_dump(const struct hist *h); /** Prints Matlab struct containing all infos to file. */ -int hist_dump_matlab(struct hist *h, FILE *f); +int hist_dump_matlab(const struct hist *h, FILE *f); /** Write the histogram in JSON format to fiel \p f. */ -int hist_dump_json(struct hist *h, FILE *f); +int hist_dump_json(const struct hist *h, FILE *f); /** Build a libjansson / JSON object of the histogram. */ -json_t * hist_json(struct hist *h); +json_t * hist_json(const struct hist *h); #ifdef __cplusplus } diff --git a/include/villas/mapping.h b/include/villas/mapping.h index 0ab06db7a..89ec23817 100644 --- a/include/villas/mapping.h +++ b/include/villas/mapping.h @@ -99,9 +99,9 @@ struct mapping_entry { }; }; -int mapping_remap(struct list *m, struct sample *remapped, struct sample *original, struct stats *s); +int mapping_remap(const struct list *m, struct sample *remapped, const struct sample *original, const struct stats *s); -int mapping_update(struct mapping_entry *e, struct sample *remapped, struct sample *original, struct stats *s); +int mapping_update(const struct mapping_entry *e, struct sample *remapped, const struct sample *original, const struct stats *s); int mapping_parse(struct mapping_entry *e, json_t *cfg, struct list *nodes); @@ -109,7 +109,7 @@ int mapping_parse_str(struct mapping_entry *e, const char *str, struct list *nod int mapping_parse_list(struct list *l, json_t *cfg, struct list *nodes); -int mapping_to_str(struct mapping_entry *me, unsigned index, char **str); +int mapping_to_str(const struct mapping_entry *me, unsigned index, char **str); #ifdef __cplusplus } diff --git a/lib/hist.c b/lib/hist.c index 0d969ef00..ac1b4def7 100644 --- a/lib/hist.c +++ b/lib/hist.c @@ -119,22 +119,22 @@ void hist_reset(struct hist *h) memset(h->data, 0, h->length * sizeof(unsigned)); } -double hist_mean(struct hist *h) +double hist_mean(const struct hist *h) { return (h->total > 0) ? h->_m[0] : NAN; } -double hist_var(struct hist *h) +double hist_var(const struct hist *h) { return (h->total > 1) ? h->_s[0] / (h->total - 1) : NAN; } -double hist_stddev(struct hist *h) +double hist_stddev(const struct hist *h) { return sqrt(hist_var(h)); } -void hist_print(struct hist *h, int details) +void hist_print(const struct hist *h, int details) { if (h->total > 0) { hist_cnt_t missed = h->total - h->higher - h->lower; @@ -159,7 +159,7 @@ void hist_print(struct hist *h, int details) stats("Counted values: %ju", h->total); } -void hist_plot(struct hist *h) +void hist_plot(const struct hist *h) { hist_cnt_t max = 1; @@ -200,7 +200,7 @@ void hist_plot(struct hist *h) table_footer(&table); } -char * hist_dump(struct hist *h) +char * hist_dump(const struct hist *h) { char *buf = alloc(128); @@ -214,7 +214,7 @@ char * hist_dump(struct hist *h) return buf; } -json_t * hist_json(struct hist *h) +json_t * hist_json(const struct hist *h) { json_t *json_buckets, *json_hist; @@ -248,7 +248,7 @@ json_t * hist_json(struct hist *h) return json_hist; } -int hist_dump_json(struct hist *h, FILE *f) +int hist_dump_json(const struct hist *h, FILE *f) { json_t *j = hist_json(h); @@ -259,7 +259,7 @@ int hist_dump_json(struct hist *h, FILE *f) return ret; } -int hist_dump_matlab(struct hist *h, FILE *f) +int hist_dump_matlab(const struct hist *h, FILE *f) { fprintf(f, "struct("); fprintf(f, "'low', %f, ", h->low); diff --git a/lib/mapping.c b/lib/mapping.c index 9db88f2b5..4b7f16269 100644 --- a/lib/mapping.c +++ b/lib/mapping.c @@ -240,7 +240,7 @@ out: json_decref(json_mapping); return ret; } -int mapping_update(struct mapping_entry *me, struct sample *remapped, struct sample *original, struct stats *s) +int mapping_update(const struct mapping_entry *me, struct sample *remapped, const struct sample *original, const struct stats *s) { int len = me->length; int off = me->offset; @@ -257,7 +257,7 @@ int mapping_update(struct mapping_entry *me, struct sample *remapped, struct sam switch (me->type) { case MAPPING_TYPE_STATS: { - struct hist *h = &s->histograms[me->stats.id]; + const struct hist *h = &s->histograms[me->stats.id]; switch (me->stats.type) { case MAPPING_STATS_TYPE_TOTAL: @@ -288,7 +288,7 @@ int mapping_update(struct mapping_entry *me, struct sample *remapped, struct sam } case MAPPING_TYPE_TIMESTAMP: { - struct timespec *ts; + const struct timespec *ts; switch (me->timestamp.type) { case MAPPING_TIMESTAMP_TYPE_RECEIVED: @@ -347,7 +347,7 @@ int mapping_update(struct mapping_entry *me, struct sample *remapped, struct sam return 0; } -int mapping_remap(struct list *m, struct sample *remapped, struct sample *original, struct stats *s) +int mapping_remap(const struct list *m, struct sample *remapped, const struct sample *original, const struct stats *s) { int ret; @@ -366,7 +366,7 @@ int mapping_remap(struct list *m, struct sample *remapped, struct sample *origin return 0; } -int mapping_to_str(struct mapping_entry *me, unsigned index, char **str) +int mapping_to_str(const struct mapping_entry *me, unsigned index, char **str) { const char *type;