The count() function for STL datatypes returns unsigned, even

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
This commit is contained in:
Yaron Keren 2013-12-22 12:04:23 +00:00
parent 1a7ebaaa3d
commit 4ef09de13e
4 changed files with 11 additions and 9 deletions

View File

@ -271,9 +271,9 @@ public:
return erase_imp(PtrTraits::getAsVoidPointer(Ptr)); return erase_imp(PtrTraits::getAsVoidPointer(Ptr));
} }
/// count - Return true if the specified pointer is in the set. /// count - Return 1 if the specified pointer is in the set, 0 otherwise.
bool count(PtrType Ptr) const { unsigned count(PtrType Ptr) const {
return count_imp(PtrTraits::getAsVoidPointer(Ptr)); return count_imp(PtrTraits::getAsVoidPointer(Ptr)) ? 1 : 0;
} }
template <typename IterT> template <typename IterT>

View File

@ -47,11 +47,11 @@ public:
return isSmall() ? Vector.size() : Set.size(); return isSmall() ? Vector.size() : Set.size();
} }
/// count - Return true if the element is in the set. /// count - Return 1 if the element is in the set, 0 otherwise.
bool count(const T &V) const { unsigned count(const T &V) const {
if (isSmall()) { if (isSmall()) {
// Since the collection is small, just do a linear search. // Since the collection is small, just do a linear search.
return vfind(V) != Vector.end(); return vfind(V) == Vector.end() ? 0 : 1;
} else { } else {
return Set.count(V); return Set.count(V);
} }

View File

@ -227,10 +227,11 @@ public:
return const_cast<SparseSet*>(this)->findIndex(KeyIndexOf(Key)); 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 { unsigned count(const KeyT &Key) const {
return find(Key) != end(); return find(Key) == end() ? 0 : 1;
} }
/// insert - Attempts to insert a new element. /// insert - Attempts to insert a new element.

View File

@ -313,6 +313,7 @@ public:
return GetOrCreateValue(Key).getValue(); return GetOrCreateValue(Key).getValue();
} }
/// count - Return 1 if the element is in the map, 0 otherwise.
size_type count(StringRef Key) const { size_type count(StringRef Key) const {
return find(Key) == end() ? 0 : 1; return find(Key) == end() ? 0 : 1;
} }