Skip to content

Commit

Permalink
feat: getFullRowList
Browse files Browse the repository at this point in the history
  • Loading branch information
c-dilks committed Mar 28, 2024
1 parent 7185f51 commit fd1cef9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
12 changes: 6 additions & 6 deletions hipo4/bank.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,11 +342,11 @@ void bank::rowlist::reset(int numRows) {
m_list.clear();
m_init = false;
if(numRows >= 0)
m_list = copy_number_list(numRows);
m_list = getFullList(numRows);
else {
if(ownerBankIsUnknown("reset"))
return;
m_list = copy_number_list(m_owner_bank->getRows());
m_list = getFullList(m_owner_bank->getRows());
}
m_init = true;
}
Expand Down Expand Up @@ -388,16 +388,14 @@ void bank::rowlist::reduce(const char *expression) {
}
}

bank::rowlist::list_t bank::rowlist::generate_number_list(list_t::size_type num) {
bank::rowlist::list_t bank::rowlist::s_number_list_init(list_t::size_type num) {
list_t result;
for(list_t::size_type i = 0; i < num; i++)
result.push_back(i);
return result;
}

bank::rowlist::list_t bank::rowlist::s_number_list = bank::rowlist::generate_number_list();

bank::rowlist::list_t bank::rowlist::copy_number_list(list_t::size_type num) {
bank::rowlist::list_t bank::rowlist::getFullList(list_t::size_type num) {
if(num < 0)
return {};
if(num <= s_number_list.size())
Expand All @@ -410,6 +408,8 @@ bank::rowlist::list_t bank::rowlist::copy_number_list(list_t::size_type num) {
}
}

bank::rowlist::list_t bank::rowlist::s_number_list = bank::rowlist::s_number_list_init();

bool bank::rowlist::ownerBankIsUnknown(std::string_view caller) {
if(m_owner_bank == nullptr) {
std::cerr <<
Expand Down
13 changes: 10 additions & 3 deletions hipo4/bank.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,13 +238,16 @@ namespace hipo {
/// @param expression the filter expression
void reduce(char const* expression);

/// @returns a list of numbers from 0 to `num`
/// @param num the size of the list
static list_t getFullList(list_t::size_type num);

private:
bool m_init{false};
list_t m_list{};
bank* m_owner_bank;

static list_t generate_number_list(list_t::size_type num = 500);
static list_t copy_number_list(list_t::size_type num);
static list_t s_number_list_init(list_t::size_type num = 500);
static list_t s_number_list;

bool ownerBankIsUnknown(std::string_view caller = "");
Expand Down Expand Up @@ -345,9 +348,13 @@ namespace hipo {
}

/// @returns an immutable list of available rows for this bank. This list may be a subset of the full
/// list of rows, if for example the bank was filtered (see `hipo::bank::rowlist::reduce`)
/// list of rows, if for example the bank was filtered (see `hipo::bank::rowlist::reduce`); _cf._ `hipo::bank::rowlist::getFullRowList`
rowlist::list_t const& getRowList() const { return bankRowList.getList(); }

/// @returns an immutable list of **all** rows in the bank; _cf._ `hipo::bank::rowlist::getRowList`. This method
/// may be less efficient than simply using a `for` loop from `0` to `getRows()`
rowlist::list_t const getFullRowList() const { return bankRowList.getFullList(getRows()); }

/// @returns a reference to the mutable `hipo::bank::rowlist` owned by this bank. For example, use this method to
/// call `hipo::bank::rowlist::reduce`.
rowlist& getMutableRowList() { return bankRowList; }
Expand Down

0 comments on commit fd1cef9

Please sign in to comment.