From 724be2dabd66e15b37cb11dcb4e4d15c881ef0ef Mon Sep 17 00:00:00 2001 From: realstealthninja Date: Sat, 27 Sep 2025 04:47:42 +0000 Subject: [PATCH] Documentation for 8541bb367440dea46d58953f6561d9dd480a5249 --- da/db8/count__of__set__bits_8cpp.html | 98 +++++++++++--------- da/db8/count__of__set__bits_8cpp.js | 2 +- da/db8/count__of__set__bits_8cpp_source.html | 94 ++++++++++--------- doxygen_crawl.html | 2 +- search/all_8.js | 2 +- search/functions_3.js | 2 +- 6 files changed, 108 insertions(+), 92 deletions(-) diff --git a/da/db8/count__of__set__bits_8cpp.html b/da/db8/count__of__set__bits_8cpp.html index 7c0c507e1..adcaf57fc 100644 --- a/da/db8/count__of__set__bits_8cpp.html +++ b/da/db8/count__of__set__bits_8cpp.html @@ -139,8 +139,8 @@ Namespaces - - + + @@ -154,8 +154,8 @@ Functions

Definition in file count_of_set_bits.cpp.

Function Documentation

- -

◆ countSetBits()

+ +

◆ countSetBits()

@@ -163,7 +163,7 @@ Functions
- +

Functions

std::uint64_t bit_manipulation::count_of_set_bits::countSetBits (std ::int64_t n)
 The main function implements set bit count.
std::uint64_t bit_manipulation::count_of_set_bits::countSetBits (std ::uint64_t n)
 The main function implements set bit count.
static void test ()
int main ()
 Main function.
std::uint64_t bit_manipulation::count_of_set_bits::countSetBits (std ::int64_t n)std ::uint64_t n)
@@ -179,21 +179,29 @@ Functions
Returns
total number of set-bits in the binary representation of number n

Definition at line 38 of file count_of_set_bits.cpp.

-
39 { // int64_t is preferred over int so that
+
39 { // uint64_t is preferred over int so that
40 // no Overflow can be there.
-
41
-
42 int count = 0; // "count" variable is used to count number of set-bits('1')
-
43 // in binary representation of number 'n'
-
44 while (n != 0) {
-
45 ++count;
-
46 n = (n & (n - 1));
-
47 }
-
48 return count;
-
49 // Why this algorithm is better than the standard one?
-
50 // Because this algorithm runs the same number of times as the number of
-
51 // set-bits in it. Means if my number is having "3" set bits, then this
-
52 // while loop will run only "3" times!!
-
53}
+
41 //It's preferred over int64_t because it Guarantees that inputs are always non-negative,
+
42 //which matches the algorithmic problem statement.
+
43 //set bit counting is conceptually defined only for non-negative numbers.
+
44 //Provides a type Safety: Using an unsigned type helps prevent accidental negative values,
+
45
+
46 std::uint64_t count = 0; // "count" variable is used to count number of set-bits('1')
+
47 // in binary representation of number 'n'
+
48 //Count is uint64_t because it Prevents theoretical overflow if someone passes very large integers.
+
49 // Behavior stays the same for all normal inputs.
+
50 // Safer for edge cases.
+
51
+
52 while (n != 0) {
+
53 ++count;
+
54 n = (n & (n - 1));
+
55 }
+
56 return count;
+
57 // Why this algorithm is better than the standard one?
+
58 // Because this algorithm runs the same number of times as the number of
+
59 // set-bits in it. Means if my number is having "3" set bits, then this
+
60 // while loop will run only "3" times!!
+
61}
@@ -215,11 +223,11 @@ Functions

Main function.

Returns
0 on exit
-

Definition at line 80 of file count_of_set_bits.cpp.

-
80 {
-
81 test(); // run self-test implementations
-
82 return 0;
-
83}
+

Definition at line 88 of file count_of_set_bits.cpp.

+
88 {
+
89 test(); // run self-test implementations
+
90 return 0;
+
91}
static void test()
Self-test implementations.
@@ -247,27 +255,27 @@ Functions
-

Definition at line 57 of file count_of_set_bits.cpp.

-
57 {
-
58 // n = 4 return 1
- -
60 // n = 6 return 2
- -
62 // n = 13 return 3
- -
64 // n = 9 return 2
- -
66 // n = 15 return 4
- -
68 // n = 25 return 3
- -
70 // n = 97 return 3
- -
72 // n = 31 return 5
- -
74 std::cout << "All test cases successfully passed!" << std::endl;
-
75}
-
std::uint64_t countSetBits(std ::int64_t n)
The main function implements set bit count.
+

Definition at line 65 of file count_of_set_bits.cpp.

