Skip to content

Commit

Permalink
simplified segemented repository and segemented vector by removing po…
Browse files Browse the repository at this point in the history
…p_back operation. Now it is clear that elements are only appended.
  • Loading branch information
drexlerd committed Dec 22, 2024
1 parent 4df42fd commit 1d9f492
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 23 deletions.
28 changes: 14 additions & 14 deletions include/loki/details/utils/segmented_repository.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,29 +76,29 @@ class SegmentedRepository
size_t index = m_uniqueness_set.size();
assert(index == m_persistent_vector.size());

// Explicitly call the constructor of T to give exclusive access to the factory.
auto element_ptr = ObserverPtr<const T>(&m_persistent_vector.emplace_back(T(index, std::forward<Args>(args)...)));
// The pointer to the location in persistent memory.
assert(element_ptr);
// Create element of type T
auto element = T(index, std::forward<Args>(args)...);

/* Test for uniqueness */
auto it = m_uniqueness_set.find(element_ptr);
auto it = m_uniqueness_set.find(ObserverPtr<const T>(&element));
if (it == m_uniqueness_set.end())
{
/* Element is unique! */

m_uniqueness_set.emplace(element_ptr);
}
else
{
/* Element is not unique! */
// Copy element to persistent memory
m_persistent_vector.push_back(std::move(element));

// Fetch the pointer to persistent element;
const auto persistent_addr = &m_persistent_vector.back();

// Mark the element as not unique.
m_uniqueness_set.insert(persistent_addr);

element_ptr = *it;
// Remove duplicate from vector
m_persistent_vector.pop_back();
// Return pointer to persistent element.
return persistent_addr;
}

return element_ptr.get();
return it->get();
}

/**
Expand Down
9 changes: 0 additions & 9 deletions include/loki/details/utils/segmented_vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,6 @@ class SegmentedVector
return element;
}

void pop_back()
{
assert(m_size > 0);
auto& segment = m_segments.back();
segment.pop_back();
m_accessor.pop_back();
--m_size;
}

/**
* Accessors
*/
Expand Down

0 comments on commit 1d9f492

Please sign in to comment.