Boost logo

Glas :

Re: [glas] return type of operator[](size_type) for sparse vectors?

From: Toon Knapen (toon.knapen_at_[hidden])
Date: 2006-05-13 05:59:05

I have implemented a sparse-vector taking into account the remarks that
have been made previously. I think this is a good compromise between
performance and functionality. I uploaded the latest state of the
documentation and the current implementation of a sparse-vector, the
mapped_vector, can be found here

There is also a small test that you can find
glas/test/sparse_vector/mapped_vector.cpp. (remember that we switched to
subversion if you want to check it out).


Russell Smiley wrote:
> I think I prefer option 3 (proxy that modifies a structural zero if
> necessary). Presumably there is some penalty for this more sophisticated
> behaviour.
> If "proxy_type operator[]" is not provided how would structural zeroes
> normally be modified?
> Russell.
>> -----Original Message-----
>> Subject: [glas] return type of operator[](size_type) for
>> sparse vectors?
>> Given a sparse vector v of size 10, what would v[0] return? Should it
>> return a reference to the element at position 0 in the sparse vector.
>> What if that element is a structural-zero? It clearly is not as
>> straightforward as with dense vectors.
>> The options AFAICT are:
>> 1) provide no 'operator[](size_type)' to avoid confusion
>> 2) return the value at the corresponding position or if the position
>> corresponds to a structural-zero return zero. Thus in that case
>> operator[] will not affect/change the structure and
>> operator[] will not
>> allow to change the value at the corresponding position.
>> 3) return a proxy. If the proxy is being assigned to, the
>> structure will
>> be changed in case the position corresponded with a structural-zero.
> _______________________________________________
> glas mailing list
> glas_at_[hidden]

Toon Knapen
Check out our training program on acoustics
and register on-line at