From 16c6b857ee4264fcc828ab85dfabddefc2a84f0d Mon Sep 17 00:00:00 2001 From: Hossein Moein Date: Mon, 3 Jul 2023 12:53:45 -0400 Subject: [PATCH] Fixed some of the const correctness --- include/DataFrame/Internals/DataFrame.tcc | 44 +++++++------- include/DataFrame/Internals/DataFrame_get.tcc | 58 +++++++++---------- .../DataFrame/Internals/DataFrame_join.tcc | 18 +++--- include/DataFrame/Internals/DataFrame_opt.tcc | 2 +- include/DataFrame/Internals/DataFrame_set.tcc | 12 ++-- 5 files changed, 67 insertions(+), 67 deletions(-) diff --git a/include/DataFrame/Internals/DataFrame.tcc b/include/DataFrame/Internals/DataFrame.tcc index 2d0ade808..4aced6034 100644 --- a/include/DataFrame/Internals/DataFrame.tcc +++ b/include/DataFrame/Internals/DataFrame.tcc @@ -155,7 +155,7 @@ DataFrame::shuffle(const StlVecType &col_names, shuffle_functor_ functor; const SpinGuard guard(lock_); - for (auto name_citer : col_names) [[likely]] { + for (const auto &name_citer : col_names) [[likely]] { const auto citer = column_tb_.find (name_citer); if (citer == column_tb_.end()) [[unlikely]] { @@ -338,8 +338,8 @@ fill_missing_linter_(ColumnVecType &vec, if (vec_size < 3) return; int count = 0; - T *y1 = &(vec[0]); - T *y2 = &(vec[2]); + const T *y1 = &(vec[0]); + const T *y2 = &(vec[2]); const IndexType *x = &(index[1]); const IndexType *x1 = &(index[0]); const IndexType *x2 = &(index[2]); @@ -398,7 +398,7 @@ fill_missing(const StlVecType &col_names, int limit) { const size_type count = col_names.size(); - StlVecType> futures(get_thread_level()); + StlVecType> futures(get_thread_level()); size_type thread_count = 0; for (size_type i = 0; i < count; ++i) { @@ -779,9 +779,9 @@ sort(const char *name1, sort_spec dir1, const char *name2, sort_spec dir2, make_consistent(); - ColumnVecType *vec1 { nullptr}; - ColumnVecType *vec2 { nullptr}; - const SpinGuard guard (lock_); + const ColumnVecType *vec1 { nullptr}; + const ColumnVecType *vec2 { nullptr}; + const SpinGuard guard (lock_); if (! ::strcmp(name1, DF_INDEX_COL_NAME)) vec1 = reinterpret_cast *>(&indices_); @@ -1002,10 +1002,10 @@ sort(const char *name1, sort_spec dir1, make_consistent(); - ColumnVecType *vec1 { nullptr}; - ColumnVecType *vec2 { nullptr}; - ColumnVecType *vec3 { nullptr}; - const SpinGuard guard (lock_); + const ColumnVecType *vec1 { nullptr}; + const ColumnVecType *vec2 { nullptr}; + const ColumnVecType *vec3 { nullptr}; + const SpinGuard guard (lock_); if (! ::strcmp(name1, DF_INDEX_COL_NAME)) vec1 = reinterpret_cast *>(&indices_); @@ -1102,11 +1102,11 @@ sort(const char *name1, sort_spec dir1, make_consistent(); - ColumnVecType *vec1 { nullptr}; - ColumnVecType *vec2 { nullptr}; - ColumnVecType *vec3 { nullptr}; - ColumnVecType *vec4 { nullptr}; - const SpinGuard guard (lock_); + const ColumnVecType *vec1 { nullptr}; + const ColumnVecType *vec2 { nullptr}; + const ColumnVecType *vec3 { nullptr}; + const ColumnVecType *vec4 { nullptr}; + const SpinGuard guard (lock_); if (! ::strcmp(name1, DF_INDEX_COL_NAME)) vec1 = reinterpret_cast *>(&indices_); @@ -1235,12 +1235,12 @@ sort(const char *name1, sort_spec dir1, make_consistent(); - ColumnVecType *vec1 { nullptr}; - ColumnVecType *vec2 { nullptr}; - ColumnVecType *vec3 { nullptr}; - ColumnVecType *vec4 { nullptr}; - ColumnVecType *vec5 { nullptr}; - const SpinGuard guard (lock_); + const ColumnVecType *vec1 { nullptr}; + const ColumnVecType *vec2 { nullptr}; + const ColumnVecType *vec3 { nullptr}; + const ColumnVecType *vec4 { nullptr}; + const ColumnVecType *vec5 { nullptr}; + const SpinGuard guard (lock_); if (! ::strcmp(name1, DF_INDEX_COL_NAME)) vec1 = reinterpret_cast *>(&indices_); diff --git a/include/DataFrame/Internals/DataFrame_get.tcc b/include/DataFrame/Internals/DataFrame_get.tcc index aaff43c1a..316752b7b 100644 --- a/include/DataFrame/Internals/DataFrame_get.tcc +++ b/include/DataFrame/Internals/DataFrame_get.tcc @@ -113,7 +113,7 @@ template typename DataFrame::template ColumnVecType & DataFrame::get_column (const char *name, bool do_lock) { - auto iter = column_tb_.find (name); + const auto iter = column_tb_.find (name); if (iter == column_tb_.end()) [[unlikely]] { char buffer [512]; @@ -156,7 +156,7 @@ DataFrame::get_column(size_type index, bool do_lock) { template bool DataFrame::has_column (const char *name) const { - auto iter = column_tb_.find (name); + const auto iter = column_tb_.find (name); return (iter != column_tb_.end()); } @@ -424,11 +424,11 @@ DataFrame::get_view_by_idx (Index2D range) { static_assert(std::is_base_of, H>::value, "Only a StdDataFrame can call get_view_by_idx()"); - auto lower = + const auto lower = std::lower_bound (indices_.begin(), indices_.end(), range.begin); - auto upper = + const auto upper = std::upper_bound (indices_.begin(), indices_.end(), range.end); - View dfv; + View dfv; if (lower != indices_.end() && (upper != indices_.end() || indices_.back() == range.end)) [[likely]] { @@ -467,9 +467,9 @@ DataFrame::get_view_by_idx (Index2D range) const { static_assert(std::is_base_of, H>::value, "Only a StdDataFrame can call get_view_by_idx()"); - auto lower = + const auto lower = std::lower_bound (indices_.begin(), indices_.end(), range.begin); - auto upper = + const auto upper = std::upper_bound (indices_.begin(), indices_.end(), range.end); ConstView dfcv; @@ -863,7 +863,7 @@ get_data_by_sel (const char *name, F &sel_functor) const { const ColumnVecType &vec = get_column(name); const size_type idx_s = indices_.size(); const size_type col_s = vec.size(); - StlVecType col_indices; + StlVecType col_indices; col_indices.reserve(idx_s / 2); for (size_type i = 0; i < col_s; ++i) @@ -874,7 +874,7 @@ get_data_by_sel (const char *name, F &sel_functor) const { IndexVecType new_index; new_index.reserve(col_indices.size()); - for (auto citer: col_indices) [[likely]] + for (const auto &citer: col_indices) [[likely]] new_index.push_back(indices_[citer]); df.load_index(std::move(new_index)); @@ -906,7 +906,7 @@ get_view_by_sel (const char *name, F &sel_functor) { const ColumnVecType &vec = get_column(name); const size_type idx_s = indices_.size(); const size_type col_s = vec.size(); - StlVecType col_indices; + StlVecType col_indices; col_indices.reserve(idx_s / 2); for (size_type i = 0; i < col_s; ++i) [[likely]] @@ -919,7 +919,7 @@ get_view_by_sel (const char *name, F &sel_functor) { typename TheView::IndexVecType new_index; new_index.reserve(col_indices.size()); - for (auto citer: col_indices) [[likely]] + for (const auto &citer: col_indices) [[likely]] new_index.push_back(&(indices_[citer])); dfv.indices_ = std::move(new_index); @@ -965,7 +965,7 @@ get_view_by_sel (const char *name, F &sel_functor) const { typename TheView::IndexVecType new_index; new_index.reserve(col_indices.size()); - for (auto citer: col_indices) [[likely]] + for (const auto &citer: col_indices) [[likely]] new_index.push_back(&(indices_[citer])); dfv.indices_ = std::move(new_index); @@ -1014,7 +1014,7 @@ get_data_by_sel (const char *name1, const char *name2, F &sel_functor) const { IndexVecType new_index; new_index.reserve(col_indices.size()); - for (auto citer: col_indices) + for (const auto &citer: col_indices) new_index.push_back(indices_[citer]); df.load_index(std::move(new_index)); @@ -1066,7 +1066,7 @@ get_view_by_sel (const char *name1, const char *name2, F &sel_functor) { typename TheView::IndexVecType new_index; new_index.reserve(col_indices.size()); - for (auto citer: col_indices) + for (const auto &citer: col_indices) new_index.push_back(&(indices_[citer])); dfv.indices_ = std::move(new_index); @@ -1119,7 +1119,7 @@ get_view_by_sel (const char *name1, const char *name2, F &sel_functor) const { typename TheView::IndexVecType new_index; new_index.reserve(col_indices.size()); - for (auto citer: col_indices) [[likely]] + for (const auto &citer: col_indices) [[likely]] new_index.push_back(&(indices_[citer])); dfv.indices_ = std::move(new_index); @@ -1172,7 +1172,7 @@ get_data_by_sel (const char *name1, IndexVecType new_index; new_index.reserve(col_indices.size()); - for (auto citer: col_indices) [[likely]] + for (const auto &citer: col_indices) [[likely]] new_index.push_back(indices_[citer]); df.load_index(std::move(new_index)); @@ -1235,7 +1235,7 @@ get_data_by_sel (F &sel_functor) const { IndexVecType new_index; new_index.reserve(col_indices.size()); - for (auto citer: col_indices) + for (const auto &citer: col_indices) new_index.push_back(indices_[citer]); df.load_index(std::move(new_index)); @@ -1298,7 +1298,7 @@ get_data_by_sel (F &sel_functor, FilterCols && ... filter_cols) const { // Get the records based on indices new_index.reserve(col_indices.size()); - for (auto citer: col_indices) + for (const auto &citer: col_indices) new_index.push_back(indices_[citer]); df.load_index(std::move(new_index)); @@ -1358,7 +1358,7 @@ get_view_by_sel (const char *name1, typename TheView::IndexVecType new_index; new_index.reserve(col_indices.size()); - for (auto citer: col_indices) [[likely]] + for (const auto &citer: col_indices) [[likely]] new_index.push_back(&(indices_[citer])); dfv.indices_ = std::move(new_index); @@ -1417,7 +1417,7 @@ get_view_by_sel (const char *name1, typename TheView::IndexVecType new_index; new_index.reserve(col_indices.size()); - for (auto citer: col_indices) [[likely]] + for (const auto &citer: col_indices) [[likely]] new_index.push_back(&(indices_[citer])); dfv.indices_ = std::move(new_index); @@ -1477,7 +1477,7 @@ get_data_by_sel(const char *name1, IndexVecType new_index; new_index.reserve(col_indices.size()); - for (auto citer: col_indices) [[likely]] + for (const auto &citer: col_indices) [[likely]] new_index.push_back(indices_[citer]); df.load_index(std::move(new_index)); @@ -1542,7 +1542,7 @@ get_view_by_sel(const char *name1, typename TheView::IndexVecType new_index; new_index.reserve(col_indices.size()); - for (auto citer: col_indices) [[likely]] + for (const auto &citer: col_indices) [[likely]] new_index.push_back(&(indices_[citer])); dfv.indices_ = std::move(new_index); @@ -1608,7 +1608,7 @@ get_view_by_sel(const char *name1, typename TheView::IndexVecType new_index; new_index.reserve(col_indices.size()); - for (auto citer: col_indices) [[likely]] + for (const auto &citer: col_indices) [[likely]] new_index.push_back(&(indices_[citer])); dfv.indices_ = std::move(new_index); @@ -1673,7 +1673,7 @@ get_data_by_sel(const char *name1, IndexVecType new_index; new_index.reserve(col_indices.size()); - for (auto citer: col_indices) [[likely]] + for (const auto &citer: col_indices) [[likely]] new_index.push_back(indices_[citer]); df.load_index(std::move(new_index)); @@ -1767,7 +1767,7 @@ get_data_by_sel(const char *name1, IndexVecType new_index; new_index.reserve(col_indices.size()); - for (auto citer: col_indices) [[likely]] + for (const auto &citer: col_indices) [[likely]] new_index.push_back(indices_[citer]); df.load_index(std::move(new_index)); @@ -1865,7 +1865,7 @@ get_data_by_sel(const char *name1, IndexVecType new_index; new_index.reserve(col_indices.size()); - for (auto citer: col_indices) + for (const auto &citer: col_indices) new_index.push_back(indices_[citer]); df.load_index(std::move(new_index)); @@ -1967,7 +1967,7 @@ get_data_by_sel(const char *name1, IndexVecType new_index; new_index.reserve(col_indices.size()); - for (auto citer: col_indices) + for (const auto &citer: col_indices) new_index.push_back(indices_[citer]); df.load_index(std::move(new_index)); @@ -2036,7 +2036,7 @@ get_view_by_sel(const char *name1, typename TheView::IndexVecType new_index; new_index.reserve(col_indices.size()); - for (auto citer: col_indices) + for (const auto &citer: col_indices) new_index.push_back(&(indices_[citer])); dfv.indices_ = std::move(new_index); @@ -2106,7 +2106,7 @@ get_view_by_sel(const char *name1, typename TheView::IndexVecType new_index; new_index.reserve(col_indices.size()); - for (auto citer: col_indices) + for (const auto &citer: col_indices) new_index.push_back(&(indices_[citer])); dfv.indices_ = std::move(new_index); diff --git a/include/DataFrame/Internals/DataFrame_join.tcc b/include/DataFrame/Internals/DataFrame_join.tcc index 2d4f161ac..0881fb95a 100644 --- a/include/DataFrame/Internals/DataFrame_join.tcc +++ b/include/DataFrame/Internals/DataFrame_join.tcc @@ -155,7 +155,7 @@ join_helper_common_( // Load the common and lhs columns for (const auto &iter : lhs.column_list_) [[likely]] { - auto rhs_citer = rhs.column_tb_.find(iter.first); + const auto rhs_citer = rhs.column_tb_.find(iter.first); if (skip_col_name && iter.first == skip_col_name) continue; @@ -182,7 +182,7 @@ join_helper_common_( // Load the rhs columns for (const auto &iter : rhs.column_list_) [[likely]] { - auto lhs_citer = lhs.column_tb_.find(iter.first); + const auto lhs_citer = lhs.column_tb_.find(iter.first); if (skip_col_name && iter.first == skip_col_name) continue; @@ -617,7 +617,7 @@ concat_helper_(LHS_T &lhs, const RHS_T &rhs, bool add_new_columns) { // Load common columns for (const auto &lhs_iter : lhs.column_list_) [[likely]] { - auto rhs_citer = rhs.column_tb_.find(lhs_iter.first); + const auto rhs_citer = rhs.column_tb_.find(lhs_iter.first); if (rhs_citer != rhs.column_tb_.end()) [[likely]] { concat_functor_ functor(lhs_iter.first.c_str(), @@ -632,7 +632,7 @@ concat_helper_(LHS_T &lhs, const RHS_T &rhs, bool add_new_columns) { // Load columns from rhs that do not exist in lhs if (add_new_columns) { for (const auto &rhs_citer : rhs.column_list_) [[likely]] { - auto lhs_iter = lhs.column_tb_.find(rhs_citer.first); + const auto lhs_iter = lhs.column_tb_.find(rhs_citer.first); if (lhs_iter == lhs.column_tb_.end()) { concat_functor_ functor(rhs_citer.first.c_str(), @@ -707,7 +707,7 @@ DataFrame::concat(const RHS_T &rhs, concat_policy cp) const { result.load_index(this->get_index().begin(), this->get_index().end()); for (const auto &lhs_citer : column_list_) { - auto rhs_citer = rhs.column_tb_.find(lhs_citer.first); + const auto rhs_citer = rhs.column_tb_.find(lhs_citer.first); if (rhs_citer != rhs.column_tb_.end()) { load_all_functor_ functor(lhs_citer.first.c_str(), @@ -776,7 +776,7 @@ DataFrame::concat_view(RHS_T &rhs, concat_policy cp) { data_[lhs_citer.second].change(functor); - auto rhs_citer = rhs.column_tb_.find(lhs_citer.first); + const auto rhs_citer = rhs.column_tb_.find(lhs_citer.first); if (rhs_citer != rhs.column_tb_.end()) rhs.data_[rhs_citer->second].change(functor); @@ -786,7 +786,7 @@ DataFrame::concat_view(RHS_T &rhs, concat_policy cp) { for (const auto &lhs_citer : column_list_) { concat_load_view_functor_ functor( lhs_citer.first.c_str(), result); - auto rhs_citer = + const auto rhs_citer = rhs.column_tb_.find(lhs_citer.first); if (rhs_citer != rhs.column_tb_.end()) { @@ -854,7 +854,7 @@ DataFrame::concat_view(RHS_T &rhs, concat_policy cp) const { data_[lhs_citer.second].change(functor); - auto rhs_citer = rhs.column_tb_.find(lhs_citer.first); + const auto rhs_citer = rhs.column_tb_.find(lhs_citer.first); if (rhs_citer != rhs.column_tb_.end()) rhs.data_[rhs_citer->second].change(functor); @@ -864,7 +864,7 @@ DataFrame::concat_view(RHS_T &rhs, concat_policy cp) const { for (const auto &lhs_citer : column_list_) { concat_load_view_functor_ functor( lhs_citer.first.c_str(), result); - auto rhs_citer = + const auto rhs_citer = rhs.column_tb_.find(lhs_citer.first); if (rhs_citer != rhs.column_tb_.end()) { diff --git a/include/DataFrame/Internals/DataFrame_opt.tcc b/include/DataFrame/Internals/DataFrame_opt.tcc index d74229748..5dc4d6b48 100644 --- a/include/DataFrame/Internals/DataFrame_opt.tcc +++ b/include/DataFrame/Internals/DataFrame_opt.tcc @@ -48,7 +48,7 @@ bool DataFrame::is_equal (const DataFrame &rhs) const { const SpinGuard guard(lock_); for (const auto &iter : column_list_) [[likely]] { - auto rhs_citer = rhs.column_tb_.find(iter.first); + const auto rhs_citer = rhs.column_tb_.find(iter.first); if (rhs_citer == rhs.column_tb_.end()) return (false); diff --git a/include/DataFrame/Internals/DataFrame_set.tcc b/include/DataFrame/Internals/DataFrame_set.tcc index cf0a30f3c..2a496fcfa 100644 --- a/include/DataFrame/Internals/DataFrame_set.tcc +++ b/include/DataFrame/Internals/DataFrame_set.tcc @@ -1186,7 +1186,7 @@ remove_duplicates (const char *name, const IndexType dummy_idx { }; for (size_type i = 0; i < col_s; ++i) [[likely]] { - auto insert_res = + const auto insert_res = row_table.emplace( std::forward_as_tuple(vec[i], include_index ? index[i] : dummy_idx), @@ -1228,7 +1228,7 @@ remove_duplicates (const char *name1, const IndexType dummy_idx { }; for (size_type i = 0; i < col_s; ++i) [[likely]] { - auto insert_res = + const auto insert_res = row_table.emplace( std::forward_as_tuple(vec1[i], vec2[i], include_index ? index[i] : dummy_idx), @@ -1275,7 +1275,7 @@ remove_duplicates (const char *name1, const IndexType dummy_idx { }; for (size_type i = 0; i < col_s; ++i) [[likely]] { - auto insert_res = + const auto insert_res = row_table.emplace( std::forward_as_tuple(vec1[i], vec2[i], vec3[i], include_index ? index[i] : dummy_idx), @@ -1327,7 +1327,7 @@ remove_duplicates (const char *name1, const IndexType dummy_idx { }; for (size_type i = 0; i < col_s; ++i) [[likely]] { - auto insert_res = + const auto insert_res = row_table.emplace( std::forward_as_tuple(vec1[i], vec2[i], vec3[i], vec4[i], include_index ? index[i] : dummy_idx), @@ -1381,7 +1381,7 @@ remove_duplicates (const char *name1, const IndexType dummy_idx { }; for (size_type i = 0; i < col_s; ++i) [[likely]] { - auto insert_res = + const auto insert_res = row_table.emplace( std::forward_as_tuple(vec1[i], vec2[i], vec3[i], vec4[i], vec5[i], @@ -1440,7 +1440,7 @@ remove_duplicates (const char *name1, const IndexType dummy_idx { }; for (size_type i = 0; i < col_s; ++i) [[likely]] { - auto insert_res = + const auto insert_res = row_table.emplace( std::forward_as_tuple(vec1[i], vec2[i], vec3[i], vec4[i], vec5[i], vec6[i],