diff --git a/.gitignore b/.gitignore index d805396..a7afc28 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ A1/coord_query_naive A1/id_query_naive A1/id_query_indexed A1/id_query_binsort +A1/random_ids */.vscode/ .vscode/ \ No newline at end of file diff --git a/A1/coord_query_kdtree.c b/A1/coord_query_kdtree.c index 67d93ab..d00436e 100644 --- a/A1/coord_query_kdtree.c +++ b/A1/coord_query_kdtree.c @@ -16,13 +16,13 @@ double closest_point_distance; int lon_comp_func(const void* a, const void* b) { return ( - ((struct record*)a)->lon - ((struct record*)b)->lon + ((struct record*)a)->lon > ((struct record*)b)->lon ); } int lat_comp_func(const void* a, const void* b) { return ( - ((struct record*)a)->lat - ((struct record*)b)->lat + ((struct record*)a)->lat > ((struct record*)b)->lat ); } diff --git a/A1/id_query_binsort.c b/A1/id_query_binsort.c index 25cae9a..58890a3 100644 --- a/A1/id_query_binsort.c +++ b/A1/id_query_binsort.c @@ -22,7 +22,7 @@ struct indexed_data { int comp_func(const void* a, const void* b) { return ( - ((struct index_record*)a)->osm_id - ((struct index_record*)b)->osm_id + ((struct index_record*)a)->osm_id > ((struct index_record*)b)->osm_id ); } @@ -48,8 +48,9 @@ void free_indexed(struct indexed_data* data) { const struct record* lookup_indexed(struct indexed_data *data, int64_t needle) { int bottom = 0; int top = data->n; + int mid; while (top >= bottom) { - int mid = bottom + ((top - bottom) / 2); + mid = bottom + ((top - bottom) / 2); if ((&data->irs[mid])->osm_id < needle) { bottom = mid + 1; }