The count() function for STL datatypes returns unsigned, even
authorYaron Keren <yaron.keren@gmail.com>
Sun, 22 Dec 2013 12:04:23 +0000 (12:04 +0000)
committerYaron Keren <yaron.keren@gmail.com>
Sun, 22 Dec 2013 12:04:23 +0000 (12:04 +0000)
where it's only bool-like 1/0 result like std::set.count().

Some of the LLVM ADT already return unsigned count(), while
others return bool count().

This patch modifies SmallPtrSet, SmallSet, SparseSet count()
to return unsigned instead of bool:

 1 instead of true
 0 instead of false

More ADT to follow.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@197879 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ADT/SmallPtrSet.h
include/llvm/ADT/SmallSet.h
include/llvm/ADT/SparseSet.h
include/llvm/ADT/StringMap.h

index b52aebf7d55148c2fef048262000b82dfa509b1f..e433c57de743b1010cffb3205fdc96804e49a2e4 100644 (file)
@@ -271,9 +271,9 @@ public:
     return erase_imp(PtrTraits::getAsVoidPointer(Ptr));
   }
 
-  /// count - Return true if the specified pointer is in the set.
-  bool count(PtrType Ptr) const {
-    return count_imp(PtrTraits::getAsVoidPointer(Ptr));
+  /// count - Return 1 if the specified pointer is in the set, 0 otherwise.
+  unsigned count(PtrType Ptr) const {
+    return count_imp(PtrTraits::getAsVoidPointer(Ptr)) ? 1 : 0;
   }
 
   template <typename IterT>
index ecd3843cd0a7384d1b25c458e884ae8abc895866..6f36234cb4dd25dd95317aaea2d754ea6a56a569 100644 (file)
@@ -47,11 +47,11 @@ public:
     return isSmall() ? Vector.size() : Set.size();
   }
 
-  /// count - Return true if the element is in the set.
-  bool count(const T &V) const {
+  /// count - Return 1 if the element is in the set, 0 otherwise.
+  unsigned count(const T &V) const {
     if (isSmall()) {
       // Since the collection is small, just do a linear search.
-      return vfind(V) != Vector.end();
+      return vfind(V) == Vector.end() ? 0 : 1;
     } else {
       return Set.count(V);
     }
index 267a340a7581486ebfa72ba90bb13eb3e34e989d..ded48c5746a141dc93d49dd2fe20897c14ae8725 100644 (file)
@@ -227,10 +227,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();
+  unsigned count(const KeyT &Key) const {
+    return find(Key) == end() ? 0 : 1;
   }
 
   /// insert - Attempts to insert a new element.
index 0838ebe91f1ba51545e46234e336e63990249311..f22ce80df72dd6b261a1cb8af254810b29bfeed6 100644 (file)
@@ -313,6 +313,7 @@ public:
     return GetOrCreateValue(Key).getValue();
   }
 
+  /// count - Return 1 if the element is in the map, 0 otherwise.
   size_type count(StringRef Key) const {
     return find(Key) == end() ? 0 : 1;
   }