summaryrefslogtreecommitdiff
path: root/choices.c
diff options
context:
space:
mode:
authorJohn Hawthorn <john.hawthorn@gmail.com>2014-09-21 14:40:36 -0700
committerJohn Hawthorn <john.hawthorn@gmail.com>2014-09-27 16:50:08 -0700
commitd5749099950bf2e4302b9cf12658092d007d8d4b (patch)
tree41e112b880335b432ddd248700c7e7b081f4312d /choices.c
parentef663072f61e21c29a8885e6518d28fae6f9c91c (diff)
Store string in result instead of position
Diffstat (limited to 'choices.c')
-rw-r--r--choices.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/choices.c b/choices.c
index 6bad58c..2a27d10 100644
--- a/choices.c
+++ b/choices.c
@@ -7,8 +7,8 @@
#define INITIAL_CAPACITY 1
static int cmpchoice(const void *_idx1, const void *_idx2) {
- const struct scored_position *a = _idx1;
- const struct scored_position *b = _idx2;
+ const struct scored_result *a = _idx1;
+ const struct scored_result *b = _idx2;
if(a->score == b->score)
return 0;
@@ -65,7 +65,7 @@ size_t choices_available(choices_t *c){
void choices_search(choices_t *c, const char *search){
choices_reset_search(c);
- c->results = malloc(c->size * sizeof(struct scored_position));
+ c->results = malloc(c->size * sizeof(struct scored_result));
if(!c->results){
fprintf(stderr, "Error: Can't allocate memory\n");
abort();
@@ -73,18 +73,18 @@ void choices_search(choices_t *c, const char *search){
for(size_t i = 0; i < c->size; i++){
if(has_match(search, c->strings[i])){
- c->results[c->available].position = i;
+ c->results[c->available].str = c->strings[i];
c->results[c->available].score = match(search, c->strings[i]);
c->available++;
}
}
- qsort(c->results, c->available, sizeof(struct scored_position), cmpchoice);
+ qsort(c->results, c->available, sizeof(struct scored_result), cmpchoice);
}
const char *choices_get(choices_t *c, size_t n){
if(n < c->available){
- return c->strings[c->results[n].position];
+ return c->results[n].str;
}else{
return NULL;
}