Refactor: hide reclist structure
[pazpar2-moved-to-github.git] / src / reclists.c
index 48ce8e7..44ed96c 100644 (file)
@@ -27,6 +27,21 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
 #include "pazpar2.h"
 #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 */
 
@@ -231,23 +246,6 @@ void reclist_rewind(struct reclist *l)
         l->pointer = 0;
 }
 
-// Jenkins one-at-a-time hash (from wikipedia)
-static unsigned int hash(const unsigned char *key)
-{
-    unsigned int hash = 0;
-
-    while (*key)
-    {
-        hash += *(key++);
-        hash += (hash << 10);
-        hash ^= (hash >> 6);
-    }
-    hash += (hash << 3);
-    hash ^= (hash >> 11);
-    hash += (hash << 15);
-    return hash;
-}
-
 struct reclist *reclist_create(NMEM nmem, int numrecs)
 {
     int hashsize = 1;
@@ -271,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, 
@@ -287,7 +297,7 @@ struct record_cluster *reclist_insert( struct reclist *l,
     assert(merge_key);
     assert(total);
 
-    bucket = hash((unsigned char*) merge_key) & l->hashmask;
+    bucket = jenkins_hash((unsigned char*) merge_key) & l->hashmask;
 
     for (p = &l->hashtable[bucket]; *p; p = &(*p)->next)
     {