diff options
author | XANTRONIX Development | 2022-03-07 17:37:02 -0500 |
---|---|---|
committer | XANTRONIX Development | 2022-03-07 17:37:02 -0500 |
commit | 6cb20921e04d134438723feb7b938f74efed8bc8 (patch) | |
tree | 9ea968badd8aa1ac53fc2d58d91d2c2b386f41c1 | |
parent | 475af90bb2a46fb46989bf099295e36f5c05b797 (diff) | |
download | xas-6cb20921e04d134438723feb7b938f74efed8bc8.tar.gz xas-6cb20921e04d134438723feb7b938f74efed8bc8.tar.bz2 xas-6cb20921e04d134438723feb7b938f74efed8bc8.zip |
Fix sequencing, again
-rw-r--r-- | include/xas/seq.h | 3 | ||||
-rw-r--r-- | src/seq.c | 33 |
2 files changed, 28 insertions, 8 deletions
diff --git a/include/xas/seq.h b/include/xas/seq.h index a604d31..f7ec322 100644 --- a/include/xas/seq.h +++ b/include/xas/seq.h @@ -57,7 +57,8 @@ struct _xas_seq_event { typedef struct _xas_seq { xas_spatial_scene *scene; - xas_seq_event *first; + xas_seq_event *first, + *last; size_t buffer_size; } xas_seq; @@ -16,6 +16,7 @@ xas_seq *xas_seq_new(xas_spatial_scene *scene, size_t buffer_size) { seq->scene = scene; seq->first = NULL; + seq->last = NULL; seq->buffer_size = buffer_size; return seq; @@ -39,10 +40,12 @@ void xas_seq_destroy(xas_seq *seq) { } static void add_event(xas_seq *seq, xas_seq_event *ev) { - xas_seq_event *current = seq->first; + xas_seq_event *current = seq->first, + *prev = NULL; if (seq->first == NULL) { seq->first = ev; + seq->last = ev; return; } @@ -50,20 +53,36 @@ static void add_event(xas_seq *seq, xas_seq_event *ev) { while (current) { xas_seq_event *next = current->next; - if (next == NULL) { + if (timercmp(&ev->timestamp, &seq->last->timestamp, >=)) { + seq->last->next = ev; + seq->last = ev; + + return; + } else if (timercmp(&ev->timestamp, ¤t->timestamp, >)) { + ev->next = current->next; current->next = ev; return; - } + } else if (prev && timercmp(&ev->timestamp, &prev->timestamp, >) + && timercmp(&ev->timestamp, ¤t->timestamp, <=)) { + prev->next = ev; + ev->next = current; - if (timercmp(&ev->timestamp, ¤t->timestamp, >=) - && timercmp(&ev->timestamp, &next->timestamp, <)) { - current->next = ev; - ev->next = next; + return; + } else if (prev && timercmp(&ev->timestamp, &prev->timestamp, <=) + && timercmp(&ev->timestamp, &seq->first->timestamp, >)) { + ev->next = seq->first->next; + seq->first->next = ev; + + return; + } else if (timercmp(&ev->timestamp, &seq->first->timestamp, <=)) { + ev->next = seq->first; + seq->first = ev; return; } + prev = current; current = next; } } |