Iterator related problem

T

toton

Hi,
I have a complex design of some dynamic situation. First I am
posting the design, then a few questions regarding the problem I am
facing. Hope some of the experts will answer the questions.
The codes are too long to post, and not finding a short compilable
example, but the following design will give almost all details to
specify the problem.
Design ....

1) class Point => stores two int x,y
class Point{
int x;
int y;
Point(int x,int y);
int x()const;
int y()const;
};


Point's get added in a deque<Point> (singleton,
boost::thread_specific_ptr , thus accessible for that thread).

data collector adds data
here result
collector removes data from here

||
||
=============================== deque<Point>
==================================
||
operator operates over the
data in it's own sequence
( in a different thread,
blocks the thread at that time)

operator creates a few other data structure which refers to a portion
of the points, like Char, Word, Line etc.
each if them stores a std::pair<size_t,size_t> of 2 indices, if they
are continuous in range, and returns a boost::sub_range (i.e a pair of
iterators). as, it can't store iterators directly, as Point's are
movable, and hence may invalidate iterators.
The scheme is like this ,
============================== deque<Point>
=====================================
| | | |
| Char[0] | Char[1] | Char[2] | ....
============================= deque<Char>
======================================
| | |
| Word[0] | Word[1] | ...

and so on.
thus,
typedef std::pair<size_t,size_t> Range;
typedef boost::sub_range<const std::deque> const_range;
class Char{
Range points_;
public:
const_range points()const;

};

The indexes takes care of the removed items, and they only linearly
increases, so that it always points to the correct items (each
container has a count of removed items, and translates the index to
appropriate one)
Now this kind of structure is designed for 2 reasons,
1) Things are dynamic, Char & Word are formed after points , they are
not known when points are coming.
2) If all the points resides on memory next by next , it helps cache
locality. (The other thing can be done is like deque<Point*>,
deque<Word*> etc, which removes all of the hurdles of index and
iterator , as then Char can store a deque<Point*> for it's portion,
and Word can store a deque<Char*> for its portion, no iterator
invalidation question, or movable question arises, however that will
be much less efficient I believe, as everything need to be initialized
with new , and here operations needs lots of access & computation on
the data structures).
In my case a typical deque<Point> holds 60K points, deque<Char>
holds 0.5K Char etc.

Now the questions,
1) Is it the best way of design ? or there can be a better way of
storing references to std containers ?
If, then how will it look ?
2) As all of these are based on continuous ranges (i.e 2 indexes )
boost::sub_range works. Now for a few things individual index are
specified, instead of first and last, and I want to iterate over those
and apply any stl algorithm just like boost::range or iterator, except
they jump here and there (all of my containers are random access) in
a sequence specified.
like

===================== deque<Word>
================================================
| Word | Word | Word| Word | .......

| | |
Prop Noun ====================
so proper noun stores a vector of 0,2,5. and sub_range (or a new
class) will return begin() as 0 th element, begin()+1, or [1] op as 2
nd element etc. So it is a little generalized range concept. And const
ness is necessary (like boost::sub_range ) .
This kind of range exists ? / can be designed ? / any alternatives ?

Thanks for any suggestion, advice ...

abir basak
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top