llvm.org GIT mirror llvm / ed4e8a8
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 size_type instead of bool, 1 instead of true and 0 instead of false. size_type is typedef-ed locally within each class to size_t. http://reviews.llvm.org/D4018 Reviewed by dblaikie. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@211350 91177308-0d34-0410-b5e6-96231b3b80d8 Yaron Keren 5 years ago
14 changed file(s) with 42 addition(s) and 29 deletion(s). Raw diff Collapse all Expand all
3333 unsigned Capacity; // Size of allocated memory in BitWord.
3434
3535 public:
36 typedef size_t size_type;
3637 // Encapsulation of a single bit.
3738 class reference {
3839 friend class BitVector;
110111 bool empty() const { return Size == 0; }
111112
112113 /// size - Returns the number of bits in this bitvector.
113 unsigned size() const { return Size; }
114 size_type size() const { return Size; }
114115
115116 /// count - Returns the number of bits which are set.
116 unsigned count() const {
117 size_type count() const {
117118 unsigned NumBits = 0;
118119 for (unsigned i = 0; i < NumBitWords(size()); ++i)
119120 if (sizeof(BitWord) == 4)
4242 typedef std::pair BucketT;
4343
4444 public:
45 typedef size_t size_type;
4546 typedef KeyT key_type;
4647 typedef ValueT mapped_type;
4748 typedef BucketT value_type;
6970 unsigned size() const { return getNumEntries(); }
7071
7172 /// Grow the densemap so that it has at least Size buckets. Does not shrink
72 void resize(size_t Size) {
73 void resize(size_type Size) {
7374 if (Size > getNumBuckets())
7475 grow(Size);
7576 }
9899 setNumTombstones(0);
99100 }
100101
101 /// count - Return true if the specified key is in the map.
102 bool count(const KeyT &Val) const {
102 /// Return 1 if the specified key is in the map, 0 otherwise.
103 size_type count(const KeyT &Val) const {
103104 const BucketT *TheBucket;
104 return LookupBucketFor(Val, TheBucket);
105 return LookupBucketFor(Val, TheBucket) ? 1 : 0;
105106 }
106107
107108 iterator find(const KeyT &Val) {
2828 public:
2929 typedef ValueT key_type;
3030 typedef ValueT value_type;
31 typedef size_t size_type;
3132
3233 explicit DenseSet(unsigned NumInitBuckets = 0) : TheMap(NumInitBuckets) {}
3334
3435 bool empty() const { return TheMap.empty(); }
35 unsigned size() const { return TheMap.size(); }
36 size_type size() const { return TheMap.size(); }
3637 size_t getMemorySize() const { return TheMap.getMemorySize(); }
3738
3839 /// Grow the DenseSet so that it has at least Size buckets. Will not shrink
4344 TheMap.clear();
4445 }
4546
46 bool count(const ValueT &V) const {
47 /// Return 1 if the specified key is in the set, 0 otherwise.
48 size_type count(const ValueT &V) const {
4749 return TheMap.count(V);
4850 }
4951
2828 typename MapType = llvm::DenseMap,
2929 typename VectorType = std::vector > >
3030 class MapVector {
31 typedef typename VectorType::size_type SizeType;
31 typedef typename VectorType::size_type size_type;
3232
3333 MapType Map;
3434 VectorType Vector;
3737 typedef typename VectorType::iterator iterator;
3838 typedef typename VectorType::const_iterator const_iterator;
3939
40 SizeType size() const {
40 size_type size() const {
4141 return Vector.size();
4242 }
4343
9999 return std::make_pair(begin() + I, false);
100100 }
101101
102 unsigned count(const KeyT &Key) const {
102 size_type count(const KeyT &Key) const {
103103 typename MapType::const_iterator Pos = Map.find(Key);
104104 return Pos == Map.end()? 0 : 1;
105105 }
147147 /// ScopeTy - This is a helpful typedef that allows clients to get easy access
148148 /// to the name of the scope for this hash table.
149149 typedef ScopedHashTableScope ScopeTy;
150 typedef size_t size_type;
150151 private:
151152 typedef ScopedHashTableVal ValTy;
152153 DenseMap TopLevelMap;
169170 AllocatorTy &getAllocator() { return Allocator; }
170171 const AllocatorTy &getAllocator() const { return Allocator; }
171172
172 bool count(const K &Key) const {
173 /// Return 1 if the specified key is in the table, 0 otherwise.
174 size_type count(const K &Key) const {
173175 return TopLevelMap.count(Key);
174176 }
175177
5353 };
5454
5555 public:
56 typedef size_t size_type;
5657 // Encapsulation of a single bit.
5758 class reference {
5859 SmallBitVector &TheVector;
167168 }
168169
169170 /// size - Returns the number of bits in this bitvector.
170 size_t size() const {
171 size_type size() const {
171172 return isSmall() ? getSmallSize() : getPointer()->size();
172173 }
173174
174175 /// count - Returns the number of bits which are set.
175 unsigned count() const {
176 size_type count() const {
176177 if (isSmall()) {
177178 uintptr_t Bits = getSmallBits();
178179 if (NumBaseBits == 32)
7272 ~SmallPtrSetImplBase();
7373
7474 public:
75 typedef size_t size_type;
7576 bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const { return size() == 0; }
76 unsigned size() const { return NumElements; }
77 size_type size() const { return NumElements; }
7778
7879 void clear() {
7980 // If the capacity of the array is huge, and the # elements used is small,
262263 }
263264
264265 /// count - Return 1 if the specified pointer is in the set, 0 otherwise.
265 unsigned count(PtrType Ptr) const {
266 size_type count(PtrType Ptr) const {
266267 return count_imp(PtrTraits::getAsVoidPointer(Ptr)) ? 1 : 0;
267268 }
268269
3636 typedef typename SmallVector::const_iterator VIterator;
3737 typedef typename SmallVector::iterator mutable_iterator;
3838 public:
39 typedef size_t size_type;
3940 SmallSet() {}
4041
4142 bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const {
4243 return Vector.empty() && Set.empty();
4344 }
4445
45 unsigned size() const {
46 size_type size() const {
4647 return isSmall() ? Vector.size() : Set.size();
4748 }
4849
4950 /// count - Return 1 if the element is in the set, 0 otherwise.
50 unsigned count(const T &V) const {
51 size_type count(const T &V) const {
5152 if (isSmall()) {
5253 // Since the collection is small, just do a linear search.
5354 return vfind(V) == Vector.end() ? 0 : 1;
4444 : public ilist_node > {
4545 public:
4646 typedef unsigned long BitWord;
47 typedef size_t size_type;
4748 enum {
4849 BITWORD_SIZE = sizeof(BitWord) * CHAR_BIT,
4950 BITWORDS_PER_ELEMENT = (ElementSize + BITWORD_SIZE - 1) / BITWORD_SIZE,
119120 return Bits[Idx / BITWORD_SIZE] & (1L << (Idx % BITWORD_SIZE));
120121 }
121122
122 unsigned count() const {
123 size_type count() const {
123124 unsigned NumBits = 0;
124125 for (unsigned i = 0; i < BITWORDS_PER_ELEMENT; ++i)
125126 if (sizeof(BitWord) == 4)
184184 typedef const ValueT &const_reference;
185185 typedef ValueT *pointer;
186186 typedef const ValueT *const_pointer;
187 typedef size_t size_type;
187188
188189 SparseMultiSet()
189190 : Sparse(nullptr), Universe(0), FreelistIdx(SMSNode::INVALID), NumFree(0) {}
326327 /// This is not the same as BitVector::size() which returns the size of the
327328 /// universe.
328329 ///
329 unsigned size() const {
330 size_type size() const {
330331 assert(NumFree <= Dense.size() && "Out-of-bounds free entries");
331332 return Dense.size() - NumFree;
332333 }
377378
378379 /// Returns the number of elements identified by Key. This will be linear in
379380 /// the number of elements of that key.
380 unsigned count(const KeyT &Key) const {
381 size_type count(const KeyT &Key) const {
381382 unsigned Ret = 0;
382383 for (const_iterator It = find(Key); It != end(); ++It)
383384 ++Ret;
123123
124124 typedef typename KeyFunctorT::argument_type KeyT;
125125 typedef SmallVector DenseT;
126 typedef size_t size_type;
126127 DenseT Dense;
127128 SparseT *Sparse;
128129 unsigned Universe;
185186 /// This is not the same as BitVector::size() which returns the size of the
186187 /// universe.
187188 ///
188 unsigned size() const { return Dense.size(); }
189 size_type size() const { return Dense.size(); }
189190
190191 /// clear - Clears the set. This is a very fast constant time operation.
191192 ///
230231 /// count - Returns 1 if this set contains an element identified by Key,
231232 /// 0 otherwise.
232233 ///
233 unsigned count(const KeyT &Key) const {
234 size_type count(const KeyT &Key) const {
234235 return find(Key) == end() ? 0 : 1;
235236 }
236237
8686 typedef KeyT key_type;
8787 typedef ValueT mapped_type;
8888 typedef std::pair value_type;
89 typedef size_t size_type;
8990
9091 explicit ValueMap(unsigned NumInitBuckets = 64)
9192 : Map(NumInitBuckets), Data() {}
102103 inline const_iterator end() const { return const_iterator(Map.end()); }
103104
104105 bool empty() const { return Map.empty(); }
105 unsigned size() const { return Map.size(); }
106 size_type size() const { return Map.size(); }
106107
107108 /// Grow the map so that it has at least Size buckets. Does not shrink
108109 void resize(size_t Size) { Map.resize(Size); }
109110
110111 void clear() { Map.clear(); }
111112
112 /// count - Return true if the specified key is in the map.
113 bool count(const KeyT &Val) const {
114 return Map.find_as(Val) != Map.end();
113 /// Return 1 if the specified key is in the map, 0 otherwise.
114 size_type count(const KeyT &Val) const {
115 return Map.find_as(Val) == Map.end() ? 0 : 1;
115116 }
116117
117118 iterator find(const KeyT &Val) {
307307 return;
308308
309309 const Function *GV = MF->getFunction();
310 assert(FnDebugInfo.count(GV) == true);
310 assert(FnDebugInfo.count(GV));
311311 assert(CurFn == &FnDebugInfo[GV]);
312312
313313 if (CurFn->Instrs.empty()) {
662662
663663 // Otherwise, we're removing metadata from an instruction.
664664 assert((hasMetadataHashEntry() ==
665 getContext().pImpl->MetadataStore.count(this)) &&
665 (getContext().pImpl->MetadataStore.count(this) > 0)) &&
666666 "HasMetadata bit out of date!");
667667 if (!hasMetadataHashEntry())
668668 return; // Nothing to remove!