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

Richard Smith richard at metafoo.co.uk
Fri Jun 6 10:00:14 PDT 2014


On Thu, Jun 5, 2014 at 11:21 PM, Yaron Keren <yaron.keren at gmail.com> wrote:

> Which types should be used in ADT?
>
> Currently it's a mix:
>
> * Most data types use unsigned.
> * SetVector use size_type, locally typedef to vector_type::size_type
> size_type where vector_type is the template argument to SetVector.
> * StringMap use size_type, locally typedef to the global size_t.
> * SmallString and StringRef uses size_t.
>

If we want our container-like types to be containers, count should return
size_type. I suspect that size_type == size_t is probably the best choice
(for performance and code size), but I really doubt this makes much
difference. I don't think there are many cases where we'd want to support
containers of more than 4Gi elements. (In short, I don't think this really
matters, but each container should be internally consistent.)

Yaron
>
>
>
>
> 2014-06-06 3:21 GMT+03:00 Richard Smith <richard at metafoo.co.uk>:
>
> On Tue, Jun 3, 2014 at 2:11 PM, Rafael EspĂ­ndola <
>> rafael.espindola at gmail.com> wrote:
>>
>>> +  /// count -
>>>
>>> While at it, please drop the name from the comment.
>>>
>>> I think the patch is OK. Richard, do you know what is the reason the
>>> stl uses size_type?
>>
>>
>> I don't know for sure, but probably for consistency and ease of
>> specification of the interface.
>>
>> [It's been like that since Stepanov and Lee's original implementation,
>> where the red-black tree implementation shared by set,map,multiset,multimap
>> did not distinguish between the unique and non-unique cases in its 'count'
>> implementation.]
>>
>>
>>> On 23 December 2013 06:51, Yaron Keren <yaron.keren at gmail.com> wrote:
>>> > 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
>>> >
>>> >
>>> > _______________________________________________
>>> > cfe-commits mailing list
>>> > cfe-commits at cs.uiuc.edu
>>> > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>>> >
>>>
>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140606/067d9f0f/attachment.html>


More information about the cfe-commits mailing list