On Fri, 19 Jan 2024 at 01:07, Andy Fan <zhihuifan1...@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