Use a safer outfuncs/readfuncs representation for BitStrings.
[pgsql.git] / contrib / ltree / crc32.c
blob134f46a805e569a0ed991aad4460a9577429375c
1 /* contrib/ltree/crc32.c */
3 /*
4 * Implements CRC-32, as used in ltree.
6 * Note that the CRC is used in the on-disk format of GiST indexes, so we
7 * must stay backwards-compatible!
8 */
10 #include "postgres.h"
11 #include "ltree.h"
13 #ifdef LOWER_NODE
14 #include <ctype.h>
15 #define TOLOWER(x) tolower((unsigned char) (x))
16 #else
17 #define TOLOWER(x) (x)
18 #endif
20 #include "crc32.h"
21 #include "utils/pg_crc.h"
23 unsigned int
24 ltree_crc32_sz(const char *buf, int size)
26 pg_crc32 crc;
27 const char *p = buf;
29 INIT_TRADITIONAL_CRC32(crc);
30 while (size > 0)
32 char c = (char) TOLOWER(*p);
34 COMP_TRADITIONAL_CRC32(crc, &c, 1);
35 size--;
36 p++;
38 FIN_TRADITIONAL_CRC32(crc);
39 return (unsigned int) crc;