Skip to content

Commit

Permalink
feat: add helper methods to utils.h (#2771)
Browse files Browse the repository at this point in the history
* feat: add helper methods to `utils.h`

* fix: add missing includes

* fix: add note
  • Loading branch information
ManasviGoyal authored Oct 26, 2023
1 parent 17aabde commit c310ec1
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion header-only/layout-builder/awkward/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
#include <stdexcept>
#include <stdint.h>
#include <typeinfo>

#include <map>
#include <vector>

namespace awkward {

Expand Down Expand Up @@ -270,6 +271,44 @@ namespace awkward {
visit_impl<sizeof...(CONTENTs)>::visit(contents, index, fun);
}

/// @brief Helper function to retrieve the names of the buffers.
///
/// Note: use with caution, beware of a potential mismatch between retrieved values!
template<typename LayoutBuilder>
std::vector<std::string> buffer_name_helper(const LayoutBuilder* builder) {
std::map <std::string, size_t> names_nbytes = {};
std::vector<std::string> buffer_name;
builder->buffer_nbytes(names_nbytes);
for (auto it: names_nbytes) {
buffer_name.push_back(it.first);
}
return buffer_name;
}

/// @brief Helper function to retrieve the sizes (in bytes) of the buffers.
///
/// Note: use with caution, beware of a potential mismatch between retrieved values!
template<typename LayoutBuilder>
std::vector<size_t> buffer_size_helper(const LayoutBuilder* builder) {
std::map <std::string, size_t> names_nbytes = {};
std::vector<size_t> buffer_size;
builder->buffer_nbytes(names_nbytes);
for (auto it: names_nbytes) {
buffer_size.push_back(it.second);
}
return buffer_size;
}

/// @brief Helper function to retrieve the number of the buffers.
///
/// Note: use with caution, beware of a potential mismatch between retrieved values!
template<typename LayoutBuilder>
size_t num_buffers_helper(const LayoutBuilder* builder) {
std::map <std::string, size_t> names_nbytes = {};
builder->buffer_nbytes(names_nbytes);
return names_nbytes.size();
}

} // namespace awkward

#endif // AWKWARD_CPP_HEADERS_UTILS_H_

0 comments on commit c310ec1

Please sign in to comment.