Re: Strange Bitmapset manipulation in DiscreteKnapsack()
От | David Rowley |
---|---|
Тема | Re: Strange Bitmapset manipulation in DiscreteKnapsack() |
Дата | |
Msg-id | CAApHDvp=yqH2NULgADr_Lm-w=NidXmT0h+-ue8tda+6G0dnBQg@mail.gmail.com обсуждение исходный текст |
Ответ на | Re: Strange Bitmapset manipulation in DiscreteKnapsack() (Andy Fan <zhihuifan1213@163.com>) |
Ответы |
Re: Strange Bitmapset manipulation in DiscreteKnapsack()
|
Список | pgsql-hackers |
On Fri, 19 Jan 2024 at 01:07, Andy Fan <zhihuifan1213@163.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
В списке pgsql-hackers по дате отправления: