PostgreSQL Source Code git master
crc32.c
Go to the documentation of this file.
1/* contrib/ltree/crc32.c */
2
3/*
4 * Implements CRC-32, as used in ltree.
5 *
6 * Note that the CRC is used in the on-disk format of GiST indexes, so we
7 * must stay backwards-compatible!
8 */
9
10#include "postgres.h"
11#include "ltree.h"
12
13#include "crc32.h"
14#include "utils/pg_crc.h"
15#ifdef LOWER_NODE
16#include "utils/pg_locale.h"
17#endif
18
19#ifdef LOWER_NODE
20
21unsigned int
22ltree_crc32_sz(const char *buf, int size)
23{
25 const char *p = buf;
26 static pg_locale_t locale = NULL;
27
28 if (!locale)
30
32 while (size > 0)
33 {
34 char foldstr[UNICODE_CASEMAP_BUFSZ];
35 int srclen = pg_mblen(p);
36 size_t foldlen;
37
38 /* fold one codepoint at a time */
39 foldlen = pg_strfold(foldstr, UNICODE_CASEMAP_BUFSZ, p, srclen,
40 locale);
41
42 COMP_TRADITIONAL_CRC32(crc, foldstr, foldlen);
43
44 size -= srclen;
45 p += srclen;
46 }
48 return (unsigned int) crc;
49}
50
51#else
52
53unsigned int
54ltree_crc32_sz(const char *buf, int size)
55{
57 const char *p = buf;
58
60 while (size > 0)
61 {
63 size--;
64 p++;
65 }
67 return (unsigned int) crc;
68}
69
70#endif /* !LOWER_NODE */
unsigned int ltree_crc32_sz(const char *buf, int size)
Definition: crc32.c:22
static char * locale
Definition: initdb.c:140
int pg_mblen(const char *mbstr)
Definition: mbutils.c:1026
return crc
uint32 pg_crc32
Definition: pg_crc.h:37
#define FIN_TRADITIONAL_CRC32(crc)
Definition: pg_crc.h:47
#define INIT_TRADITIONAL_CRC32(crc)
Definition: pg_crc.h:46
#define COMP_TRADITIONAL_CRC32(crc, data, len)
Definition: pg_crc.h:48
size_t pg_strfold(char *dst, size_t dstsize, const char *src, ssize_t srclen, pg_locale_t locale)
Definition: pg_locale.c:1348
pg_locale_t pg_database_locale(void)
Definition: pg_locale.c:1175
#define UNICODE_CASEMAP_BUFSZ
Definition: pg_locale.h:32
static char buf[DEFAULT_XLOG_SEG_SIZE]
Definition: pg_test_fsync.c:71