I am recording integer values that fall in the interval [-lim,+lim]
. One possible way of doing this is to have use an array of size (2*lim+1)
. Each time integer x
arises I increment the appropriate element in the array. However, it is likely
that the actual interval is much smaller than [-lim,+lim]
, but the actual size of the interval isn't known a priori
. I would like to use a container that is only as large as it needed to be, as the potential interval is large and I need to use many of these containers. Is the best way to have a vector that I resize when necessary? (I thought that constantly resizing vectors would be pretty expensive, though.) Is there an efficient alternative?