Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/support/sorted_vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,28 @@

namespace wasm {

template<typename T> struct SortedVector : public std::vector<T> {
template<typename T> struct SortedVector : private std::vector<T> {
using Base = std::vector<T>;
using Base::back;
using Base::begin;
using Base::clear;
using Base::empty;
using Base::end;
using Base::erase;
using Base::push_back;
using Base::resize;
using Base::size;
using typename Base::const_iterator;
using typename Base::iterator;

private:
// Resize is dangerous, as adding new items may break the order. We only use
// this internally (and carefully).
using Base::resize;

public:
SortedVector() = default;

bool operator==(const SortedVector&) const = default;
Comment thread
stevenfontanella marked this conversation as resolved.

SortedVector merge(const SortedVector& other) const {
SortedVector ret;
ret.resize(size() + other.size());
Expand Down Expand Up @@ -75,7 +81,7 @@ template<typename T> struct SortedVector : public std::vector<T> {

T& insert(T x) {
if (empty() || back() < x) {
push_back(std::move(x));
Base::push_back(std::move(x));
return back();
}
auto it = std::lower_bound(begin(), end(), x);
Expand Down Expand Up @@ -162,12 +168,6 @@ template<typename T> struct SortedVector : public std::vector<T> {
resize(write);
}

void verify() const {
for (Index i = 1; i < size(); i++) {
assert((*this)[i - 1] < (*this)[i]);
}
}

void dump(const char* str = nullptr) const {
std::cout << "SortedVector " << (str ? str : "") << ": ";
for (const auto& x : *this) {
Expand Down
Loading