Re: [PATCH] Add crc32(text) & crc32(bytea) - Mailing list pgsql-hackers

From Nathan Bossart
Subject Re: [PATCH] Add crc32(text) & crc32(bytea)
Date
Msg-id Zqu2JJ0uW-n-pljs@nathan
Whole thread Raw
In response to Re: [PATCH] Add crc32(text) & crc32(bytea)  (Aleksander Alekseev <aleksander@timescale.com>)
Responses Re: [PATCH] Add crc32(text) & crc32(bytea)
List 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



pgsql-hackers by date:

Previous
From: Junwang Zhao
Date:
Subject: Official devcontainer config
Next
From: Jelte Fennema-Nio
Date:
Subject: Re: Official devcontainer config