summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/queue.c19
-rw-r--r--lib/queue.h7
-rw-r--r--lib/wolff.h2
-rw-r--r--lib/wolff_tools.c30
4 files changed, 47 insertions, 11 deletions
diff --git a/lib/queue.c b/lib/queue.c
index aebbb2a..0823518 100644
--- a/lib/queue.c
+++ b/lib/queue.c
@@ -9,6 +9,14 @@ void stack_push(ll_t **q, uint32_t x) {
*q = nq;
}
+void stack_push_d(dll_t **q, double x) {
+ dll_t *nq = malloc(sizeof(dll_t));
+ nq->x = x;
+ nq->next = *q;
+
+ *q = nq;
+}
+
uint32_t stack_pop(ll_t **q) {
ll_t *old_q = *q;
@@ -20,6 +28,17 @@ uint32_t stack_pop(ll_t **q) {
return x;
}
+double stack_pop_d(dll_t **q) {
+ dll_t *old_q = *q;
+
+ *q = old_q->next;
+ double x = old_q->x;
+
+ free(old_q);
+
+ return x;
+}
+
bool stack_contains(const ll_t *q, uint32_t x) {
if (q == NULL) {
return false;
diff --git a/lib/queue.h b/lib/queue.h
index c7acec1..23834ba 100644
--- a/lib/queue.h
+++ b/lib/queue.h
@@ -11,8 +11,15 @@ typedef struct ll_tag {
struct ll_tag *next;
} ll_t;
+typedef struct dll_tag {
+ double x;
+ struct dll_tag *next;
+} dll_t;
+
void stack_push(ll_t **q, uint32_t x);
+void stack_push_d(dll_t **q, double x);
uint32_t stack_pop(ll_t **q);
+double stack_pop_d(dll_t **q);
bool stack_contains(const ll_t *q, uint32_t x);
diff --git a/lib/wolff.h b/lib/wolff.h
index cf24427..66ce493 100644
--- a/lib/wolff.h
+++ b/lib/wolff.h
@@ -54,7 +54,7 @@ typedef struct {
uint64_t n;
uint64_t W;
double *OO;
- double *Op;
+ dll_t *Op;
double O;
double O2;
} autocorr_t;
diff --git a/lib/wolff_tools.c b/lib/wolff_tools.c
index 92e8302..a417d4e 100644
--- a/lib/wolff_tools.c
+++ b/lib/wolff_tools.c
@@ -258,21 +258,31 @@ void update_autocorr(autocorr_t *OO, double O) {
OO->O = add_to_avg(OO->O, O, OO->n);
OO->O2 = add_to_avg(OO->O2, pow(O, 2), OO->n);
- uint64_t lim = OO->W;
-
- if (OO->n < OO->W) {
- lim = OO->n;
+ dll_t *Otmp = OO->Op;
+ dll_t *Osave;
+ uint64_t t = 0;
+
+ while (Otmp != NULL) {
+ OO->OO[t] = add_to_avg(OO->OO[t], O * (Otmp->x), OO->n - t - 1);
+ t++;
+ if (t == OO->W - 1) {
+ Osave = Otmp;
+ }
+ Otmp = Otmp->next;
}
- for (uint64_t t = 0; t < lim; t++) {
- OO->OO[t] = add_to_avg(OO->OO[t], O * OO->Op[t], OO->n - t - 1);
+ if (t == OO->W) {
+ if (OO->W == 1) {
+ free(OO->Op);
+ OO->Op = NULL;
+ } else {
+ free(Osave->next);
+ Osave->next = NULL;
+ }
}
- for (uint64_t t = 0; t < OO->W - 1; t++) {
- OO->Op[OO->W - 1 - t] = OO->Op[OO->W - 2 - t];
- }
+ stack_push_d(&(OO->Op), O);
- OO->Op[0] = O;
OO->n++;
}