Created
May 8, 2015 07:20
-
-
Save ixqbar/0259a6bfe28c83aa9829 to your computer and use it in GitHub Desktop.
krmt-geo代码分析-排序
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//https://github.com/mattsta/krmt | |
static int sort_gp_asc(const void *a, const void *b) { | |
const struct geojsonPoint *gpa = a, *gpb = b; | |
/* We can't do adist - bdist because they are doubles and | |
* the comparator returns an int. */ | |
if (gpa->dist > gpb->dist) | |
return 1; | |
else if (gpa->dist == gpb->dist) | |
return 0; | |
else | |
return -1; | |
} | |
static int sort_gp_desc(const void *a, const void *b) { | |
return -sort_gp_asc(a, b); | |
} | |
struct geojsonPoint *gp = zmalloc(sizeof(*gp) * result_length); | |
... | |
qsort(gp, result_length, sizeof(*gp), sort_gp_asc); | |
... | |
qsort(gp, result_length, sizeof(*gp), sort_gp_desc); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment