Re: [PATCH] Add crc32(text) & crc32(bytea)

From: Nathan Bossart <nathandbossart(at)gmail(dot)com>
To: Aleksander Alekseev <aleksander(at)timescale(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [PATCH] Add crc32(text) & crc32(bytea)
Date: 2024-08-01 16:21:56
Message-ID: Zqu2JJ0uW-n-pljs@nathan
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

+/*
+ * Calculate CRC32 of the given data.
+ */
+static inline pg_crc32
+crc32_sz(const char *buf, int size)
+{
+ pg_crc32 crc;
+ const char *p = buf;
+
+ INIT_TRADITIONAL_CRC32(crc);
+ while (size > 0)
+ {
+ char c = (char) (*p);
+
+ COMP_TRADITIONAL_CRC32(crc, &c, 1);
+ size--;
+ p++;
+ }
+ FIN_TRADITIONAL_CRC32(crc);
+ return crc;
+}

I'm curious why we need to do this instead of only using the macros:

INIT_TRADITIONAL_CRC32(crc);
COMP_TRADITIONAL_CRC32(crc, VARDATA_ANY(in), len);
FIN_TRADITIONAL_CRC32(crc);

+ * IDENTIFICATION
+ * src/backend/utils/adt/hashfuncs.c

Perhaps these would fit into src/backend/utils/hash/pg_crc.c?

--
nathan

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Jelte Fennema-Nio 2024-08-01 16:29:19 Re: Official devcontainer config
Previous Message Junwang Zhao 2024-08-01 14:56:40 Official devcontainer config