]> mj.ucw.cz Git - libucw.git/blob - lib/index.h
6a22cf17b3b66149120b493cc44e2b2e619cb8c4
[libucw.git] / lib / index.h
1 /*
2  *      Sherlock: Data structures used in indices
3  *
4  *      (c) 2001--2002 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 #define INT_ATTR(t,i,o,k,g,p) t i;
19   CUSTOM_ATTRS                          /* Include all custom attributes */
20 #undef INT_ATTR
21   byte weight;
22   byte flags;
23   // byte rfu[2];                       /* If no custom attributes are defined */
24 };
25
26 enum card_flag {
27   CARD_FLAG_EMPTY = 1,                  /* Empty document (redirect, robot file etc.) [scanner] */
28   CARD_FLAG_ACCENTED = 2,               /* Document contains accented characters [scanner] */
29   CARD_FLAG_DUP = 4,                    /* Removed as a duplicate [merger] */
30   CARD_FLAG_MERGED = 8,                 /* Destination of a merge [merger] */
31 };
32
33 #define CARD_POS_SHIFT 5                /* Card positions are shifted this # of bytes to the right */
34
35 /* String fingerprints */
36
37 struct fingerprint {
38   byte hash[12];
39 };
40
41 void fingerprint(byte *string, struct fingerprint *fp);
42
43 static inline u32
44 fp_hash(struct fingerprint *fp)
45 {
46   return (fp->hash[0] << 24) | (fp->hash[1] << 16) | (fp->hash[2] << 8) | fp->hash[3];
47 }
48
49 /* Reading of tagged text (Unicode values, tags mapped to 0x80000000 and higher) */
50
51 #define GET_TAGGED_CHAR(p,u) do {                               \
52   u = *p;                                                       \
53   if (u >= 0xc0)                                                \
54     GET_UTF8_CHAR(p,u);                                         \
55   else if (u >= 0x80)                                           \
56     {                                                           \
57       p++;                                                      \
58       if (u >= 0xb0)                                            \
59         {                                                       \
60           if (u != 0xb0)                                        \
61             ASSERT(0);                                          \
62           u += 0x80020000;                                      \
63         }                                                       \
64       else if (u >= 0xa0)                                       \
65         {                                                       \
66           ASSERT(*p >= 0x80 && *p <= 0xbf);                     \
67           u = 0x80010000 + ((u & 0x0f) << 6) + (*p++ & 0x3f);   \
68         }                                                       \
69       else                                                      \
70         u += 0x80000000;                                        \
71     }                                                           \
72   else                                                          \
73     p++;                                                        \
74 } while (0)