First work on multi-way read.
[idzebra-moved-to-github.git] / index / zsets.c
index 2963e4f..75d5c6c 100644 (file)
@@ -1,10 +1,26 @@
 /*
- * Copyright (C) 1995, Index Data I/S 
+ * Copyright (C) 1994-1995, Index Data I/S 
  * All rights reserved.
  * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: zsets.c,v $
- * Revision 1.2  1995-09-06 10:33:04  adam
+ * Revision 1.6  1995-09-28 09:19:49  adam
+ * xfree/xmalloc used everywhere.
+ * Extract/retrieve method seems to work for text records.
+ *
+ * Revision 1.5  1995/09/27  16:17:32  adam
+ * More work on retrieve.
+ *
+ * Revision 1.4  1995/09/07  13:58:36  adam
+ * New parameter: result-set file descriptor (RSFD) to support multiple
+ * positions within the same result-set.
+ * Boolean operators: and, or, not implemented.
+ * Result-set references.
+ *
+ * Revision 1.3  1995/09/06  16:11:19  adam
+ * Option: only one word key per file.
+ *
+ * Revision 1.2  1995/09/06  10:33:04  adam
  * More work on present. Some log messages removed.
  *
  * Revision 1.1  1995/09/05  15:28:40  adam
@@ -50,8 +66,62 @@ ZServerSet *resultSetGet (ZServerInfo *zi, const char *name)
     return NULL;
 }
 
-ZServerRecord *resultSetRecordGet (ZServerInfo *zi, const char *name, 
-                                   int num, int *positions)
+ZServerSetSysno *resultSetSysnoGet  (ZServerInfo *zi, const char *name, 
+                                     int num, int *positions)
+{
+    ZServerSet *sset;
+    ZServerSetSysno *sr;
+    RSET rset;
+    int num_i = 0;
+    int position = 0;
+    int psysno = 0;
+    struct it_key key;
+    RSFD rfd;
+
+    if (!(sset = resultSetGet (zi, name)))
+        return NULL;
+    if (!(rset = sset->rset))
+        return NULL;
+    logf (LOG_DEBUG, "resultSetRecordGet");
+    sr = xmalloc (sizeof(*sr) * num);
+    rfd = rset_open (rset, 0);
+    while (rset_read (rset, rfd, &key))
+    {
+        if (key.sysno != psysno)
+        {
+            psysno = key.sysno;
+            position++;
+            if (position == positions[num_i])
+            {
+                sr[num_i].sysno = psysno;
+                num_i++;
+                if (++num_i == num)
+                    break;
+            }
+        }
+    }
+    rset_close (rset, rfd);
+    while (num_i < num)
+    {
+        sr[num_i].sysno = 0;
+        num_i++;
+    }
+    return sr;
+}
+
+void resultSetRecordDel (ZServerInfo *zi, ZServerRecord *records, int num)
+{
+    int i;
+
+    for (i = 0; i<num; i++)
+        xfree (records[i].buf);
+    xfree (records);
+}
+
+
+#if 0
+ZServerSetSysno *resultSetSysno  (ZServerInfo *zi, const char *name, 
+                                  int num, int *positions)
 {
     ZServerSet *sset;
     ZServerRecord *sr;
@@ -60,6 +130,7 @@ ZServerRecord *resultSetRecordGet (ZServerInfo *zi, const char *name,
     int position = 0;
     int psysno = 0;
     struct it_key key;
+    RSFD rfd;
 
     if (!(sset = resultSetGet (zi, name)))
         return NULL;
@@ -67,8 +138,8 @@ ZServerRecord *resultSetRecordGet (ZServerInfo *zi, const char *name,
         return NULL;
     logf (LOG_DEBUG, "resultSetRecordGet");
     sr = xmalloc (sizeof(*sr) * num);
-    rset_open (rset, 0);
-    while (rset_read (rset, &key))
+    rfd = rset_open (rset, 0);
+    while (rset_read (rset, rfd, &key))
     {
         if (key.sysno != psysno)
         {
@@ -118,7 +189,7 @@ ZServerRecord *resultSetRecordGet (ZServerInfo *zi, const char *name,
             }
         }
     }
-    rset_close (rset);
+    rset_close (rset, rfd);
     while (num_i < num)
     {
         sr[num_i].buf = NULL;
@@ -127,12 +198,4 @@ ZServerRecord *resultSetRecordGet (ZServerInfo *zi, const char *name,
     }
     return sr;
 }
-
-void resultSetRecordDel (ZServerInfo *zi, ZServerRecord *records, int num)
-{
-    int i;
-
-    for (i = 0; i<num; i++)
-        free (records[i].buf);
-    free (records);
-}
+#endif