From 0818e0450b743e626ef22adb9491831d547beffa Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Thu, 8 Oct 2009 14:52:34 +0200 Subject: [PATCH] Refactor: hide reclist structure --- src/http_command.c | 2 +- src/logic.c | 2 +- src/reclists.c | 26 ++++++++++++++++++++++++++ src/reclists.h | 17 ++++------------- src/relevance.c | 6 +++--- 5 files changed, 35 insertions(+), 18 deletions(-) diff --git a/src/http_command.c b/src/http_command.c index 6c68ae4..c8bf0ba 100644 --- a/src/http_command.c +++ b/src/http_command.c @@ -812,7 +812,7 @@ static void cmd_show(struct http_channel *c) if (block) { - if (status && (!s->psession->reclist || !s->psession->reclist->num_records)) + if (status && reclist_get_num_records(s->psession->reclist) == 0) { // if there is already a watch/block. we do not block this one if (session_set_watch(s->psession, SESSION_WATCH_SHOW, diff --git a/src/logic.c b/src/logic.c index 302b6b5..550222e 100644 --- a/src/logic.c +++ b/src/logic.c @@ -779,7 +779,7 @@ struct record_cluster **show(struct session *s, struct reclist_sortparms *sp, } reclist_sort(s->reclist, sp); - *total = s->reclist->num_records; + *total = reclist_get_num_records(s->reclist); *sumhits = s->total_hits; for (i = 0; i < start; i++) diff --git a/src/reclists.c b/src/reclists.c index 3e3100c..44ed96c 100644 --- a/src/reclists.c +++ b/src/reclists.c @@ -29,6 +29,20 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include "reclists.h" #include "jenkins_hash.h" +struct reclist +{ + struct reclist_bucket **hashtable; + int hashtable_size; + int hashmask; + + struct record_cluster **flatlist; + int flatlist_size; + int num_records; + int pointer; + + NMEM nmem; +}; + static struct reclist_sortparms *qsort_sortparms = 0; /* thread pr */ struct reclist_bucket @@ -255,6 +269,18 @@ struct reclist *reclist_create(NMEM nmem, int numrecs) return res; } +int reclist_get_num_records(struct reclist *l) +{ + if (l) + return l->num_records; + return 0; +} + +struct record_cluster *reclist_get_cluster(struct reclist *l, int i) +{ + return l->flatlist[i]; +} + // Insert a record. Return record cluster (newly formed or pre-existing) struct record_cluster *reclist_insert( struct reclist *l, struct conf_service *service, diff --git a/src/reclists.h b/src/reclists.h index e75b5da..fcf5919 100644 --- a/src/reclists.h +++ b/src/reclists.h @@ -23,19 +23,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include "pazpar2_config.h" #include "record.h" -struct reclist -{ - struct reclist_bucket **hashtable; - int hashtable_size; - int hashmask; - - struct record_cluster **flatlist; - int flatlist_size; - int num_records; - int pointer; - - NMEM nmem; -}; +struct reclist; // This is a recipe for sorting. First node in list has highest priority struct reclist_sortparms @@ -73,6 +61,9 @@ void reclist_rewind(struct reclist *l); struct reclist_sortparms *reclist_parse_sortparms(NMEM nmem, const char *parms, struct conf_service *service); +int reclist_get_num_records(struct reclist *l); +struct record_cluster *reclist_get_cluster(struct reclist *l, int i); + #endif /* diff --git a/src/relevance.c b/src/relevance.c index 8690763..a338917 100644 --- a/src/relevance.c +++ b/src/relevance.c @@ -308,10 +308,10 @@ void relevance_prepare_read(struct relevance *rel, struct reclist *reclist) } } // Calculate relevance for each document - for (i = 0; i < reclist->num_records; i++) + for (i = 0; i < reclist_get_num_records(reclist); i++) { int t; - struct record_cluster *rec = reclist->flatlist[i]; + struct record_cluster *rec = reclist_get_cluster(reclist, i); float relevance; relevance = 0; for (t = 1; t < rel->vec_len; t++) @@ -324,7 +324,7 @@ void relevance_prepare_read(struct relevance *rel, struct reclist *reclist) } rec->relevance = (int) (relevance * 100000); } - reclist->pointer = 0; + reclist_rewind(reclist); xfree(idfvec); } -- 1.7.10.4