Skip to content

Commit 817f850

Browse files
Previous doc cleanup (#76)
Co-authored-by: Alexander Gonzalez <[email protected]>
1 parent 7044a89 commit 817f850

File tree

2 files changed

+29
-125
lines changed

2 files changed

+29
-125
lines changed

src/bit_manipulation/basic.rs

+28-125
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,3 @@
1-
//! This module provides basic bit manipulation operations.
2-
//!
3-
//! The following functions are available:
4-
//!
5-
//! - `get_bit`: Gets the value of a specific bit in a number.
6-
//! - `set_bit`: Sets a specific bit in a number to 1.
7-
//! - `clear_bit`: Sets a specific bit in a number to 0.
8-
//! - `update_bit`: Updates a specific bit in a number based on a boolean value.
9-
//! - `is_even`: Checks if a number is even.
10-
//! - `is_positive`: Checks if a number is positive.
11-
//! - `multiply_by_two`: Multiplies a number by two.
12-
//! - `divide_by_two`: Divides a number by two.
13-
//! - `twos_complement`: Calculates the two's complement of a number.
14-
//! - `multiply_signed`: Multiplies two signed numbers.
15-
//! - `multiply_unsigned`: Multiplies two unsigned numbers.
16-
//! - `count_ones`: Counts the number of ones in a number.
17-
//! - `bit_equivalence`: Counts the number of equal bits between two numbers.
18-
//! - `bit_distance`: Calculates the bit distance between two numbers.
19-
//! - `is_power_of_two`: Checks if a number is a power of two.
20-
//! - `is_power_of_two_difference`: Checks if the number is the difference of two powers of two.
21-
//! - `rightmost_one`: Returns the position of the rightmost one-bit in a number.
22-
//! - `rightmost_zero`: Returns the position of the rightmost zero-bit in a number.
23-
//!
24-
//! For more information on each function, please refer to their individual documentation.
25-
261
/// Gets specific bits from a number.
272
///
283
/// Returns the value of the bit at position `n` in `bits`.
@@ -31,17 +6,13 @@
316
///
327
/// # Arguments
338
///
34-
/// `bits` - The number to extract the bit from.
35-
/// `n` - The position of the bit to extract.
9+
/// * `bits` - The number to extract the bit from.
10+
/// * `n` - The position of the bit to extract.
3611
///
3712
/// # Returns
3813
///
3914
/// The value of the bit at position `n` in `bits`.
4015
///
41-
/// # Panic
42-
///
43-
/// This function will not panic.
44-
///
4516
/// # Examples
4617
///
4718
/// ```rust
@@ -65,17 +36,13 @@ pub fn get_bit(bits: i8, n: usize) -> i8 {
6536
///
6637
/// # Arguments
6738
///
68-
/// `bits` - The number to set the bit in.
69-
/// `n` - The position of the bit to set.
39+
/// * `bits` - The number to set the bit in.
40+
/// * `n` - The position of the bit to set.
7041
///
7142
/// # Returns
7243
///
7344
/// The number with the bit at position `n` set to 1.
7445
///
75-
/// # Panic
76-
///
77-
/// This function will not panic.
78-
///
7946
/// # Examples
8047
///
8148
/// ```rust
@@ -99,17 +66,13 @@ pub fn set_bit(bits: i8, n: usize) -> i8 {
9966
///
10067
/// # Arguments
10168
///
102-
/// `bits` - The number to clear the bit in.
103-
/// `n` - The position of the bit to clear.
69+
/// * `bits` - The number to clear the bit in.
70+
/// * `n` - The position of the bit to clear.
10471
///
10572
/// # Returns
10673
///
10774
/// The number with the bit at position `n` set to 0.
10875
///
109-
/// # Panic
110-
///
111-
/// This function will not panic.
112-
///
11376
/// # Examples
11477
///
11578
/// ```rust
@@ -132,18 +95,14 @@ pub fn clear_bit(bits: i8, n: usize) -> i8 {
13295
///
13396
/// # Arguments
13497
///
135-
/// `bits` - The number to update the bit in.
136-
/// `n` - The position of the bit to update.
137-
/// `set_it` - If true, the bit will be set to 1, otherwise it will be set to 0.
98+
/// * `bits` - The number to update the bit in.
99+
/// * `n` - The position of the bit to update.
100+
/// * `set_it` - If true, the bit will be set to 1, otherwise it will be set to 0.
138101
///
139102
/// # Returns
140103
///
141104
/// The number with the bit at position `n` set to 1 if `set_it` is true, otherwise set to 0.
142105
///
143-
/// # Panic
144-
///
145-
/// This function will not panic.
146-
///
147106
/// # Examples
148107
///
149108
/// ```rust
@@ -183,16 +142,12 @@ pub fn update_bit(bits: i8, n: usize, set_it: bool) -> i8 {
183142
///
184143
/// # Arguments
185144
///
186-
/// `bits` - The number to check.
145+
/// * `bits` - The number to check.
187146
///
188147
/// # Returns
189148
///
190149
/// True if the least significant bit of `bits` is 0, otherwise false.
191150
///
192-
/// # Panic
193-
///
194-
/// This function will not panic.
195-
///
196151
/// # Examples
197152
///
198153
/// ```rust
@@ -220,16 +175,12 @@ pub fn is_even(bits: i8) -> bool {
220175
///
221176
/// # Arguments
222177
///
223-
/// `bits` - The number to check.
178+
/// * `bits` - The number to check.
224179
///
225180
/// # Returns
226181
///
227182
/// True if the most significant bit of `bits` is 0, otherwise false.
228183
///
229-
/// # Panic
230-
///
231-
/// This function will not panic.
232-
///
233184
/// # Examples
234185
///
235186
/// ```rust
@@ -261,17 +212,13 @@ pub fn is_positive(bits: i8) -> bool {
261212
///
262213
/// # Arguments
263214
///
264-
/// `bits` - The number to multiply.
215+
/// * `bits` - The number to multiply.
265216
///
266217
/// # Returns
267218
///
268219
/// The result of shifting the bits of `bits` one position to the left.
269220
///
270-
/// # Panic
271-
///
272-
/// This function will not panic.
273-
///
274-
/// # Examples
221+
// # Examples
275222
///
276223
/// ```rust
277224
/// use rust_algorithms::bit_manipulation::multiply_by_two;
@@ -293,16 +240,12 @@ pub fn multiply_by_two(bits: i8) -> i8 {
293240
///
294241
/// # Arguments
295242
///
296-
/// `bits` - The number to divide.
243+
/// * `bits` - The number to divide.
297244
///
298245
/// # Returns
299246
///
300247
/// The result of shifting the bits of `bits` one position to the right.
301248
///
302-
/// # Panic
303-
///
304-
/// This function will not panic.
305-
///
306249
/// # Examples
307250
///
308251
/// ```rust
@@ -325,16 +268,12 @@ pub fn divide_by_two(bits: i8) -> i8 {
325268
///
326269
/// # Arguments
327270
///
328-
/// `bits` - The number to calculate the two's complement of.
271+
/// * `bits` - The number to calculate the two's complement of.
329272
///
330273
/// # Returns
331274
///
332275
/// The two's complement of `bits`.
333276
///
334-
/// # Panic
335-
///
336-
/// This function will not panic.
337-
///
338277
/// # Examples
339278
///
340279
/// ```rust
@@ -359,17 +298,13 @@ pub fn twos_complement(bits: i8) -> i8 {
359298
///
360299
/// # Arguments
361300
///
362-
/// `a` - The first number to multiply.
363-
/// `b` - The second number to multiply.
301+
/// * `a` - The first number to multiply.
302+
/// * `b` - The second number to multiply.
364303
///
365304
/// # Returns
366305
///
367306
/// The result of multiplying `a` by `b`.
368307
///
369-
/// # Panic
370-
///
371-
/// This function will not panic.
372-
///
373308
/// # Examples
374309
///
375310
/// ```rust
@@ -406,17 +341,13 @@ pub fn multiply_signed(a: i8, b: i8) -> i8 {
406341
///
407342
/// # Arguments
408343
///
409-
/// `a` - The first number to multiply.
410-
/// `b` - The second number to multiply.
344+
/// * `a` - The first number to multiply.
345+
/// * `b` - The second number to multiply.
411346
///
412347
/// # Returns
413348
///
414349
/// The result of multiplying `a` by `b`.
415350
///
416-
/// # Panic
417-
///
418-
/// This function will not panic.
419-
///
420351
/// # Examples
421352
///
422353
/// ```rust
@@ -449,16 +380,12 @@ pub fn multiply_unsigned(a: i8, b: i8) -> i8 {
449380
///
450381
/// # Arguments
451382
///
452-
/// `bits` - The number to count the ones in.
383+
/// * `bits` - The number to count the ones in.
453384
///
454385
/// # Returns
455386
///
456387
/// The number of ones in `bits`.
457388
///
458-
/// # Panic
459-
///
460-
/// This function will not panic.
461-
///
462389
/// # Examples
463390
///
464391
/// ```rust
@@ -490,17 +417,13 @@ pub fn count_ones(bits: i8) -> i8 {
490417
///
491418
/// # Arguments
492419
///
493-
/// `a` - The first number to compare.
494-
/// `b` - The second number to compare.
420+
/// * `a` - The first number to compare.
421+
/// * `b` - The second number to compare.
495422
///
496423
/// # Returns
497424
///
498425
/// The number of equal bits between `a` and `b`.
499426
///
500-
/// # Panic
501-
///
502-
/// This function will not panic.
503-
///
504427
/// # Examples
505428
///
506429
/// ```rust
@@ -524,17 +447,13 @@ pub fn bit_equivalence(a: i8, b: i8) -> i8 {
524447
///
525448
/// # Arguments
526449
///
527-
/// `a` - The first number to compare.
528-
/// `b` - The second number to compare.
450+
/// * `a` - The first number to compare.
451+
/// * `b` - The second number to compare.
529452
///
530453
/// # Returns
531454
///
532455
/// The number of different bits between `a` and `b`.
533456
///
534-
/// # Panic
535-
///
536-
/// This function will not panic.
537-
///
538457
/// # Examples
539458
///
540459
/// ```rust
@@ -563,16 +482,12 @@ pub fn bit_distance(a: i8, b: i8) -> i8 {
563482
///
564483
/// # Arguments
565484
///
566-
/// `bits` - The number to check.
485+
/// * `bits` - The number to check.
567486
///
568487
/// # Returns
569488
///
570489
/// True if `bits` is a power of two, otherwise false.
571490
///
572-
/// # Panic
573-
///
574-
/// This function will not panic.
575-
///
576491
/// # Examples
577492
///
578493
/// ```rust
@@ -617,16 +532,12 @@ pub fn is_power_of_two(bits: i8) -> bool {
617532
///
618533
/// # Arguments
619534
///
620-
/// `bits` - The number to check.
535+
/// * `bits` - The number to check.
621536
///
622537
/// # Returns
623538
///
624539
/// True if `bits` is of the form `2^k - 2^j`, where `k > j`, otherwise `false`.
625540
///
626-
/// # Panic
627-
///
628-
/// This function will not panic.
629-
///
630541
/// # Examples
631542
///
632543
/// ```rust
@@ -655,16 +566,12 @@ pub fn is_power_of_two_difference(bits: i8) -> bool {
655566
///
656567
/// # Arguments
657568
///
658-
/// `bits` - The number to check.
569+
/// * `bits` - The number to check.
659570
///
660571
/// # Returns
661572
///
662573
/// The position of the rightmost one-bit in `bits`.
663574
///
664-
/// # Panic
665-
///
666-
/// This function will not panic.
667-
///
668575
/// # Examples
669576
///
670577
/// ```rust
@@ -685,16 +592,12 @@ pub fn rightmost_one(bits: i8) -> i8 {
685592
///
686593
/// # Arguments
687594
///
688-
/// `bits` - The number to check.
595+
/// * `bits` - The number to check.
689596
///
690597
/// # Returns
691598
///
692599
/// The position of the rightmost zero-bit in `bits`.
693600
///
694-
/// # Panic
695-
///
696-
/// This function will not panic.
697-
///
698601
/// # Examples
699602
///
700603
/// ```rust

src/bit_manipulation/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//! This module provides basic bit manipulation operations.
12
mod basic;
23

34
pub use self::basic::bit_distance;

0 commit comments

Comments
 (0)