Skip to content

Commit 00cbbb9

Browse files
authored
Fixed typos in src/ciphers/kernighan.rs and mod.rs (#945)
* Fixed typos in src/ciphers/kernighan.rs and mod.rs * fixed typos in DICTIONARY.md * .
1 parent 269690c commit 00cbbb9

File tree

4 files changed

+26
-26
lines changed

4 files changed

+26
-26
lines changed

DIRECTORY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
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)

src/ciphers/kernighan.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
}

src/ciphers/kerninghan.rs

Lines changed: 0 additions & 23 deletions
This file was deleted.

src/ciphers/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ mod caesar;
77
mod chacha;
88
mod diffie_hellman;
99
mod hashing_traits;
10-
mod kerninghan;
10+
mod kernighan;
1111
mod morse_code;
1212
mod polybius;
1313
mod rail_fence;
@@ -32,7 +32,7 @@ pub use self::chacha::chacha20;
3232
pub use self::diffie_hellman::DiffieHellman;
3333
pub use self::hashing_traits::Hasher;
3434
pub use self::hashing_traits::HMAC;
35-
pub use self::kerninghan::kerninghan;
35+
pub use self::kernighan::kernighan;
3636
pub use self::morse_code::{decode, encode};
3737
pub use self::polybius::{decode_ascii, encode_ascii};
3838
pub use self::rail_fence::{rail_fence_decrypt, rail_fence_encrypt};

0 commit comments

Comments
 (0)