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

后端 未结 6 1698
旧巷少年郎
旧巷少年郎 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:29

    A standard bitvector does not support efficient iteration over true bits - the runtime is always O(n), where n is the number of total bits, which has no dependence on k. However, there are specialized data structures like van Emde Boas trees and y-fast tries, that support iteration over the bits in time O(k lg lg n), where n is the number of bits and k is the number of true bits.

提交回复
热议问题