# HG changeset patch
# User dcoudert <david.coudert@inria.fr>
# Date 1376770316 7200
# Node ID 64d54ad0eca1f26e81af292d1cca0a9122422253
# Parent 995fbbf0196f8c00d0d66a64a425564a2bca0705
trac #13352  Running time improvement of the bitset_len method
diff git a/sage/misc/bitset.pxi b/sage/misc/bitset.pxi
a

b


438  438  Calculate the number of items in the set (i.e., the number of nonzero bits). 
439  439  """ 
440  440  cdef long len = 0 
441   cdef long i = bitset_first(bits) 
442   while i >= 0: 
443   len += 1 
444   i = bitset_next(bits, i + 1) 
 441  cdef long i 
 442  for i from 0 <= i < bits.limbs: 
 443  if bits.bits[i]: 
 444  len += __builtin_popcountl(bits.bits[i]) 
445  445  return len 
446  446  
447  447  cdef inline long bitset_hash(bitset_t bits): 
diff git a/sage/misc/bitset_pxd.pxi b/sage/misc/bitset_pxd.pxi
a

b


22  22  void *memcpy(void *, void *, size_t) 
23  23  int memcmp(void *, void *, size_t) 
24  24  size_t strlen(char *) 
 25  int __builtin_popcountl(unsigned long) 
25  26  
26  27  # constant literals 
27  28  int index_shift "(sizeof(unsigned long)==8 ? 6 : 5)" 