]> mj.ucw.cz Git - libucw.git/blob - lib/index.h
Initial version of SQL gathering utility gsql added.
[libucw.git] / lib / index.h
1 /*
2  *      Sherlock: Data structures used in indices
3  *
4  *      (c) 2001 Martin Mares <mj@ucw.cz>
5  */
6
7 /* Words */
8
9 #define MAX_WORD_LEN            64
10
11 /* Word and string types are defined in lib/custom.h */
12
13 /* Index card attributes */
14
15 struct card_attr {
16   u32 card;                             /* Reference to card description (either oid or filepos) */
17   u32 site_id;
18   byte weight;
19   byte flags;
20   byte rfu[2];
21 };
22
23 enum card_flag {
24   CARD_FLAG_EMPTY = 1,                  /* Empty document (redirect, robot file etc.) [scanner] */
25   CARD_FLAG_ACCENTED = 2,               /* Document contains accented characters [scanner] */
26   CARD_FLAG_DUP = 4,                    /* Removed as a duplicate [merger] */
27   CARD_FLAG_MERGED = 8,                 /* Destination of a merge [merger] */
28 };
29
30 #define CARD_POS_SHIFT 5                /* Card positions are shifted this # of bytes to the right */
31
32 /* String fingerprints */
33
34 struct fingerprint {
35   byte hash[12];
36 };
37
38 void fingerprint(byte *string, struct fingerprint *fp);
39
40 static inline u32
41 fp_hash(struct fingerprint *fp)
42 {
43   return (fp->hash[0] << 24) | (fp->hash[1] << 16) | (fp->hash[2] << 8) | fp->hash[3];
44 }
45
46 /* Reading of tagged text (Unicode values, tags mapped to 0x80000000 and higher) */
47
48 #define GET_TAGGED_CHAR(p,u) do {                               \
49   u = *p;                                                       \
50   if (u >= 0xc0)                                                \
51     GET_UTF8_CHAR(p,u);                                         \
52   else if (u >= 0x80)                                           \
53     {                                                           \
54       p++;                                                      \
55       if (u >= 0xb0)                                            \
56         {                                                       \
57           if (u != 0xb0)                                        \
58             ASSERT(0);                                          \
59           u += 0x80020000;                                      \
60         }                                                       \
61       else if (u >= 0xa0)                                       \
62         {                                                       \
63           ASSERT(*p >= 0x80 && *p <= 0xbf);                     \
64           u = 0x80010000 + ((u & 0x0f) << 6) + (*p++ & 0x3f);   \
65         }                                                       \
66       else                                                      \
67         u += 0x80000000;                                        \
68     }                                                           \
69   else                                                          \
70     p++;                                                        \
71 } while (0)