← Back to team overview

dolfin team mailing list archive

Re: RFC: remove (container.size() == 0) idiom

 

On Thu, Mar 1, 2012 at 2:22 AM, Marco Morandini <morandini@xxxxxxxxxxxxxx>wrote:

> There are some occurrences of
>
> container.size() == 0
>
> scattered throughout the code
> (and fewer of container.size() != 0) .
> Many of them are harmless, i.e. whenever container
> is a vector. Some of them, however,
> are for maps of sets (e.g. dolfin/adaptivity/**Extrapolation.cpp:149 ),
> leading to completely unnecessary O(N) operations (racall that size() is
> O(N) for a map or a list).
>
>
While true for a list, it is not a problem for maps or sets:

http://www.cplusplus.com/reference/stl/map/size/
http://www.cplusplus.com/reference/stl/set/size/

While a silly implementation of a list will be O(n) most good
implementations keep its size around.

-- Andy

> I'd like to prepare a (mostly mechanical) patch that changes them into
> container.empty() .
>
> Would be acceptable to change all of them (I'd like to go for this route)
> or should I change only the places where container is not a vector?
>
> Thanks,
>
> Marco
>
> ______________________________**_________________
> Mailing list: https://launchpad.net/~dolfin
> Post to     : dolfin@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~dolfin
> More help   : https://help.launchpad.net/**ListHelp<https://help.launchpad.net/ListHelp>
>

Follow ups

References