Function count

Synopsis

#include <include/EASTL/bitset.h>

size_type count() const

Description

No description yet.

Source

Lines 854-882 in include/EASTL/bitset.h. Line 330 in include/EASTL/bitset.h.

template <size_t NW, typename WordType>
inline typename BitsetBase<NW, WordType>::size_type
BitsetBase<NW, WordType>::count() const
{
    size_type n = 0;
    for(size_t i = 0; i < NW; i++)
    {
        #if defined(__GNUC__) && (((__GNUC__ * 100) + __GNUC_MINOR__) >= 304) && !defined(EA_PLATFORM_ANDROID) // GCC 3.4 or later
            #if(EA_PLATFORM_WORD_SIZE == 4)
                n += (size_type)__builtin_popcountl(mWord[i]);
            #else
                n += (size_type)__builtin_popcountll(mWord[i]);
            #endif
        #elif defined(__GNUC__) && (__GNUC__ < 3)
            n +=  BitsetCountBits(mWord[i]); // GCC 2.x compiler inexplicably blows up on the code below.
        #else
            // todo: use __popcnt16, __popcnt, __popcnt64 for msvc builds
            // https://msdn.microsoft.com/en-us/library/bb385231(v=vs.140).aspx
            for(word_type w = mWord[i]; w; w >>= 4)
                n += EASTL_BITSET_COUNT_STRING[w & 0xF];
            // Version which seems to run slower in benchmarks:
            // n +=  BitsetCountBits(mWord[i]);
        #endif
    }
    return n;
}





Add Discussion as Guest

Log in