Prune CRLF.
[oota-llvm.git] / include / llvm / ADT / SparseSet.h
index 063c6755c680c67e882d7c0ac8293820e32f0afa..9a13440000acfd6a22c96963859f50fab33f5866 100644 (file)
@@ -20,8 +20,8 @@
 #ifndef LLVM_ADT_SPARSESET_H
 #define LLVM_ADT_SPARSESET_H
 
-#include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/SmallVector.h"
 #include "llvm/Support/DataTypes.h"
 #include <limits>
 
@@ -118,8 +118,13 @@ template<typename ValueT,
          typename KeyFunctorT = llvm::identity<unsigned>,
          typename SparseT = uint8_t>
 class SparseSet {
+  static_assert(std::numeric_limits<SparseT>::is_integer &&
+                !std::numeric_limits<SparseT>::is_signed,
+                "SparseT must be an unsigned integer type");
+
   typedef typename KeyFunctorT::argument_type KeyT;
   typedef SmallVector<ValueT, 8> DenseT;
+  typedef unsigned size_type;
   DenseT Dense;
   SparseT *Sparse;
   unsigned Universe;
@@ -138,7 +143,7 @@ public:
   typedef ValueT *pointer;
   typedef const ValueT *const_pointer;
 
-  SparseSet() : Sparse(0), Universe(0) {}
+  SparseSet() : Sparse(nullptr), Universe(0) {}
   ~SparseSet() { free(Sparse); }
 
   /// setUniverse - Set the universe size which determines the largest key the
@@ -182,7 +187,7 @@ public:
   /// This is not the same as BitVector::size() which returns the size of the
   /// universe.
   ///
-  unsigned size() const { return Dense.size(); }
+  size_type size() const { return Dense.size(); }
 
   /// clear - Clears the set.  This is a very fast constant time operation.
   ///
@@ -198,9 +203,6 @@ public:
   ///
   iterator findIndex(unsigned Idx) {
     assert(Idx < Universe && "Key out of range");
-    assert(std::numeric_limits<SparseT>::is_integer &&
-           !std::numeric_limits<SparseT>::is_signed &&
-           "SparseT must be an unsigned integer type");
     const unsigned Stride = std::numeric_limits<SparseT>::max() + 1u;
     for (unsigned i = Sparse[Idx], e = size(); i < e; i += Stride) {
       const unsigned FoundIdx = ValIndexOf(Dense[i]);
@@ -227,10 +229,11 @@ public:
     return const_cast<SparseSet*>(this)->findIndex(KeyIndexOf(Key));
   }
 
-  /// count - Returns true if this set contains an element identified by Key.
+  /// count - Returns 1 if this set contains an element identified by Key,
+  /// 0 otherwise.
   ///
-  bool count(const KeyT &Key) const {
-    return find(Key) != end();
+  size_type count(const KeyT &Key) const {
+    return find(Key) == end() ? 0 : 1;
   }
 
   /// insert - Attempts to insert a new element.