Boost logo

Boost :

Subject: Re: [boost] [devector] optimum growing/insertion policy
From: Joaquin M López Muñoz (joaquinlopezmunoz_at_[hidden])
Date: 2017-10-18 09:36:17


El 16/10/2017 a las 19:38, Thorsten Ottosen via Boost escribió:
> Den 15-10-2017 kl. 14:09 skrev Joaquin M López Muñoz via Boost:
>> Hi,
>
>> * Maintain a counter right_ of right insertions that gets incremented
>> when a
>> right insertion occurs and *decremented* when an erasure is issued
>> past the
>> middle of the devector.
>
> So to implement this with a custom Resizing policy, the policy would
> need be stored via compressed_pair as a member and additionally
> provide a hook:
>
>   right_event( int elements )
>
> where elements can be both positive and negative and which is called
> from push_back and insert as needed. By default this could be an empty
> function.

In another post I'm proposing an alternative policy interface which can in
principle accommodate any policy --AFAICS.

>
>> * Right insertions trigger right shifting except when there's no back
>> free capacity,
>> in which case a reallocation is performed.
>> * Left insertions trigger left shifting except when there's no front
>> free capacity,
>> in which case a reallocation is performed.
>> * Reallocation reserves space for G*size() elements: of the resulting
>> G*size()-size()
>> free space, a fraction right_/size() is devoted to back free capacity,
>
> Maybe this is lost to me in the details, but given code that works for
> vector:
>
>   vector<int> v;
>   ...
>   v.reserve( v.size() + N );
>
> which guarantees no exceptions and no reallocations, how would that
> work with your policy?

Sorry, now it's me who's lost :-) std::vector::reserve can both throw
and reallocate, right?

Joaquín M López Muñoz


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk