Geo taxonomy: correctly store / update the categories

Don't throw away data unless new data has been received. And don't store
multiple copies of the same category. And most importantly, never write
past the end of the array.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2015-07-13 15:18:52 -07:00
parent 94d3aa04dc
commit e82f8ea565
3 changed files with 37 additions and 13 deletions

View file

@ -38,3 +38,11 @@ void free_taxonomy(struct taxonomy_data *t)
t->nr = 0;
}
}
int taxonomy_index_for_category(struct taxonomy_data *t, enum taxonomy_category cat)
{
for (int i = 0; i < t->nr; i++)
if (t->category[i].category == cat)
return i;
return -1;
}