+
65 {
+
66 // n = 4 return 1
+ +
68 // n = 6 return 2
+ +
70 // n = 13 return 3
+ +
72 // n = 9 return 2
+ +
74 // n = 15 return 4
+ +
76 // n = 25 return 3
+ +
78 // n = 97 return 3
+ +
80 // n = 31 return 5
+ +
82 std::cout << "All test cases successfully passed!" << std::endl;
+
83}
+
std::uint64_t countSetBits(std ::uint64_t n)
The main function implements set bit count.
diff --git a/da/db8/count__of__set__bits_8cpp.js b/da/db8/count__of__set__bits_8cpp.js index e4d9eedbb..ecaafb249 100644 --- a/da/db8/count__of__set__bits_8cpp.js +++ b/da/db8/count__of__set__bits_8cpp.js @@ -1,5 +1,5 @@ var count__of__set__bits_8cpp = [ - [ "bit_manipulation::count_of_set_bits::countSetBits", "da/db8/count__of__set__bits_8cpp.html#a86c98dc299e4db28b73e08309d977e62", null ], + [ "bit_manipulation::count_of_set_bits::countSetBits", "da/db8/count__of__set__bits_8cpp.html#aea9e56e21fc34d417d702319303a285a", null ], [ "main", "da/db8/count__of__set__bits_8cpp.html#ae66f6b31b5ad750f1fe042a706a4e3d4", null ] ]; \ No newline at end of file diff --git a/da/db8/count__of__set__bits_8cpp_source.html b/da/db8/count__of__set__bits_8cpp_source.html index 9602672c4..0655b2c52 100644 --- a/da/db8/count__of__set__bits_8cpp_source.html +++ b/da/db8/count__of__set__bits_8cpp_source.html @@ -123,53 +123,61 @@ $(function(){initNavTree('da/db8/count__of__set__bits_8cpp_source.html','../../'
25namespace bit_manipulation {
32namespace count_of_set_bits {
-
38std::uint64_t countSetBits(
-
39 std ::int64_t n) { // int64_t is preferred over int so that
+
38std::uint64_t countSetBits(
+
39 std ::uint64_t n) { // uint64_t is preferred over int so that
40 // no Overflow can be there.
-
41
-
42 int count = 0; // "count" variable is used to count number of set-bits('1')
-
43 // in binary representation of number 'n'
-
44 while (n != 0) {
-
45 ++count;
-
46 n = (n & (n - 1));
-
47 }
-
48 return count;
-
49 // Why this algorithm is better than the standard one?
-
50 // Because this algorithm runs the same number of times as the number of
-
51 // set-bits in it. Means if my number is having "3" set bits, then this
-
52 // while loop will run only "3" times!!
-
53}
+
41 //It's preferred over int64_t because it Guarantees that inputs are always non-negative,
+
42 //which matches the algorithmic problem statement.
+
43 //set bit counting is conceptually defined only for non-negative numbers.
+
44 //Provides a type Safety: Using an unsigned type helps prevent accidental negative values,
+
45
+
46 std::uint64_t count = 0; // "count" variable is used to count number of set-bits('1')
+
47 // in binary representation of number 'n'
+
48 //Count is uint64_t because it Prevents theoretical overflow if someone passes very large integers.
+
49 // Behavior stays the same for all normal inputs.
+
50 // Safer for edge cases.
+
51
+
52 while (n != 0) {
+
53 ++count;
+
54 n = (n & (n - 1));
+
55 }
+
56 return count;
+
57 // Why this algorithm is better than the standard one?
+
58 // Because this algorithm runs the same number of times as the number of
+
59 // set-bits in it. Means if my number is having "3" set bits, then this
+
60 // while loop will run only "3" times!!
+
61}
-
54} // namespace count_of_set_bits
-
55} // namespace bit_manipulation
-
56
-
57static void test() {
-
58 // n = 4 return 1
-
59 assert(bit_manipulation::count_of_set_bits::countSetBits(4) == 1);
-
60 // n = 6 return 2
-
61 assert(bit_manipulation::count_of_set_bits::countSetBits(6) == 2);
-
62 // n = 13 return 3
-
63 assert(bit_manipulation::count_of_set_bits::countSetBits(13) == 3);
-
64 // n = 9 return 2
-
65 assert(bit_manipulation::count_of_set_bits::countSetBits(9) == 2);
-
66 // n = 15 return 4
-
67 assert(bit_manipulation::count_of_set_bits::countSetBits(15) == 4);
-
68 // n = 25 return 3
-
69 assert(bit_manipulation::count_of_set_bits::countSetBits(25) == 3);
-
70 // n = 97 return 3
-
71 assert(bit_manipulation::count_of_set_bits::countSetBits(97) == 3);
-
72 // n = 31 return 5
-
73 assert(bit_manipulation::count_of_set_bits::countSetBits(31) == 5);
-
74 std::cout << "All test cases successfully passed!" << std::endl;
-
75}
-
-
80int main() {
-
81 test(); // run self-test implementations
-
82 return 0;
+
62} // namespace count_of_set_bits
+
63} // namespace bit_manipulation
+
64
+
65static void test() {
+
66 // n = 4 return 1
+ +
68 // n = 6 return 2
+ +
70 // n = 13 return 3
+ +
72 // n = 9 return 2
+ +
74 // n = 15 return 4
+ +
76 // n = 25 return 3
+ +
78 // n = 97 return 3
+ +
80 // n = 31 return 5
+ +
82 std::cout << "All test cases successfully passed!" << std::endl;
83}
+
+
88int main() {
+
89 test(); // run self-test implementations
+
90 return 0;
+
91}
-
std::uint64_t countSetBits(std ::int64_t n)
The main function implements set bit count.
-
int main()
Main function.
+
int main()
Main function.
+
std::uint64_t countSetBits(std ::uint64_t n)
The main function implements set bit count.
static void test()
Self-test implementations.
for std::string
Functions for the count sets bits implementation.
diff --git a/doxygen_crawl.html b/doxygen_crawl.html index 53a730ce5..f13ea9fe6 100644 --- a/doxygen_crawl.html +++ b/doxygen_crawl.html @@ -2255,8 +2255,8 @@ - + diff --git a/search/all_8.js b/search/all_8.js index aea5cb974..cc0eeed82 100644 --- a/search/all_8.js +++ b/search/all_8.js @@ -108,7 +108,7 @@ var searchData= ['count_5fpaths_5fdfs_105',['count_paths_dfs',['../df/dce/namespacegraph.html#af99fccdd19e8f223e8749561589a762b',1,'graph']]], ['countbitsflip_106',['countBitsFlip',['../d7/d56/count__bits__flip_8cpp.html#a2548486b6c3b80101e768562e687ef7b',1,'bit_manipulation::count_bits_flip']]], ['countinversion_107',['countInversion',['../d2/d26/count__inversions_8cpp.html#a3332498eabf6579ef059c0d0e9f4ec80',1,'sorting::inversion']]], - ['countsetbits_108',['countSetBits',['../da/db8/count__of__set__bits_8cpp.html#a86c98dc299e4db28b73e08309d977e62',1,'bit_manipulation::count_of_set_bits']]], + ['countsetbits_108',['countSetBits',['../da/db8/count__of__set__bits_8cpp.html#aea9e56e21fc34d417d702319303a285a',1,'bit_manipulation::count_of_set_bits']]], ['covenant_20code_20of_20conduct_109',['Contributor Covenant Code of Conduct',['../d3/dd7/md__c_o_d_e___o_f___c_o_n_d_u_c_t.html',1,'']]], ['cpu_20scheduling_20algorithms_110',['Cpu Scheduling Algorithms',['../d5/d88/md__d_i_r_e_c_t_o_r_y.html#autotoc_md48',1,'']]], ['create_5fhash_111',['create_hash',['../d9/d03/namespacestring__search.html#a8fb0bc932ba8b582c9f4c71338d050f8',1,'string_search']]], diff --git a/search/functions_3.js b/search/functions_3.js index ffeeb0871..6956beb4a 100644 --- a/search/functions_3.js +++ b/search/functions_3.js @@ -40,7 +40,7 @@ var searchData= ['count_5fpaths_5fdfs_37',['count_paths_dfs',['../df/dce/namespacegraph.html#af99fccdd19e8f223e8749561589a762b',1,'graph']]], ['countbitsflip_38',['countBitsFlip',['../d7/d56/count__bits__flip_8cpp.html#a2548486b6c3b80101e768562e687ef7b',1,'bit_manipulation::count_bits_flip']]], ['countinversion_39',['countInversion',['../d2/d26/count__inversions_8cpp.html#a3332498eabf6579ef059c0d0e9f4ec80',1,'sorting::inversion']]], - ['countsetbits_40',['countSetBits',['../da/db8/count__of__set__bits_8cpp.html#a86c98dc299e4db28b73e08309d977e62',1,'bit_manipulation::count_of_set_bits']]], + ['countsetbits_40',['countSetBits',['../da/db8/count__of__set__bits_8cpp.html#aea9e56e21fc34d417d702319303a285a',1,'bit_manipulation::count_of_set_bits']]], ['create_5fhash_41',['create_hash',['../d9/d03/namespacestring__search.html#a8fb0bc932ba8b582c9f4c71338d050f8',1,'string_search']]], ['create_5flist_42',['create_list',['../d1/df3/hash__search_8cpp.html#ad0831425f1389166a9518f422d0c6ec5',1,'hash_search.cpp']]], ['create_5fmatrix_43',['create_matrix',['../de/d75/qr__eigen__values_8cpp.html#a9bbf469d5525a816b0d6ca812119093d',1,'qr_eigen_values.cpp']]],