473,395 Members | 1,706 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Iterator related problem

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_tof 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_tRange;
typedef boost::sub_range<const std::dequeconst_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<Pointholds 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

Feb 7 '07 #1
0 1600

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

38
by: Grant Edwards | last post by:
In an interview at http://acmqueue.com/modules.php?name=Content&pa=showpage&pid=273 Alan Kay said something I really liked, and I think it applies equally well to Python as well as the languages...
26
by: Michael Klatt | last post by:
I am trying to write an iterator for a std::set that allows the iterator target to be modified. Here is some relvant code: template <class Set> // Set is an instance of std::set<> class...
29
by: Hagen | last post by:
Hello, in a recent thread "speed of vector vs array" I read about the problem of the slow acces by addressing vector elements by indexing, unfortunately I see no workaround in my case. My...
13
by: Dan Tsafrir | last post by:
is the following code standard? (cleanly compiles under g++-4.0.2): struct Asc { bool operator()(int a, int b) {return a < b;} }; struct Des { bool operator()(int a, int b) {return b > a;} };...
6
by: PengYu.UT | last post by:
Hi, Suppose I have a list which contains pointers. I want the pointer got by dereferencing the iterator be a pointer pointing to a const object. But std::list<const T*>::const_iterator doens't...
0
by: mailforpr | last post by:
Hi. Let me introduce an iterator to you, the so-called "Abstract Iterator" I developed the other day. I actually have no idea if there's another "Abstract Iterator" out there, as I have never...
2
by: toton | last post by:
Hi, I am developing one container of my own, which has iterators. the iterator is not derived from boost iterator facade (for some other reason), instead it is manually designed. Now when I am...
10
by: desktop | last post by:
I have read about input, output forward etc iterators. But if I make the following: int myints = {1,2,3,4,5,1,2,3,4,5}; std::vector<intmyvector (myints,myints+10); std::vector<int>::iterator...
4
by: mkborregaard | last post by:
Hi, I have the weirdest problem, and I can not see what is going wrong. I have made a 2d container class, and am implementing an iterator for that class. However, the ++ operator is behaving very...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.