libjmmcg  release_579_6_g8cffd
A C++ library containing an eclectic mix of useful, advanced components.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
jmmcg::LIBJMMCG_VER_NAMESPACE::dyn::basic::count_setbits Struct Reference

Count the number of set bits in the input number. More...

#include <count_setbits.hpp>

Public Types

typedef unsigned long long element_type
 

Static Public Member Functions

static __attribute__ ((const)) element_type result(element_type num) noexcept(true)
 
constexpr static float efficiency () noexcept(true)
 

Detailed Description

Count the number of set bits in the input number.

Because the operator>>() is poorly defined this only works for unsigned types. This is because there may be a sign bit or two's complement representation of the negative number. Then shifting might cause the sign bit to be shifted into the number itself, possibly causing an infinite loop.

Complexity: run-time: O(n) where n is at most the number of bits used to represent the input type. Space: O(1)

Also have a look at:

Definition at line 93 of file count_setbits.hpp.

Member Typedef Documentation

◆ element_type

Member Function Documentation

◆ __attribute__()

static jmmcg::LIBJMMCG_VER_NAMESPACE::dyn::basic::count_setbits::__attribute__ ( (const)  )
inlinestaticnoexcept

A very simple loop-based implementation, with no lookups nor unrolling.

Definition at line 99 of file count_setbits.hpp.

◆ efficiency()

constexpr static float jmmcg::LIBJMMCG_VER_NAMESPACE::dyn::basic::count_setbits::efficiency ( )
inlinestaticconstexprnoexcept

Definition at line 109 of file count_setbits.hpp.


The documentation for this struct was generated from the following file: