I read this file (C: \ cygwin \ lib \ gcc \ i686-pc-cygwin \ 3.4.4 \ include \ C ++ \ bitset) on my computer.
See These
/// Returns the number of bits which are set. size_t count() const { return this->_M_do_count(); } size_t _M_do_count() const { size_t __result = 0; for (size_t __i = 0; __i < _Nw; __i++) __result += __builtin_popcountl(_M_w[__i]); return __result; }
By the way, _Nw is indicated here:
template<size_t _Nw> struct _Base_bitset
So O (n) in the gcc implementation. We conclude that the specification does not require it better than O (n). And no one in their right mind will realize it in much worse than that. Then we can safely assume that it is in the worst case O (n). Perhaps better, but you can never count on it.
Haozhun
source share