Re: popcount

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Peter Eisentraut <peter(dot)eisentraut(at)enterprisedb(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, David Fetter <david(at)fetter(dot)org>, Daniel Verite <daniel(at)manitou-mail(dot)org>, PostgreSQL Development <pgsql-hackers(at)postgresql(dot)org>, Vik Fearing <vik(dot)fearing(at)2ndquadrant(dot)com>
Subject: Re: popcount
Date: 2021-01-19 12:58:12
Message-ID: CA+Tgmoa18D-8FvtBE3-dJHDTX6A33OeAmRKa6R7+i8-E_o1G-w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Tue, Jan 19, 2021 at 3:06 AM Peter Eisentraut
<peter(dot)eisentraut(at)enterprisedb(dot)com> wrote:
> On 2021-01-18 16:34, Tom Lane wrote:
> > Peter Eisentraut <peter(dot)eisentraut(at)enterprisedb(dot)com> writes:
> >> [ assorted nits ]
> >
> > At the level of bikeshedding ... I quite dislike using the name "popcount"
> > for these functions. I'm aware that some C compilers provide primitives
> > of that name, but I wouldn't expect a SQL programmer to know that;
> > without that context the name seems pretty random and unintuitive.
> > Moreover, it invites confusion with SQL's use of "pop" to abbreviate
> > "population" in the statistical aggregates, such as var_pop().
>
> I was thinking about that too, but according to
> <https://en.wikipedia.org/wiki/Hamming_weight>, popcount is an accepted
> high-level term, with "pop" also standing for "population".

Yeah, I am not sure that it's going to be good to invent our own name
for this, although maybe. But at least I think we should make sure
there are some good comments in an easily discoverable place. Some
people seem to think every programmer in the universe should know what
things like popcount() and fls() and ffs() and stuff like that are,
but it's far from obvious and I often have to refresh my memory. Let's
make it easy for someone to figure out, if they don't know already.
Like just a comment that says "this returns the number of 1 bits in
the integer supplied as an argument" or something can save somebody a
lot of trouble.

--
Robert Haas
EDB: http://www.enterprisedb.com

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Amit Kapila 2021-01-19 12:58:42 Re: TOAST condition for column size
Previous Message Michael Paquier 2021-01-19 12:37:50 Re: Paint some PG_USED_FOR_ASSERTS_ONLY in inline functions of ilist.h and bufpage.h