Commit 7156e2cd authored by dagal's avatar dagal
Browse files

Thread-safe CTR queries

parent 3e12f97e
...@@ -25,8 +25,6 @@ QueryType queryTypes[16] = { ...@@ -25,8 +25,6 @@ QueryType queryTypes[16] = {
{15, 4, false, get_from_x_to_y} {15, 4, false, get_from_x_to_y}
}; };
TimeQuery *query;
TimeQuery * prepareQuery() { TimeQuery * prepareQuery() {
TimeQuery *tq = (TimeQuery *) malloc(sizeof(TimeQuery)); TimeQuery *tq = (TimeQuery *) malloc(sizeof(TimeQuery));
tq->values = (uint *) malloc(sizeof(uint)*8); tq->values = (uint *) malloc(sizeof(uint)*8);
...@@ -69,54 +67,64 @@ void * CTR_load(char *filename, char *linesFile, char *timesFile, char *commons) ...@@ -69,54 +67,64 @@ void * CTR_load(char *filename, char *linesFile, char *timesFile, char *commons)
index_size(index, &Index_size); index_size(index, &Index_size);
query = prepareQuery();
return index; return index;
} }
void CTR_free(void * ctr) { void CTR_free(void * ctr) {
free_index(ctr); free_index(ctr);
freeQuery(query);
} }
uint64_t CTR_start(void * ctr, uint32_t s, uint32_t h_start, uint32_t h_end) { uint64_t CTR_start(void * ctr, uint32_t s, uint32_t h_start, uint32_t h_end) {
TimeQuery *query = prepareQuery();
query->values[1] = s; query->values[1] = s;
query->time->h_start = h_start; query->time->h_start = h_start;
query->time->h_end = h_end; query->time->h_end = h_end;
query->subtype = 0; query->subtype = 0;
if (h_end) query->subtype |= XY_TIME_START; if (h_end) query->subtype |= XY_TIME_START;
return get_starts_with_x(ctr, query); uint64_t result = get_starts_with_x(ctr, query);
freeQuery(query);
return result;
} }
uint64_t CTR_end(void * ctr, uint32_t s, uint32_t h_start, uint32_t h_end) { uint64_t CTR_end(void * ctr, uint32_t s, uint32_t h_start, uint32_t h_end) {
TimeQuery *query = prepareQuery();
query->values[1] = s; query->values[1] = s;
query->time->h_start = h_start; query->time->h_start = h_start;
query->time->h_end = h_end; query->time->h_end = h_end;
query->subtype = 0; query->subtype = 0;
if (h_end) query->subtype |= XY_TIME_END; if (h_end) query->subtype |= XY_TIME_END;
return get_ends_with_x(ctr, query); uint64_t result = get_ends_with_x(ctr, query);
freeQuery(query);
return result;
} }
uint64_t CTR_switch(void * ctr, uint32_t s, uint32_t h_start, uint32_t h_end) { uint64_t CTR_switch(void * ctr, uint32_t s, uint32_t h_start, uint32_t h_end) {
TimeQuery *query = prepareQuery();
query->values[1] = s; query->values[1] = s;
query->time->h_start = h_start; query->time->h_start = h_start;
query->time->h_end = h_end; query->time->h_end = h_end;
query->subtype = 0; query->subtype = 0;
if (h_end) query->subtype |= XY_TIME_START; if (h_end) query->subtype |= XY_TIME_START;
return get_x_in_the_middle(ctr, query); uint64_t result = get_x_in_the_middle(ctr, query);
freeQuery(query);
return result;
} }
uint64_t CTR_board(void * ctr, uint32_t s, uint32_t h_start, uint32_t h_end) { uint64_t CTR_board(void * ctr, uint32_t s, uint32_t h_start, uint32_t h_end) {
TimeQuery *query = prepareQuery();
query->values[1] = s; query->values[1] = s;
query->time->h_start = h_start; query->time->h_start = h_start;
query->time->h_end = h_end; query->time->h_end = h_end;
query->subtype = 0; query->subtype = 0;
if (h_end) query->subtype |= XY_TIME_START; if (h_end) query->subtype |= XY_TIME_START;
return get_uses_x(ctr, query); uint64_t result = get_uses_x(ctr, query);
freeQuery(query);
return result;
} }
uint64_t CTR_xy(void * ctr, uint32_t s1, uint32_t s2, uint32_t h_start, uint32_t h_end) { uint64_t CTR_xy(void * ctr, uint32_t s1, uint32_t s2, uint32_t h_start, uint32_t h_end) {
TimeQuery *query = prepareQuery();
query->values[1] = s1; query->values[1] = s1;
query->values[3] = s2; query->values[3] = s2;
query->time->h_start = h_start; query->time->h_start = h_start;
...@@ -124,5 +132,8 @@ uint64_t CTR_xy(void * ctr, uint32_t s1, uint32_t s2, uint32_t h_start, uint32_t ...@@ -124,5 +132,8 @@ uint64_t CTR_xy(void * ctr, uint32_t s1, uint32_t s2, uint32_t h_start, uint32_t
query->subtype = 0; query->subtype = 0;
if (h_end) query->subtype |= XY_TIME_START; if (h_end) query->subtype |= XY_TIME_START;
// TODO XY_TIME_END // TODO XY_TIME_END
return get_from_x_to_y(ctr, query);
uint64_t result = get_from_x_to_y(ctr, query);
freeQuery(query);
return result;
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment