]> mj.ucw.cz Git - libucw.git/blob - lib/index.h
Implemented base-224 encoder and decoder.
[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 /* Global index parameters */
14
15 struct index_params {
16   sh_time_t ref_time;                   /* Reference time (for document ages etc.) */
17 };
18
19 /* Index card attributes */
20
21 struct card_attr {
22   u32 card;                             /* Reference to card description (either oid or filepos) */
23   u32 site_id;
24 #define INT_ATTR(t,i,o,k,g,p) t i;
25   CUSTOM_ATTRS                          /* Include all custom attributes */
26 #undef INT_ATTR
27   byte weight;
28   byte flags;
29   byte age;                             /* Document age in pseudo-logarithmic units wrt. reference time */
30   // byte rfu[1];                       /* If no custom attributes are defined */
31 };
32
33 enum card_flag {
34   CARD_FLAG_EMPTY = 1,                  /* Empty document (redirect, robot file etc.) [scanner] */
35   CARD_FLAG_ACCENTED = 2,               /* Document contains accented characters [scanner] */
36   CARD_FLAG_DUP = 4,                    /* Removed as a duplicate [merger] */
37   CARD_FLAG_MERGED = 8,                 /* Destination of a merge [merger] */
38 };
39
40 #define CARD_POS_SHIFT 5                /* Card positions are shifted this # of bytes to the right */
41
42 /* String fingerprints */
43
44 struct fingerprint {
45   byte hash[12];
46 };
47
48 void fingerprint(byte *string, struct fingerprint *fp);
49
50 static inline u32
51 fp_hash(struct fingerprint *fp)
52 {
53   return (fp->hash[0] << 24) | (fp->hash[1] << 16) | (fp->hash[2] << 8) | fp->hash[3];
54 }
55
56 /* Reading of tagged text (Unicode values, tags mapped to 0x80000000 and higher) */
57
58 #define GET_TAGGED_CHAR(p,u) do {                               \
59   u = *p;                                                       \
60   if (u >= 0xc0)                                                \
61     GET_UTF8_CHAR(p,u);                                         \
62   else if (u >= 0x80)                                           \
63     {                                                           \
64       p++;                                                      \
65       if (u >= 0xb0)                                            \
66         {                                                       \
67           if (u != 0xb0)                                        \
68             ASSERT(0);                                          \
69           u += 0x80020000;                                      \
70         }                                                       \
71       else if (u >= 0xa0)                                       \
72         {                                                       \
73           ASSERT(*p >= 0x80 && *p <= 0xbf);                     \
74           u = 0x80010000 + ((u & 0x0f) << 6) + (*p++ & 0x3f);   \
75         }                                                       \
76       else                                                      \
77         u += 0x80000000;                                        \
78     }                                                           \
79   else                                                          \
80     p++;                                                        \
81 } while (0)
82
83 /* Conversion of document age from seconds to our internal units */
84
85 static inline int
86 convert_age(sh_time_t lastmod, sh_time_t reftime)
87 {
88   sh_time_t age;
89   if (reftime < lastmod)                /* past times */
90     return -1;
91   age = (reftime - lastmod) / 3600;
92   if (age < 48)                         /* last 2 days: 1 hour resolution */
93     return age;
94   age = (age-48) / 24;
95   if (age < 64)                         /* next 64 days: 1 day resolution */
96     return 48 + age;
97   age = (age-64) / 7;
98   if (age < 135)                        /* next 135 weeks: 1 week resolution */
99     return 112 + age;
100   age = (age-135) / 52;
101   if (age < 8)                          /* next 8 years: 1 year resolution */
102     return 247 + age;
103   return 255;                           /* then just "infinite future" */
104 }