Skip to content

Commit

Permalink
Previous doc cleanup (#76)
Browse files Browse the repository at this point in the history
Co-authored-by: Alexander Gonzalez <[email protected]>
  • Loading branch information
scriptandcompile and alexfertel authored Jun 9, 2024
1 parent 7044a89 commit 817f850
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 125 deletions.
153 changes: 28 additions & 125 deletions src/bit_manipulation/basic.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,3 @@
//! This module provides basic bit manipulation operations.
//!
//! The following functions are available:
//!
//! - `get_bit`: Gets the value of a specific bit in a number.
//! - `set_bit`: Sets a specific bit in a number to 1.
//! - `clear_bit`: Sets a specific bit in a number to 0.
//! - `update_bit`: Updates a specific bit in a number based on a boolean value.
//! - `is_even`: Checks if a number is even.
//! - `is_positive`: Checks if a number is positive.
//! - `multiply_by_two`: Multiplies a number by two.
//! - `divide_by_two`: Divides a number by two.
//! - `twos_complement`: Calculates the two's complement of a number.
//! - `multiply_signed`: Multiplies two signed numbers.
//! - `multiply_unsigned`: Multiplies two unsigned numbers.
//! - `count_ones`: Counts the number of ones in a number.
//! - `bit_equivalence`: Counts the number of equal bits between two numbers.
//! - `bit_distance`: Calculates the bit distance between two numbers.
//! - `is_power_of_two`: Checks if a number is a power of two.
//! - `is_power_of_two_difference`: Checks if the number is the difference of two powers of two.
//! - `rightmost_one`: Returns the position of the rightmost one-bit in a number.
//! - `rightmost_zero`: Returns the position of the rightmost zero-bit in a number.
//!
//! For more information on each function, please refer to their individual documentation.

/// Gets specific bits from a number.
///
/// Returns the value of the bit at position `n` in `bits`.
Expand All @@ -31,17 +6,13 @@
///
/// # Arguments
///
/// `bits` - The number to extract the bit from.
/// `n` - The position of the bit to extract.
/// * `bits` - The number to extract the bit from.
/// * `n` - The position of the bit to extract.
///
/// # Returns
///
/// The value of the bit at position `n` in `bits`.
///
/// # Panic
///
/// This function will not panic.
///
/// # Examples
///
/// ```rust
Expand All @@ -65,17 +36,13 @@ pub fn get_bit(bits: i8, n: usize) -> i8 {
///
/// # Arguments
///
/// `bits` - The number to set the bit in.
/// `n` - The position of the bit to set.
/// * `bits` - The number to set the bit in.
/// * `n` - The position of the bit to set.
///
/// # Returns
///
/// The number with the bit at position `n` set to 1.
///
/// # Panic
///
/// This function will not panic.
///
/// # Examples
///
/// ```rust
Expand All @@ -99,17 +66,13 @@ pub fn set_bit(bits: i8, n: usize) -> i8 {
///
/// # Arguments
///
/// `bits` - The number to clear the bit in.
/// `n` - The position of the bit to clear.
/// * `bits` - The number to clear the bit in.
/// * `n` - The position of the bit to clear.
///
/// # Returns
///
/// The number with the bit at position `n` set to 0.
///
/// # Panic
///
/// This function will not panic.
///
/// # Examples
///
/// ```rust
Expand All @@ -132,18 +95,14 @@ pub fn clear_bit(bits: i8, n: usize) -> i8 {
///
/// # Arguments
///
/// `bits` - The number to update the bit in.
/// `n` - The position of the bit to update.
/// `set_it` - If true, the bit will be set to 1, otherwise it will be set to 0.
/// * `bits` - The number to update the bit in.
/// * `n` - The position of the bit to update.
/// * `set_it` - If true, the bit will be set to 1, otherwise it will be set to 0.
///
/// # Returns
///
/// The number with the bit at position `n` set to 1 if `set_it` is true, otherwise set to 0.
///
/// # Panic
///
/// This function will not panic.
///
/// # Examples
///
/// ```rust
Expand Down Expand Up @@ -183,16 +142,12 @@ pub fn update_bit(bits: i8, n: usize, set_it: bool) -> i8 {
///
/// # Arguments
///
/// `bits` - The number to check.
/// * `bits` - The number to check.
///
/// # Returns
///
/// True if the least significant bit of `bits` is 0, otherwise false.
///
/// # Panic
///
/// This function will not panic.
///
/// # Examples
///
/// ```rust
Expand Down Expand Up @@ -220,16 +175,12 @@ pub fn is_even(bits: i8) -> bool {
///
/// # Arguments
///
/// `bits` - The number to check.
/// * `bits` - The number to check.
///
/// # Returns
///
/// True if the most significant bit of `bits` is 0, otherwise false.
///
/// # Panic
///
/// This function will not panic.
///
/// # Examples
///
/// ```rust
Expand Down Expand Up @@ -261,17 +212,13 @@ pub fn is_positive(bits: i8) -> bool {
///
/// # Arguments
///
/// `bits` - The number to multiply.
/// * `bits` - The number to multiply.
///
/// # Returns
///
/// The result of shifting the bits of `bits` one position to the left.
///
/// # Panic
///
/// This function will not panic.
///
/// # Examples
// # Examples
///
/// ```rust
/// use rust_algorithms::bit_manipulation::multiply_by_two;
Expand All @@ -293,16 +240,12 @@ pub fn multiply_by_two(bits: i8) -> i8 {
///
/// # Arguments
///
/// `bits` - The number to divide.
/// * `bits` - The number to divide.
///
/// # Returns
///
/// The result of shifting the bits of `bits` one position to the right.
///
/// # Panic
///
/// This function will not panic.
///
/// # Examples
///
/// ```rust
Expand All @@ -325,16 +268,12 @@ pub fn divide_by_two(bits: i8) -> i8 {
///
/// # Arguments
///
/// `bits` - The number to calculate the two's complement of.
/// * `bits` - The number to calculate the two's complement of.
///
/// # Returns
///
/// The two's complement of `bits`.
///
/// # Panic
///
/// This function will not panic.
///
/// # Examples
///
/// ```rust
Expand All @@ -359,17 +298,13 @@ pub fn twos_complement(bits: i8) -> i8 {
///
/// # Arguments
///
/// `a` - The first number to multiply.
/// `b` - The second number to multiply.
/// * `a` - The first number to multiply.
/// * `b` - The second number to multiply.
///
/// # Returns
///
/// The result of multiplying `a` by `b`.
///
/// # Panic
///
/// This function will not panic.
///
/// # Examples
///
/// ```rust
Expand Down Expand Up @@ -406,17 +341,13 @@ pub fn multiply_signed(a: i8, b: i8) -> i8 {
///
/// # Arguments
///
/// `a` - The first number to multiply.
/// `b` - The second number to multiply.
/// * `a` - The first number to multiply.
/// * `b` - The second number to multiply.
///
/// # Returns
///
/// The result of multiplying `a` by `b`.
///
/// # Panic
///
/// This function will not panic.
///
/// # Examples
///
/// ```rust
Expand Down Expand Up @@ -449,16 +380,12 @@ pub fn multiply_unsigned(a: i8, b: i8) -> i8 {
///
/// # Arguments
///
/// `bits` - The number to count the ones in.
/// * `bits` - The number to count the ones in.
///
/// # Returns
///
/// The number of ones in `bits`.
///
/// # Panic
///
/// This function will not panic.
///
/// # Examples
///
/// ```rust
Expand Down Expand Up @@ -490,17 +417,13 @@ pub fn count_ones(bits: i8) -> i8 {
///
/// # Arguments
///
/// `a` - The first number to compare.
/// `b` - The second number to compare.
/// * `a` - The first number to compare.
/// * `b` - The second number to compare.
///
/// # Returns
///
/// The number of equal bits between `a` and `b`.
///
/// # Panic
///
/// This function will not panic.
///
/// # Examples
///
/// ```rust
Expand All @@ -524,17 +447,13 @@ pub fn bit_equivalence(a: i8, b: i8) -> i8 {
///
/// # Arguments
///
/// `a` - The first number to compare.
/// `b` - The second number to compare.
/// * `a` - The first number to compare.
/// * `b` - The second number to compare.
///
/// # Returns
///
/// The number of different bits between `a` and `b`.
///
/// # Panic
///
/// This function will not panic.
///
/// # Examples
///
/// ```rust
Expand Down Expand Up @@ -563,16 +482,12 @@ pub fn bit_distance(a: i8, b: i8) -> i8 {
///
/// # Arguments
///
/// `bits` - The number to check.
/// * `bits` - The number to check.
///
/// # Returns
///
/// True if `bits` is a power of two, otherwise false.
///
/// # Panic
///
/// This function will not panic.
///
/// # Examples
///
/// ```rust
Expand Down Expand Up @@ -617,16 +532,12 @@ pub fn is_power_of_two(bits: i8) -> bool {
///
/// # Arguments
///
/// `bits` - The number to check.
/// * `bits` - The number to check.
///
/// # Returns
///
/// True if `bits` is of the form `2^k - 2^j`, where `k > j`, otherwise `false`.
///
/// # Panic
///
/// This function will not panic.
///
/// # Examples
///
/// ```rust
Expand Down Expand Up @@ -655,16 +566,12 @@ pub fn is_power_of_two_difference(bits: i8) -> bool {
///
/// # Arguments
///
/// `bits` - The number to check.
/// * `bits` - The number to check.
///
/// # Returns
///
/// The position of the rightmost one-bit in `bits`.
///
/// # Panic
///
/// This function will not panic.
///
/// # Examples
///
/// ```rust
Expand All @@ -685,16 +592,12 @@ pub fn rightmost_one(bits: i8) -> i8 {
///
/// # Arguments
///
/// `bits` - The number to check.
/// * `bits` - The number to check.
///
/// # Returns
///
/// The position of the rightmost zero-bit in `bits`.
///
/// # Panic
///
/// This function will not panic.
///
/// # Examples
///
/// ```rust
Expand Down
1 change: 1 addition & 0 deletions src/bit_manipulation/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//! This module provides basic bit manipulation operations.
mod basic;

pub use self::basic::bit_distance;
Expand Down

0 comments on commit 817f850

Please sign in to comment.