Re: Strange Bitmapset manipulation in DiscreteKnapsack()

From: David Rowley <dgrowleyml(at)gmail(dot)com>
To: Andy Fan <zhihuifan1213(at)163(dot)com>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Strange Bitmapset manipulation in DiscreteKnapsack()
Date: 2024-01-18 21:31:33
Message-ID: CAApHDvp=yqH2NULgADr_Lm-w=NidXmT0h+-ue8tda+6G0dnBQg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, 19 Jan 2024 at 01:07, Andy Fan <zhihuifan1213(at)163(dot)com> wrote:
> I find the following code in DiscreteKnapsack is weird.
>
>
> for (i = 0; i <= max_weight; ++i)
> {
> values[i] = 0;
>
> ** memory allocation here, and the num_items bit is removed later **
>
> sets[i] = bms_make_singleton(num_items);
> }
>
>
> ** num_items bit is removed here **
> result = bms_del_member(bms_copy(sets[max_weight]), num_items);

It does not seem weird to me. If the set is going to have multiple
words then adding a member 1 higher than the highest we'll ever add
ensures the set has enough words and we don't need to repalloc to grow
the set when we bms_add_member().

David

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message David G. Johnston 2024-01-18 21:44:35 Re: ALTER ROLE documentation improvement
Previous Message Przemysław Sztoch 2024-01-18 20:49:26 Re: UUID v7