Re: Strange Bitmapset manipulation in DiscreteKnapsack()

From: Andy Fan <zhihuifan1213(at)163(dot)com>
To: David Rowley <dgrowleyml(at)gmail(dot)com>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Strange Bitmapset manipulation in DiscreteKnapsack()
Date: 2024-01-19 03:01:03
Message-ID: 875xzqxbv5.fsf@163.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


David Rowley <dgrowleyml(at)gmail(dot)com> writes:

> 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().

Hmm, I missed this part, thanks for the explaination. If bitset feature
can get in someday, the future user case like this can use bitset
directly to avoid this trick method.

--
Best Regards
Andy Fan

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Amit Langote 2024-01-19 03:09:49 Re: remaining sql/json patches
Previous Message Lukas Fittl 2024-01-19 02:58:40 Re: UUID v7