本文整理汇总了C++中count_bits函数的典型用法代码示例。如果您正苦于以下问题:C++ count_bits函数的具体用法?C++ count_bits怎么用?C++ count_bits使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了count_bits函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: sieve_count
uint64_t sieve_count(uint64_t* s, uint64_t prime_num, uint64_t first, uint64_t last, uint64_t L, uint64_t U, uint64_t* s2)
{
/*use Legendre sieve for 2, 3, and 5 so sieve s does not have to store numbers
divisible by 2, 3, or 5*/
if (prime_num == 1) return last - (first -1);
else if (prime_num == 2) return last - last/2 - (first - 1 - (first -1)/2);
else if (prime_num == 3) return last - last/2 - last/3 + last/6 -((first - 1) - (first - 1)/2 - (first - 1)/3 + (first - 1)/6);
uint64_t a, b, c, ans;
if(first > 0) a = (first + NEXT[first % MOD])/MOD * GROUPS + POS[first % MOD];
else a = 0;
if (last > 0) b = (last + PREV[last % MOD])/MOD * GROUPS + POS[last % MOD];
else b = 0;
if (L > 1) c = (L-1 + PREV[(L-1) % MOD])/MOD * GROUPS + POS[(L-1) % MOD];
else c = 0;
if(a - c > 0 && b - c > 0) ans = count_bits(s2, a - c, b - c);
else ans = 0;
// printf("L = %lu is bit %lu U is %lu\n", L, c, U);
// printf("sieve count args: prime_num = %lu first = %lu last = %lu L = %lu, U = %lu\n",prime_num,first,last,L,U);
//printf("a = %lu b = %lu c = %lu\n",a,b,c);
// printf("start bit = %lu finish_bit = %lu\n", a-c, b-c);
printf("L = %lu\ti = %lu\twheel = %lu\ttraditional = %lu\n",L, prime_num, ans, count_bits(s, first - L, last - L));
return count_bits(s, first - L, last - L);
}
开发者ID:jfkingiii,项目名称:meissel-lehmer,代码行数:29,代码来源:S2_bit_wheel.c
示例2: inet_ptom
/* convert a netmask string (eg 255.255.255.0 or ffff:ff::) in +src+ into
* the length (24) in +dst+. Return 0 if some sort of failure, or 1 on
* success.
*/
int inet_ptom (int af, const char *src, unsigned int *dst)
{
union inX_addr addr;
if (!empty_str(src)) {
if (inet_pton (af, src, &addr) < 0) {
*dst = 0;
return 0;
}
}
if (af == AF_INET) {
*dst = count_bits(ntohl(addr.in4.s_addr));
return 1;
} else if (af == AF_INET6) {
int i, count;
for (i = 0, *dst = 0; i < 4; i++) {
count = count_bits(htonl(addr.in6.s6_addr32[i]));
*dst += count;
if (count != 32) break; /* Don't go any further if the mask has finished */
}
return 1;
} else {
*dst = 0;
return 0;
}
}
开发者ID:GalliumOS,项目名称:ubiquity,代码行数:31,代码来源:netcfg-common.c
示例3: count_bits
size_t BitMap::count() const{
size_t cnt = 0;
for(auto i = array.rbegin() ; i != array.rend() ; ++i){
if (i == array.rbegin() && bitset_size % block_size){
cnt += count_bits(*i & ((1u << bitset_size % block_size) - 1));
} else {
cnt += count_bits(*i);
}
}
return cnt;
}
开发者ID:kovalevfm,项目名称:bitset,代码行数:11,代码来源:bitmap.cpp
示例4: if
bool LoRaPHYUS915Hybrid::validate_channel_mask(uint16_t* channel_masks)
{
bool mask_state = false;
uint16_t block1 = 0;
uint16_t block2 = 0;
uint8_t index = 0;
uint16_t temp_channel_masks[US915_HYBRID_CHANNEL_MASK_SIZE];
// Copy channels mask to not change the input
for (uint8_t i = 0; i < 4; i++) {
temp_channel_masks[i] = channel_masks[i];
}
for(uint8_t i = 0; i < 4; i++) {
block1 = temp_channel_masks[i] & 0x00FF;
block2 = temp_channel_masks[i] & 0xFF00;
if (count_bits(block1, 16) > 1) {
temp_channel_masks[i] &= block1;
temp_channel_masks[4] = 1 << ( i * 2 );
mask_state = true;
index = i;
break;
} else if( count_bits( block2, 16 ) > 1 ) {
temp_channel_masks[i] &= block2;
temp_channel_masks[4] = 1 << ( i * 2 + 1 );
mask_state = true;
index = i;
break;
}
}
// Do change the channel mask, if we have found a valid block.
if (mask_state == true) {
// Copy channels mask back again
for (uint8_t i = 0; i < 4; i++) {
channel_masks[i] = temp_channel_masks[i];
if (i != index) {
channel_masks[i] = 0;
}
}
channel_masks[4] = temp_channel_masks[4];
}
return mask_state;
}
开发者ID:hasnainvirk,项目名称:mbed-os,代码行数:53,代码来源:LoRaPHYUS915Hybrid.cpp
示例5: TEST
TEST(BitMatrixTest, SetReset)
{
ocgl::BitMatrix m(4, 5);
for (int i = 0; i < m.rows(); ++i)
for (int j = 0; j < m.cols(); ++j) {
EXPECT_EQ(0, count_bits(m));
m.set(i, j);
EXPECT_EQ(1, count_bits(m));
m.reset(i, j);
EXPECT_EQ(0, count_bits(m));
}
}
开发者ID:timvdm,项目名称:OpenChemicalGraphLibrary,代码行数:13,代码来源:BitMatrix.cpp
示例6: Scm_BitsCount0
int Scm_BitsCount0(const ScmBits *bits, int start, int end)
{
int sw = start / SCM_WORD_BITS;
int ew = (end-1)/ SCM_WORD_BITS;
int sb = start % SCM_WORD_BITS;
int eb = end % SCM_WORD_BITS;
if (start == end) return 0;
if (sw == ew) return count_bits(~bits[sw] & SCM_BITS_MASK(sb, eb));
u_long num = count_bits(~bits[sw] & SCM_BITS_MASK(sb, 0));
for (sw++; sw < ew; sw++) num += count_bits(~bits[sw]);
return num + (count_bits(~bits[ew] & SCM_BITS_MASK(0, eb)));
}
开发者ID:Z-Shang,项目名称:Gauche,代码行数:14,代码来源:bits.c
示例7: main
int main()
{
std::cout << count_bits(8) << std::endl;
std::cout << count_bits(15) << std::endl;
std::cout << count_bits(10) << std::endl;
std::cout << count_bits(100) << std::endl;
std::cout << count_bits(127) << std::endl;
std::cout << std::bitset<4 * 8>(182927) << std::endl;
std::cout << std::bitset<4 * 8>(reverse(182927)) << std::endl;
int a = 23;
int b = 22;
std::cout << a << " + " << b << ": " << add(a, b) << std::endl;
}
开发者ID:mzimbres,项目名称:rtcpp,代码行数:15,代码来源:interview_bits.cpp
示例8: Decode
bool OMXPlayerVideo::Decode(OMXPacket *pkt)
{
if(!pkt)
return false;
// some packed bitstream AVI files set almost all pts values to DVD_NOPTS_VALUE, but have a scattering of real pts values.
// the valid pts values match the dts values.
// if a stream has had more than 4 valid pts values in the last 16, the use UNKNOWN, otherwise use dts
m_history_valid_pts = (m_history_valid_pts << 1) | (pkt->pts != DVD_NOPTS_VALUE);
double pts = pkt->pts;
if(pkt->pts == DVD_NOPTS_VALUE && (m_iCurrentPts == DVD_NOPTS_VALUE || count_bits(m_history_valid_pts & 0xffff) < 4))
pts = pkt->dts;
if (pts != DVD_NOPTS_VALUE)
pts += m_iVideoDelay;
if(pts != DVD_NOPTS_VALUE)
m_iCurrentPts = pts;
while((int) m_decoder->GetFreeSpace() < pkt->size)
{
OMXClock::OMXSleep(10);
if(m_flush_requested) return true;
}
CLog::Log(LOGINFO, "CDVDPlayerVideo::Decode dts:%.0f pts:%.0f cur:%.0f, size:%d", pkt->dts, pkt->pts, m_iCurrentPts, pkt->size);
m_decoder->Decode(pkt->data, pkt->size, pts);
return true;
}
开发者ID:ekapujiw2002,项目名称:pi,代码行数:29,代码来源:OMXPlayerVideo.cpp
示例9: check_line_hdr
/*
***************************************************************************
* Determine if a stat header line has to be displayed.
*
* RETURNS:
* TRUE if a header line has to be displayed.
***************************************************************************
*/
int check_line_hdr(void)
{
int i, rc = FALSE;
/* Get number of options entered on the command line */
if (get_activity_nr(act, AO_SELECTED, COUNT_OUTPUTS) > 1)
return TRUE;
for (i = 0; i < NR_ACT; i++) {
if (IS_SELECTED(act[i]->options)) {
/* Special processing for activities using a bitmap */
if (act[i]->bitmap) {
if (count_bits(act[i]->bitmap->b_array,
BITMAP_SIZE(act[i]->bitmap->b_size)) > 1) {
rc = TRUE;
}
}
else if (act[i]->nr > 1) {
rc = TRUE;
}
/* Stop now since we have only one selected activity */
break;
}
}
return rc;
}
开发者ID:Embedded-linux,项目名称:sysstat,代码行数:35,代码来源:sar.c
示例10: main
void main()
{
/* Write a case statement to select which hack it is
* */
count_bits();
return;
}
开发者ID:ApoorvaKarnik,项目名称:fuzzyCode,代码行数:7,代码来源:bitHacks.c
示例11: get_random_number_from_candidate_list_and_remove_it
unsigned int get_random_number_from_candidate_list_and_remove_it(CandidateListType *list, unsigned int index)
{
unsigned int randomIndex; // index of the selected candidate in the list
unsigned int count; // number of remaining candidates in the list
unsigned int candidate; // selected candidate
assert(NULL != list && index < (NROWS*NCOLS) && "get_random_number_from_candidate_list_and_remove_it(): Bad input");
// 1. count how many remaining numbers we have (how many set bits)
count = count_bits(list[index]);
assert(count > 0 && "get_random_number_from_candidate_list_and_remove_it(): No candidate remaining");
// 2. generate random index (will be 0 when count is 1)
randomIndex = (unsigned int) arc4random() % count;
// 3. get the corresponding candidate
for (candidate = 0; candidate < NCOLS; ++candidate)
{
if (BIT_CHECK(list[index],candidate)) {
if (0 == randomIndex) {
break;
}
else {
--randomIndex;
}
}
}
assert(0 <= candidate && candidate < NCOLS && 0 == randomIndex && "get_random_number_from_candidate_list_and_remove_it(): Bad index");
// 4. remove it from the candidate list
BIT_CLEAR(list[index],candidate);
return (unsigned int)(candidate+1); // Indices start at 0 but values start at 1, need to increase
}
开发者ID:julien-l,项目名称:mysudoku,代码行数:34,代码来源:SudokuAlgorithms.c
示例12: scan_operands
//done
void scan_operands (operands_t operands) {
printf("scan_operands() for %s\n", lc3_get_format_name(operands));
int operandCount = 0;
int numOperands = count_bits(operands);
int errorCount = numErrors;
for (operand_t op = FMT_R1; op <= FMT_STR; op <<= 1) {
//if the bits are set
//printf(" ");
if(op & operands){
//create a token
char* token = next_token();
//get the operand of that token
if(token != NULL){
get_operand(op,token);
//if errorocunt is not equal return
if (errorCount != numErrors)
return; // error, so skip processing remainder of line
//inc operand count
operandCount++;
//if the count is less then the operands
if(operandCount < numOperands){
//get comma or error
get_comma_or_error();
}
//check errorcount again
if (errorCount != numErrors)
return; // error, so skip processing remainder of line
}
}
}
}
开发者ID:davedennis,项目名称:LC3-Assembler,代码行数:34,代码来源:assembler.c
示例13: VBR_quantize_granule
static int
VBR_quantize_granule(lame_internal_flags * gfc, gr_info * cod_info, FLOAT8 * xr34, int gr, int ch)
{
int status;
/* encode scalefacs */
if (gfc->is_mpeg1)
status = scale_bitcount(&cod_info->scalefac, cod_info);
else
status = scale_bitcount_lsf(gfc, &cod_info->scalefac, cod_info);
if (status != 0) {
return -1;
}
/* quantize xr34 */
cod_info->part2_3_length = count_bits(gfc, cod_info->l3_enc, xr34, cod_info);
if (cod_info->part2_3_length >= LARGE_BITS)
return -2;
cod_info->part2_3_length += cod_info->part2_length;
if (gfc->use_best_huffman == 1) {
best_huffman_divide(gfc, cod_info);
}
return 0;
}
开发者ID:TravisKraatz,项目名称:cinelerra,代码行数:27,代码来源:vbrquantize.c
示例14: unsigned_size
/* get size as unsigned char string */
static unsigned long unsigned_size(void *a)
{
unsigned long t;
LTC_ARGCHK(a != NULL);
t = count_bits(a);
if (mpa_cmp_short((const mpanum)a, 0) == 0) return 0;
return (t>>3) + ((t&7)?1:0);
}
开发者ID:MrTomasz,项目名称:optee_os,代码行数:9,代码来源:mpa_desc.c
示例15: create_food
void create_food(ULONG f)
{
ULONG i;
SLONG temp_segment;
UWORD orig_x, x, y;
UWORD form;
if (f < MAX_FOODS)
{
form = 0;
while (!form)
form = (UWORD) ((rand()&rand())&0xffff);
foods[f].Form = form;
foods[f].Size = count_bits(form);
foods[f].Effect = choose_effect();
foods[f].Colour = food_colours[foods[f].Effect];
foods[f].Timer = 2000;
temp_segment = get_a_segment();
if (temp_segment == -1)
return;
if (assign_a_food_position(temp_segment,form))
{
put_a_segment(temp_segment);
return;
}
orig_x = x = segs[temp_segment].X;
y = segs[temp_segment].Y;
put_a_segment(temp_segment);
for (i=0; i<16; i++)
{
if (form & 1)
{
temp_segment = get_a_segment();
if (temp_segment != -1)
{
foods[f].Size++;
segs[temp_segment].Next = foods[f].Head;
segs[temp_segment].Colour = foods[f].Colour;
segs[temp_segment].X = x;
segs[temp_segment].Y = y;
foods[f].Head = temp_segment;
}
else
return;
}
x += BLOB_SIZE;
if (x - orig_x == BLOB_SIZE*4)
{
x = orig_x;
y += BLOB_SIZE;
}
form >>= 1;
}
}
开发者ID:elbeno,项目名称:snakes,代码行数:56,代码来源:food.c
示例16: bitset_count
/**
* Number of bits in the set (as opposed to the total size of the set)
*/
int bitset_count(bitset *b)
{
unsigned int i;
int count = 0;
for (i = 0; i < b->bs_size; i++)
count += count_bits(b->bs_bits[i]);
return count;
}
开发者ID:SUSE,项目名称:accelio,代码行数:13,代码来源:bitset.c
示例17: VBR_noise_shaping
int
VBR_noise_shaping(lame_internal_flags * gfc, const FLOAT8 * xr34orig, int minbits, int maxbits,
const III_psy_xmin * l3_xmin, int gr, int ch)
{
FLOAT8 xr34[576];
int ret, bits, huffbits;
gr_info *cod_info = &gfc->l3_side.tt[gr][ch];
switch (cod_info->block_type) {
default:
ret = long_block_shaping(gfc, xr34orig, xr34, minbits, maxbits, l3_xmin, gr, ch);
break;
case SHORT_TYPE:
ret = short_block_shaping(gfc, xr34orig, xr34, minbits, maxbits, l3_xmin, gr, ch);
break;
}
if (ret == -1) /* Houston, we have a problem */
return -1;
if (cod_info->part2_3_length < minbits) {
huffbits = minbits - cod_info->part2_length;
bits = bin_search_StepSize(gfc, cod_info, huffbits, gfc->OldValue[ch], xr34);
gfc->OldValue[ch] = cod_info->global_gain;
cod_info->part2_3_length = bits + cod_info->part2_length;
if (gfc->use_best_huffman == 1) {
best_huffman_divide(gfc, cod_info);
}
}
if (cod_info->part2_3_length > maxbits) {
huffbits = maxbits - cod_info->part2_length;
if (huffbits < 0)
huffbits = 0;
bits = bin_search_StepSize(gfc, cod_info, huffbits, gfc->OldValue[ch], xr34);
gfc->OldValue[ch] = cod_info->global_gain;
while (bits > huffbits) {
++cod_info->global_gain;
bits = count_bits(gfc, cod_info->l3_enc, xr34, cod_info);
}
cod_info->part2_3_length = bits;
if (bits >= LARGE_BITS) /* Houston, we have a problem */
return -2;
cod_info->part2_3_length += cod_info->part2_length;
if (gfc->use_best_huffman == 1) {
best_huffman_divide(gfc, cod_info);
}
}
if (cod_info->part2_length >= LARGE_BITS) /* Houston, we have a problem */
return -2;
assert(cod_info->global_gain < 256);
return 0;
}
开发者ID:TravisKraatz,项目名称:cinelerra,代码行数:55,代码来源:vbrquantize.c
示例18: bin_search_StepSize
static int
bin_search_StepSize(lame_internal_flags * const gfc, gr_info * const cod_info,
const int desired_rate, const int start, const FLOAT8 xrpow[576])
{
int nBits;
int CurrentStep;
int flag_GoneOver = 0;
int StepSize = start;
binsearchDirection_t Direction = BINSEARCH_NONE;
assert(gfc->CurrentStep);
CurrentStep = gfc->CurrentStep;
do {
cod_info->global_gain = StepSize;
nBits = count_bits(gfc, cod_info->l3_enc, xrpow, cod_info);
if (CurrentStep == 1)
break; /* nothing to adjust anymore */
if (flag_GoneOver)
CurrentStep /= 2;
if (nBits > desired_rate) {
/* increase Quantize_StepSize */
if (Direction == BINSEARCH_DOWN && !flag_GoneOver) {
flag_GoneOver = 1;
CurrentStep /= 2; /* late adjust */
}
Direction = BINSEARCH_UP;
StepSize += CurrentStep;
if (StepSize > 255)
break;
}
else if (nBits < desired_rate) {
/* decrease Quantize_StepSize */
if (Direction == BINSEARCH_UP && !flag_GoneOver) {
flag_GoneOver = 1;
CurrentStep /= 2; /* late adjust */
}
Direction = BINSEARCH_DOWN;
StepSize -= CurrentStep;
if (StepSize < 0)
break;
}
else
break; /* nBits == desired_rate;; most unlikely to happen. */
} while (1); /* For-ever, break is adjusted. */
CurrentStep = start - StepSize;
gfc->CurrentStep = CurrentStep / 4 != 0 ? 4 : 2;
return nBits;
}
开发者ID:TravisKraatz,项目名称:cinelerra,代码行数:55,代码来源:vbrquantize.c
示例19: count_bits
constexpr
inline
size_t
count_bits( T val, size_t count= 0 ) noexcept
{
return
( val == T(0) )
? count
: count_bits( T(val & T( val - T(1) )), // clears lowest set bit
count + 1 );
}
开发者ID:ClaasBontus,项目名称:bitset2,代码行数:11,代码来源:count_bits.hpp
示例20: count_bits
static size_t
count_bits (uint64_t bitmap)
{
size_t c;
if (bitmap == 0)
return 0;
c = bitmap & 1 ? 1 : 0;
bitmap >>= 1;
return c + count_bits (bitmap);
}
开发者ID:limohua,项目名称:libguestfs,代码行数:12,代码来源:md.c
注:本文中的count_bits函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论