]> mj.ucw.cz Git - libucw.git/blob - lib/index.h
The StringMap file contains an end marker pointing past the last
[libucw.git] / lib / index.h
1 /*
2  *      Sherlock Gatherer: Data structures used in indices
3  *
4  *      (c) 2001 Martin Mares <mj@ucw.cz>
5  */
6
7 #define CLAMP(x,min,max) ({ int _t=x; (_t < min) ? min : (_t > max) ? max : _t; })
8
9 /* Words */
10
11 #define MAX_WORD_LEN            64
12
13 /* Word types */
14
15 enum word_type {
16   WT_RESERVED,                          /* Reserved word type */
17   WT_TEXT,                              /* Ordinary text */
18   WT_EMPH,                              /* Emphasized text */
19   WT_SMALL,                             /* Small font */
20   WT_TITLE,                             /* Document title */
21   WT_SMALL_HEADING,                     /* Heading */
22   WT_BIG_HEADING,                       /* Larger heading */
23   WT_KEYWORD,                           /* Explicitly marked keyword */
24   WT_META,                              /* Various meta-information */
25   WT_ALT                                /* Alternate texts for graphical elements */
26 };
27
28 #define WORD_TYPE_NAMES                         \
29         T(WORD, ~0)                             \
30         T(TEXT, 1 << WT_TEXT)                   \
31         T(EMPH, 1 << WT_EMPH)                   \
32         T(SMALL, 1 << WT_SMALL)                 \
33         T(TITLE, 1 << WT_TITLE)                 \
34         T(HDR, (1 << WT_SMALL_HEADING) | (1 << WT_BIG_HEADING))  \
35         T(HDR1, 1 << WT_SMALL_HEADING)          \
36         T(HDR2, 1 << WT_BIG_HEADING)            \
37         T(KEYWD, 1 << WT_KEYWORD)               \
38         T(META, 1 << WT_META)                   \
39         T(ALT, 1 << WT_ALT)
40
41 /* String types */
42
43 enum string_type {
44   ST_RESERVED,                          /* Reserved string type */
45   ST_URL,                               /* URL of the document */
46   ST_HOST,                              /* Host name */
47   ST_DOMAIN,                            /* Domain name */
48   ST_REF,                               /* URL reference */
49   ST_BACKREF,                           /* Back-reference (frame or redirect source) */
50 };
51
52 #define STRING_TYPE_NAMES                       \
53         T(URL, 1 << ST_URL)                     \
54         T(HOST, 1 << ST_HOST)                   \
55         T(DOMAIN, 1 << ST_DOMAIN)               \
56         T(REF, 1 << ST_REF)                     \
57         T(BACKREF, 1 << ST_BACKREF)
58
59 #define STRING_TYPES_URL ((1 << ST_URL) | (1 << ST_REF) | (1 << ST_BACKREF))
60 /* These must be indexed in lowercase form */
61 #define STRING_TYPES_CASE_INSENSITIVE ((1 << ST_HOST) | (1 << ST_DOMAIN))
62
63 /* Index card attributes */
64
65 struct card_attr {
66   u32 card;                             /* Reference to card description (either oid or filepos) */
67   u32 site_id;
68   byte weight;
69   byte flags;
70   byte rfu[2];
71 };
72
73 enum card_flag {
74   CARD_FLAG_EMPTY = 1,                  /* Empty document (redirect, robot file etc.) [scanner] */
75   CARD_FLAG_ACCENTED = 2,               /* Document contains accented characters [scanner] */
76   CARD_FLAG_DUP = 4,                    /* Removed as a duplicate [merger] */
77   CARD_FLAG_MERGED = 8,                 /* Destination of a merge [merger] */
78 };
79
80 #define CARD_POS_SHIFT 5                /* Card positions are shifted this # of bytes to the right */
81
82 /* String fingerprints */
83
84 struct fingerprint {
85   byte hash[12];
86 };
87
88 void fingerprint(byte *string, struct fingerprint *fp);
89
90 static inline u32
91 fp_hash(struct fingerprint *fp)
92 {
93   return (fp->hash[0] << 24) | (fp->hash[1] << 16) | (fp->hash[2] << 8) | fp->hash[3];
94 }
95
96 /* Reading of tagged text (Unicode values, tags mapped to 0x80000000 and higher) */
97
98 #define GET_TAGGED_CHAR(p,u) do {                               \
99   u = *p;                                                       \
100   if (u >= 0xc0)                                                \
101     GET_UTF8(p,u);                                              \
102   else if (u >= 0x80)                                           \
103     {                                                           \
104       p++;                                                      \
105       if (u >= 0xb0)                                            \
106         u += 0x80020000;                                        \
107       else if (u >= 0xa0)                                       \
108         u = 0x80010000 + ((u & 0x0f) << 6) + (*p++ & 0x3f);     \
109       else                                                      \
110         u += 0x80000000;                                        \
111     }                                                           \
112   else                                                          \
113     p++;                                                        \
114 } while (0)