C hack for storing a bit that takes 1 bit space?

后端 未结 5 1527
误落风尘
误落风尘 2021-02-05 18:14

I have a long list of numbers between 0 and 67600. Now I want to store them using an array that is 67600 elements long. An element is set to 1 if a number was in the set and it

5条回答
  •  隐瞒了意图╮
    2021-02-05 18:41

    There is in fact! std::vector has a specialization for this: http://en.cppreference.com/w/cpp/container/vector_bool

    See the doc, it stores it as efficiently as possible.

    Edit: as somebody else said, std::bitset is also available: http://en.cppreference.com/w/cpp/utility/bitset

提交回复
热议问题