Skip to content

Commit

Permalink
Add tdb::pmr::list wrapper as an alias for std::list
Browse files Browse the repository at this point in the history
  • Loading branch information
bekadavis9 committed Mar 4, 2024
1 parent e838f29 commit 30873da
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 8 deletions.
1 change: 1 addition & 0 deletions tiledb/common/memory_tracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ enum class MemoryType {
ENUMERATION,
ENUMERATION_PATHS,
FOOTER,
FILTERED_DATA,
FILTERED_DATA_BLOCK,
GENERIC_TILE_IO,
RTREE,
Expand Down
62 changes: 62 additions & 0 deletions tiledb/common/pmr.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#ifndef TILEDB_COMMON_PMR_H
#define TILEDB_COMMON_PMR_H

#include <list>
#include <unordered_map>
#include <vector>

Expand Down Expand Up @@ -119,6 +120,67 @@ unique_ptr<Tp> make_unique(memory_resource* resource, size_t size) {
return make_unique<Tp>(resource, size, alignof(Tp));
}

/* ********************************* */
/* PMR LIST DECLARATION */
/* ********************************* */
template <class Tp>
using pmr_list = std::list<Tp, polymorphic_allocator<Tp>>;

template <class Tp>
class list : public pmr_list<Tp> {
public:
using value_type = typename pmr_list<Tp>::value_type;
using allocator_type = typename pmr_list<Tp>::allocator_type;
using size_type = typename pmr_list<Tp>::size_type;
using difference_type = typename pmr_list<Tp>::difference_type;
using reference = typename pmr_list<Tp>::reference;
using const_reference = typename pmr_list<Tp>::const_reference;
using pointer = typename pmr_list<Tp>::pointer;
using const_pointer = typename pmr_list<Tp>::const_pointer;
using iterator = typename pmr_list<Tp>::iterator;
using const_iterator = typename pmr_list<Tp>::const_iterator;
using reverse_iterator = typename pmr_list<Tp>::reverse_iterator;
using const_reverse_iterator = typename pmr_list<Tp>::const_reverse_iterator;

// Delete all default constructors because they don't require an allocator
list() = delete;
list(const list& other) = delete;
list(list&& other) = delete;

// Delete non-allocator aware copy and move assign.
list& operator=(const list& other) = delete;
list& operator=(list&& other) noexcept = delete;

explicit list(const allocator_type& alloc) noexcept
: pmr_list<Tp>(alloc) {
}

explicit list(size_type count, const Tp& value, const allocator_type& alloc)
: pmr_list<Tp>(count, value, alloc) {
}

explicit list(size_type count, const allocator_type& alloc)
: pmr_list<Tp>(count, alloc) {
}

template <class InputIt>
list(InputIt first, InputIt last, const allocator_type& alloc)
: pmr_list<Tp>(first, last, alloc) {
}

list(const list& other, const allocator_type& alloc)
: pmr_list<Tp>(other, alloc) {
}

list(list&& other, const allocator_type& alloc)
: pmr_list<Tp>(other, alloc) {
}

list(std::initializer_list<Tp> init, const allocator_type& alloc)
: pmr_list<Tp>(init, alloc) {
}
};

/* ********************************* */
/* PMR VECTOR DECLARATION */
/* ********************************* */
Expand Down
22 changes: 14 additions & 8 deletions tiledb/sm/query/readers/filtered_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,12 @@ class FilteredData {
std::vector<ThreadPool::Task>& read_tasks,
shared_ptr<MemoryTracker> memory_tracker)
: memory_tracker_(memory_tracker)
, fixed_data_blocks_(
memory_tracker_->get_resource(MemoryType::FILTERED_DATA))
, var_data_blocks_(
memory_tracker_->get_resource(MemoryType::FILTERED_DATA))
, nullable_data_blocks_(
memory_tracker_->get_resource(MemoryType::FILTERED_DATA))
, name_(name)
, fragment_metadata_(fragment_metadata)
, var_sized_(var_sized)
Expand Down Expand Up @@ -395,7 +401,7 @@ class FilteredData {
}

/** @return Data blocks corresponding to the tile type. */
inline std::list<FilteredDataBlock>& data_blocks(const TileType type) {
inline tdb::pmr::list<FilteredDataBlock>& data_blocks(const TileType type) {
switch (type) {
case TileType::FIXED:
return fixed_data_blocks_;
Expand All @@ -409,7 +415,7 @@ class FilteredData {
}

/** @return Current data block corresponding to the tile type. */
inline std::list<FilteredDataBlock>::iterator& current_data_block(
inline tdb::pmr::list<FilteredDataBlock>::iterator& current_data_block(
const TileType type) {
switch (type) {
case TileType::FIXED:
Expand Down Expand Up @@ -592,22 +598,22 @@ class FilteredData {
shared_ptr<MemoryTracker> memory_tracker_;

/** Fixed data blocks. */
std::list<FilteredDataBlock> fixed_data_blocks_;
tdb::pmr::list<FilteredDataBlock> fixed_data_blocks_;

/** Current fixed data block used when creating fixed tiles. */
std::list<FilteredDataBlock>::iterator current_fixed_data_block_;
tdb::pmr::list<FilteredDataBlock>::iterator current_fixed_data_block_;

/** Var data blocks. */
std::list<FilteredDataBlock> var_data_blocks_;
tdb::pmr::list<FilteredDataBlock> var_data_blocks_;

/** Current var data block used when creating var tiles. */
std::list<FilteredDataBlock>::iterator current_var_data_block_;
tdb::pmr::list<FilteredDataBlock>::iterator current_var_data_block_;

/** Nullable data blocks. */
std::list<FilteredDataBlock> nullable_data_blocks_;
tdb::pmr::list<FilteredDataBlock> nullable_data_blocks_;

/** Current nullable data block used when creating nullable tiles. */
std::list<FilteredDataBlock>::iterator current_nullable_data_block_;
tdb::pmr::list<FilteredDataBlock>::iterator current_nullable_data_block_;

/** Name of the attribute. */
const std::string& name_;
Expand Down

0 comments on commit 30873da

Please sign in to comment.