[PATCH] D18579: SetVector: Add front, pop_front and resize operations
Matthias Braun via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 29 14:37:40 PDT 2016
MatzeB created this revision.
MatzeB added reviewers: dblaikie, echristo, qcolombet.
MatzeB added a subscriber: llvm-commits.
MatzeB set the repository for this revision to rL LLVM.
Herald added a subscriber: mcrosier.
front() and pop_front() are useful if the underlying vector type is a std::dequeue.
resize() allows the usage of BitVector as set type and tuning in the case of DenseSet/SmallPtrSet.
Repository:
rL LLVM
http://reviews.llvm.org/D18579
Files:
include/llvm/ADT/SetVector.h
Index: include/llvm/ADT/SetVector.h
===================================================================
--- include/llvm/ADT/SetVector.h
+++ include/llvm/ADT/SetVector.h
@@ -116,6 +116,12 @@
return vector_.back();
}
+ /// Return the first element of the SetVector.
+ const T &front() const {
+ assert(!empty() && "Cannot call front() on empty SetVector!");
+ return vector_.front();
+ }
+
/// \brief Index into the SetVector.
const_reference operator[](size_type n) const {
assert(n < vector_.size() && "SetVector access out of range!");
@@ -218,14 +224,33 @@
return Ret;
}
+ /// \brief Remove the first element of the SetVector, only available if the
+ /// underlying vector type supports the pop_front() operation.
+ void pop_front() {
+ assert(!empty() && "Cannot remove an element from an empty SetVector!");
+ set_.erase(front());
+ vector_.pop_front();
+ }
+
+ T LLVM_ATTRIBUTE_UNUSED_RESULT pop_front_val() {
+ T Ret = front();
+ pop_front();
+ return Ret;
+ }
+
bool operator==(const SetVector &that) const {
return vector_ == that.vector_;
}
bool operator!=(const SetVector &that) const {
return vector_ != that.vector_;
}
+ /// Call resize on the underlying set.
+ void resize(size_t size) {
+ set_.resize(size);
+ }
+
private:
/// \brief A wrapper predicate designed for use with std::remove_if.
///
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D18579.51986.patch
Type: text/x-patch
Size: 1414 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160329/dff06a81/attachment.bin>
More information about the llvm-commits
mailing list