New parameter: result-set file descriptor (RSFD) to support multiple
[idzebra-moved-to-github.git] / index / kcompare.c
1 /*
2  * Copyright (C) 1994-1995, Index Data I/S 
3  * All rights reserved.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Log: kcompare.c,v $
7  * Revision 1.3  1995-09-07 13:58:36  adam
8  * New parameter: result-set file descriptor (RSFD) to support multiple
9  * positions within the same result-set.
10  * Boolean operators: and, or, not implemented.
11  * Result-set references.
12  *
13  * Revision 1.2  1995/09/06  16:11:17  adam
14  * Option: only one word key per file.
15  *
16  * Revision 1.1  1995/09/04  09:10:36  adam
17  * More work on index add/del/update.
18  * Merge sort implemented.
19  * Initial work on z39 server.
20  *
21  */
22
23 #include <stdlib.h>
24 #include <string.h>
25 #include <stdio.h>
26 #include <assert.h>
27
28 #include "index.h"
29
30 int key_compare (const void *p1, const void *p2)
31 {
32     struct it_key i1, i2;
33     memcpy (&i1, p1, sizeof(i1));
34     memcpy (&i2, p2, sizeof(i2));
35     if (i1.sysno != i2.sysno)
36     {
37         if (i1.sysno > i2.sysno)
38             return 2;
39         else
40             return -2;
41     }
42     if (i1.seqno != i2.seqno)
43     {
44         if (i1.seqno > i2.seqno)
45             return 1;
46         else
47             return -1;
48     }
49 #if IT_KEY_HAVE_FIELD
50     if (i1.field != i2.field)
51     {
52         if (i1.field > i2.field)
53             return 1;
54         else
55             return -1;
56     }
57 #endif
58     return 0;
59 }
60
61 int key_compare_x (const struct it_key *i1, const struct it_key *i2)
62 {
63     if ( i1->sysno != i2->sysno)
64         return i1->sysno - i2->sysno;
65 #if IT_KEY_HAVE_FIELD
66     if ( i1->seqno != i2->seqno)
67         return i1->seqno - i2->seqno;
68     return i1->field - i2->field;
69 #else
70     return i1->seqno - i2->seqno;
71 #endif
72 }
73