File tree Expand file tree Collapse file tree 4 files changed +26
-26
lines changed
Expand file tree Collapse file tree 4 files changed +26
-26
lines changed Original file line number Diff line number Diff line change 3434 * [ Chacha] ( https://github.com/TheAlgorithms/Rust/blob/master/src/ciphers/chacha.rs )
3535 * [ Diffie-Hellman] ( https://github.com/TheAlgorithms/Rust/blob/master/src/ciphers/diffie_hellman.rs )
3636 * [ Hashing Traits] ( https://github.com/TheAlgorithms/Rust/blob/master/src/ciphers/hashing_traits.rs )
37- * [ Kerninghan ] ( https://github.com/TheAlgorithms/Rust/blob/master/src/ciphers/kerninghan .rs )
37+ * [ Kernighan ] ( https://github.com/TheAlgorithms/Rust/blob/master/src/ciphers/kernighan .rs )
3838 * [ Morse Code] ( https://github.com/TheAlgorithms/Rust/blob/master/src/ciphers/morse_code.rs )
3939 * [ Polybius] ( https://github.com/TheAlgorithms/Rust/blob/master/src/ciphers/polybius.rs )
4040 * [ Rail Fence] ( https://github.com/TheAlgorithms/Rust/blob/master/src/ciphers/rail_fence.rs )
Original file line number Diff line number Diff line change 1+ pub fn kernighan ( n : u32 ) -> i32 {
2+ let mut count = 0 ;
3+ let mut n = n;
4+
5+ while n > 0 {
6+ n = n & ( n - 1 ) ;
7+ count += 1 ;
8+ }
9+
10+ count
11+ }
12+
13+ #[ cfg( test) ]
14+ mod tests {
15+ use super :: * ;
16+
17+ #[ test]
18+ fn count_set_bits ( ) {
19+ assert_eq ! ( kernighan( 0b0000_0000_0000_0000_0000_0000_0000_1011 ) , 3 ) ;
20+ assert_eq ! ( kernighan( 0b0000_0000_0000_0000_0000_0000_1000_0000 ) , 1 ) ;
21+ assert_eq ! ( kernighan( 0b1111_1111_1111_1111_1111_1111_1111_1101 ) , 31 ) ;
22+ }
23+ }
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ mod caesar;
77mod chacha;
88mod diffie_hellman;
99mod hashing_traits;
10- mod kerninghan ;
10+ mod kernighan ;
1111mod morse_code;
1212mod polybius;
1313mod rail_fence;
@@ -32,7 +32,7 @@ pub use self::chacha::chacha20;
3232pub use self :: diffie_hellman:: DiffieHellman ;
3333pub use self :: hashing_traits:: Hasher ;
3434pub use self :: hashing_traits:: HMAC ;
35- pub use self :: kerninghan :: kerninghan ;
35+ pub use self :: kernighan :: kernighan ;
3636pub use self :: morse_code:: { decode, encode} ;
3737pub use self :: polybius:: { decode_ascii, encode_ascii} ;
3838pub use self :: rail_fence:: { rail_fence_decrypt, rail_fence_encrypt} ;
You can’t perform that action at this time.
0 commit comments