Efficient way of iterating over true bits in std::bitset?

后端 未结 6 1705
旧巷少年郎
旧巷少年郎 2020-12-14 16:29

Is there a way of iterating over a (possibly huge) std::bitset that is linear in the number of bits that are set to true? I want to prevent ha

6条回答
  •  暖寄归人
    2020-12-14 17:20

    Looping over the entire bitset and simply checking the value and storing the index if true, IS linear. You can speed that up though with a lookup table. See this code:

    http://xiangqi-engine.cvs.sourceforge.net/viewvc/xiangqi-engine/tsito2/src/Utility.cpp?revision=1.5&view=markup

提交回复
热议问题