count() patch to unsigned for DenseMap, DenseSet, ScopedHashTable, ValueMap

Yaron Keren yaron.keren at gmail.com
Mon Dec 23 03:51:17 PST 2013


The count() function for STL datatypes returns unsigned, even where it's
only 1/0 result like std::set. Some of the LLVM ADT already return unsigned
count(), while others still return bool count().

In continuation to r197879, this patch modifies DenseMap, DenseSet,
ScopedHashTable, ValueMap:: count() to return unsigned instead of bool, 1
instead of true and 0 instead of false.

Yaron
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20131223/895a2e15/attachment.html>
-------------- next part --------------
Index: DenseMap.h
===================================================================
--- DenseMap.h	(revision 197903)
+++ DenseMap.h	(working copy)
@@ -99,10 +99,10 @@
     setNumTombstones(0);
   }
 
-  /// count - Return true if the specified key is in the map.
-  bool count(const KeyT &Val) const {
+  /// count - Return 1 if the specified key is in the map, 0 otherwise.
+  unsigned count(const KeyT &Val) const {
     const BucketT *TheBucket;
-    return LookupBucketFor(Val, TheBucket);
+    return LookupBucketFor(Val, TheBucket) ? 1 : 0;
   }
 
   iterator find(const KeyT &Val) {
Index: DenseSet.h
===================================================================
--- DenseSet.h	(revision 197903)
+++ DenseSet.h	(working copy)
@@ -42,7 +42,8 @@
     TheMap.clear();
   }
 
-  bool count(const ValueT &V) const {
+  /// count - Return 1 if the specified key is in the set, 0 otherwise.
+  unsigned count(const ValueT &V) const {
     return TheMap.count(V);
   }
 
Index: ScopedHashTable.h
===================================================================
--- ScopedHashTable.h	(revision 197903)
+++ ScopedHashTable.h	(working copy)
@@ -172,7 +172,7 @@
   AllocatorRefTy getAllocator() { return Allocator; }
   AllocatorCRefTy getAllocator() const { return Allocator; }
 
-  bool count(const K &Key) const {
+  unsigned count(const K &Key) const {
     return TopLevelMap.count(Key);
   }
 
Index: ValueMap.h
===================================================================
--- ValueMap.h	(revision 197903)
+++ ValueMap.h	(working copy)
@@ -108,9 +108,9 @@
 
   void clear() { Map.clear(); }
 
-  /// count - Return true if the specified key is in the map.
-  bool count(const KeyT &Val) const {
-    return Map.find_as(Val) != Map.end();
+  /// count - Return 1 if the specified key is in the map, 0 otherwise.
+  unsigned count(const KeyT &Val) const {
+    return Map.find_as(Val) == Map.end() ? 0 : 1;
   }
 
   iterator find(const KeyT &Val) {


More information about the cfe-commits mailing list