Skip to content

Commit

Permalink
have empty() as (fast) alternative to size()
Browse files Browse the repository at this point in the history
Summary:
This is a behavior-preserving change. It just provides an additional internal function.

This should be a bit faster.

Reviewed By: agampe

Differential Revision: D50583738

fbshipit-source-id: 5ca4321bc0178fe5fe5c7ed2cb423fa264a3f71b
  • Loading branch information
Nikolai Tillmann authored and facebook-github-bot committed Nov 14, 2023
1 parent 37a34a1 commit 1169daf
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
13 changes: 13 additions & 0 deletions include/sparta/PowersetAbstractDomain.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ class PowersetImplementation : public AbstractValue<Derived> {
Snapshot>::value,
"Derived::elements() does not exist");

// bool size() const;
static_assert(std::is_same<decltype(std::declval<const Derived>().empty()),
bool>::value,
"Derived::empty() does not exist");

// size_t size() const;
static_assert(std::is_same<decltype(std::declval<const Derived>().size()),
size_t>::value,
Expand Down Expand Up @@ -137,6 +142,14 @@ class PowersetAbstractDomain
return this->get_value()->elements();
}

bool empty() const {
RUNTIME_CHECK(this->kind() == AbstractValueKind::Value,
invalid_abstract_value()
<< expected_kind(AbstractValueKind::Value)
<< actual_kind(this->kind()));
return this->get_value()->empty();
}

size_t size() const {
RUNTIME_CHECK(this->kind() == AbstractValueKind::Value,
invalid_abstract_value()
Expand Down
2 changes: 2 additions & 0 deletions include/sparta/SetAbstractDomain.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ class SetValue final : public PowersetImplementation<typename Set::value_type,

const Set& elements() const { return m_set; }

bool empty() const { return m_set.empty(); }

size_t size() const { return m_set.size(); }

bool contains(const Element& e) const { return m_set.contains(e); }
Expand Down
2 changes: 2 additions & 0 deletions include/sparta/SparseSetAbstractDomain.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ class SparseSetValue final
return AbstractValueKind::Value;
}

bool empty() const { return m_element_num == 0; }

size_t size() const { return m_element_num; }

friend std::ostream& operator<<(std::ostream& o,
Expand Down

0 comments on commit 1169daf

Please sign in to comment.