File tree Expand file tree Collapse file tree 2 files changed +6
-7
lines changed
Expand file tree Collapse file tree 2 files changed +6
-7
lines changed Original file line number Diff line number Diff line change @@ -428,20 +428,14 @@ pub fn (a BitField) == (b BitField) bool {
428428pub fn (instance BitField) pop_count () int {
429429 size := instance.size
430430 bitnslots := zbitnslots (size)
431- tail := size % slot_size
432431 mut count := 0
433- for i in 0 .. bitnslots - 1 {
432+ for i in 0 .. bitnslots {
434433 for j in 0 .. slot_size {
435434 if u32 (instance.field[i] >> u32 (j)) & u32 (1 ) == u32 (1 ) {
436435 count++
437436 }
438437 }
439438 }
440- for j in 0 .. tail {
441- if u32 (instance.field[bitnslots - 1 ] >> u32 (j)) & u32 (1 ) == u32 (1 ) {
442- count++
443- }
444- }
445439 return count
446440}
447441
Original file line number Diff line number Diff line change @@ -134,6 +134,11 @@ fn test_pop_count() {
134134 assert count0 == count1
135135}
136136
137+ fn test_pop_count2 () {
138+ b := bitfield.from_str ('011000110110110000010001000011010011011111011110101001010011011010001100001001101111111011010011' )
139+ assert b.pop_count () == 50
140+ }
141+
137142fn test_hamming () {
138143 len := 80
139144 mut count := 0
You can’t perform that action at this time.
0 commit comments