PostgreSQL Source Code git master
Loading...
Searching...
No Matches
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 const char *end = buf + size;
27 static pg_locale_t locale = NULL;
28
29 if (!locale)
30 locale = pg_database_locale();
31
33 while (size > 0)
34 {
36 int srclen = pg_mblen_range(p, end);
37 size_t foldlen;
38
39 /* fold one codepoint at a time */
41 locale);
42
44
45 size -= srclen;
46 p += srclen;
47 }
49 return (unsigned int) crc;
50}
51
52#else
53
54unsigned int
55ltree_crc32_sz(const char *buf, int size)
56{
58 const char *p = buf;
59
61 while (size > 0)
62 {
64 size--;
65 p++;
66 }
68 return (unsigned int) crc;
69}
70
71#endif /* !LOWER_NODE */
unsigned int ltree_crc32_sz(const char *buf, int size)
Definition crc32.c:22
int pg_mblen_range(const char *mbstr, const char *end)
Definition mbutils.c:1084
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]
static int fb(int x)