diff --git a/d1/d9e/prefix__sum__array_8cpp.html b/d1/d9e/prefix__sum__array_8cpp.html
index 8c86818a2..152c3a324 100644
--- a/d1/d9e/prefix__sum__array_8cpp.html
+++ b/d1/d9e/prefix__sum__array_8cpp.html
@@ -139,16 +139,18 @@ Namespaces
Prefix Sum Array data structure implementation.
@@ -165,8 +167,8 @@ std::vector< int64_t >
Definition in file prefix_sum_array.cpp.
-
-◆ build()
+
+◆ build()
@@ -174,7 +176,7 @@ std::vector< int64_t > |
|
| void range_queries::prefix_sum_array::build |
( |
- std::vector< int64_t > | original_array | ) |
+ const std::vector< int64_t > & | original_array | ) |
|
@@ -190,11 +192,13 @@ std::vector< int64_t >
- Returns
- void
Definition at line 41 of file prefix_sum_array.cpp.
- 41 {
- 42 for (int i = 1; i <= static_cast<int>(original_array.size()); i++) {
- 43 PSA.push_back(PSA[i - 1] + original_array[i]);
- 44 }
- 45}
+ 41 {
+ 42 PSA.clear();
+ 43 PSA.push_back(0);
+ 44 for (std::size_t i = 1; i < original_array.size(); ++i) {
+ 45 PSA.push_back(PSA.back() + original_array[i]);
+ 46 }
+ 47}
@@ -216,12 +220,12 @@ std::vector< int64_t > |
Main function.
- Returns
- 0 on exit
-Definition at line 80 of file prefix_sum_array.cpp.
- 80 {
-
- 82 return 0;
- 83}
- static void test() Self-test implementations.
+ Definition at line 82 of file prefix_sum_array.cpp.
+ 82 {
+
+ 84 return 0;
+ 85}
+ static void test() Self-test implementations.
@@ -254,8 +258,8 @@ std::vector< int64_t > |
- Returns
- sum of the range [beg, end]
-Definition at line 52 of file prefix_sum_array.cpp.
- 52{ return PSA[end] - PSA[beg - 1]; }
+ Definition at line 54 of file prefix_sum_array.cpp.
+ 54{ return PSA[end] - PSA[beg - 1]; }
@@ -285,23 +289,41 @@ std::vector< int64_t > |
Self-test implementations.
- Returns
- void
-Definition at line 61 of file prefix_sum_array.cpp.
- 61 {
- 62 std::vector<int64_t> values{0, 123, 0, 2, -2, 5,
- 63 24, 0, 23, -1, -1};
- 64
-
- 66
- 67
-
- 69 173);
-
- 71 27);
-
- 73 51);
- 74}
- int64_t query(int64_t beg, int64_t end) query function
- void build(std::vector< int64_t > original_array) function that builds the PSA
+ Definition at line 63 of file prefix_sum_array.cpp.
+ 63 {
+ 64 std::vector<int64_t> values{0, 123, 0, 2, -2, 5,
+ 65 24, 0, 23, -1, -1};
+ 66
+
+ 68
+ 69
+
+ 71 173);
+
+ 73 27);
+
+ 75 51);
+ 76}
+ int64_t query(int64_t beg, int64_t end) query function
+ void build(const std::vector< int64_t > &original_array) function that builds the PSA
+
+
+
+
+
+◆ PSA
+
+
+
+
+
+ | std::vector<int64_t> range_queries::prefix_sum_array::PSA {} |
+
+
+
diff --git a/d1/d9e/prefix__sum__array_8cpp.js b/d1/d9e/prefix__sum__array_8cpp.js
index 6b5243a15..c91314e85 100644
--- a/d1/d9e/prefix__sum__array_8cpp.js
+++ b/d1/d9e/prefix__sum__array_8cpp.js
@@ -1,6 +1,6 @@
var prefix__sum__array_8cpp =
[
- [ "range_queries::prefix_sum_array::build", "d1/d9e/prefix__sum__array_8cpp.html#ab36151479ad37d53ef9fcb60a274b1d9", null ],
+ [ "range_queries::prefix_sum_array::build", "d1/d9e/prefix__sum__array_8cpp.html#a98e118ed64ba95a8198e1a915459c177", null ],
[ "main", "d1/d9e/prefix__sum__array_8cpp.html#ae66f6b31b5ad750f1fe042a706a4e3d4", null ],
[ "range_queries::prefix_sum_array::query", "d1/d9e/prefix__sum__array_8cpp.html#a7c8fd967c36dbba5fdf9c71faed604cf", null ],
[ "test", "d1/d9e/prefix__sum__array_8cpp.html#aa8dca7b867074164d5f45b0f3851269d", null ]
diff --git a/d1/d9e/prefix__sum__array_8cpp_source.html b/d1/d9e/prefix__sum__array_8cpp_source.html
index 4fc0b8f7d..76eb2908e 100644
--- a/d1/d9e/prefix__sum__array_8cpp_source.html
+++ b/d1/d9e/prefix__sum__array_8cpp_source.html
@@ -125,50 +125,52 @@ $(function(){initNavTree('d1/d9e/prefix__sum__array_8cpp_source.html','../../','
- 34std::vector<int64_t> PSA(1, 0);
+ 34std::vector<int64_t> PSA{};
- 41void build(std::vector<int64_t> original_array) {
- 42 for ( int i = 1; i <= static_cast<int>(original_array.size()); i++) {
- 43 PSA.push_back(PSA[i - 1] + original_array[i]);
-
-
+ 41void build( const std::vector<int64_t>& original_array) {
+
+
+ 44 for (std::size_t i = 1; i < original_array.size(); ++i) {
+ 45 PSA.push_back(PSA.back() + original_array[i]);
+
+
-
- 52int64_t query(int64_t beg, int64_t end) { return PSA[end] - PSA[beg - 1]; }
-
-
-
-
-
-
- 62 std::vector<int64_t> values{0, 123, 0, 2, -2, 5,
-
-
-
-
-
-
-
-
-
-
-
-
+
+ 54int64_t query(int64_t beg, int64_t end) { return PSA[end] - PSA[beg - 1]; }
+
+
+
+
+
+
+ 64 std::vector<int64_t> values{0, 123, 0, 2, -2, 5,
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
+
+
Range sum queries using prefix-sum-array.
- int64_t query(int64_t beg, int64_t end) query function
- static void test() Self-test implementations.
- void build(std::vector< int64_t > original_array) function that builds the PSA
-
+ int64_t query(int64_t beg, int64_t end) query function
+ void build(const std::vector< int64_t > &original_array) function that builds the PSA
+ static void test() Self-test implementations.
+
diff --git a/doxygen_crawl.html b/doxygen_crawl.html
index 811164b92..152a1c21b 100644
--- a/doxygen_crawl.html
+++ b/doxygen_crawl.html
@@ -279,8 +279,8 @@
+
-
diff --git a/search/all_7.js b/search/all_7.js
index d9d94c57e..d0a61e3b1 100644
--- a/search/all_7.js
+++ b/search/all_7.js
@@ -69,7 +69,7 @@ var searchData=
['bubble_20sort_20algorithm_20analysis_20best_20case_20worst_20case_20average_20case_66',['Bubble Sort Algorithm Analysis (Best Case - Worst Case - Average Case)',['../d8/d13/bubble__sort_8cpp.html#autotoc_md111',1,'']]],
['bubble_5fsort_67',['bubble_sort',['../d0/dd5/namespacebubble__sort.html',1,'bubble_sort'],['../d8/d13/bubble__sort_8cpp.html#af3b12930a83915712461d53fe9659686',1,'sorting::bubble_sort::bubble_sort()']]],
['bubble_5fsort_2ecpp_68',['bubble_sort.cpp',['../d8/d13/bubble__sort_8cpp.html',1,'']]],
- ['build_69',['build',['../d1/d9e/prefix__sum__array_8cpp.html#ab36151479ad37d53ef9fcb60a274b1d9',1,'range_queries::prefix_sum_array']]],
+ ['build_69',['build',['../d1/d9e/prefix__sum__array_8cpp.html#a98e118ed64ba95a8198e1a915459c177',1,'range_queries::prefix_sum_array']]],
['building_20locally_70',['Building Locally',['../d6/dcd/md__c_o_n_t_r_i_b_u_t_i_n_g.html#autotoc_md37',1,'']]],
['buzz_5fnumber_2ecpp_71',['buzz_number.cpp',['../d1/d76/buzz__number_8cpp.html',1,'']]]
];
diff --git a/search/functions_2.js b/search/functions_2.js
index a2a4e7911..c4b7822cd 100644
--- a/search/functions_2.js
+++ b/search/functions_2.js
@@ -28,5 +28,5 @@ var searchData=
['brute_5fforce_25',['brute_force',['../d9/d03/namespacestring__search.html#aeb2cd81064717aedd62bfb096b1a73d8',1,'string_search::brute_force()'],['../d3/d7d/brute__force__string__searching_8cpp.html#aeb2cd81064717aedd62bfb096b1a73d8',1,'brute_force(): brute_force_string_searching.cpp']]],
['bst_5fnode_26',['bst_node',['../dd/db6/structbinary__search__tree_1_1bst__node.html#a51dd9bd6dd32bce3b74dd64557306778',1,'binary_search_tree::bst_node']]],
['bubble_5fsort_27',['bubble_sort',['../d8/d13/bubble__sort_8cpp.html#af3b12930a83915712461d53fe9659686',1,'sorting::bubble_sort']]],
- ['build_28',['build',['../d1/d9e/prefix__sum__array_8cpp.html#ab36151479ad37d53ef9fcb60a274b1d9',1,'range_queries::prefix_sum_array']]]
+ ['build_28',['build',['../d1/d9e/prefix__sum__array_8cpp.html#a98e118ed64ba95a8198e1a915459c177',1,'range_queries::prefix_sum_array']]]
];
|