473,587 Members | 2,490 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(sin gleton,
boost::thread_s pecific_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_rang e (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_rang e<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<Pointhold s 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_rang e 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_rang e ) .
This kind of range exists ? / can be designed ? / any alternatives ?

Thanks for any suggestion, advice ...

abir basak

Feb 7 '07 #1
0 1615

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

Similar topics

38
3654
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 mentioned: I characterized one way of looking at languages in this way: a lot of them are either the agglutination of features or they're a...
26
1514
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 Iterator { public : typedef typename Set::value_type T; typedef typename Set::iterator SetIterator; Iterator(Set& container, const SetIterator& it);
29
3949
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 case: class A {
13
2519
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;} }; int main() { int arr = {1, 2, 3}; set<int,Asc> asc(arr, arr+3); set<int,Des>::iterator beg = asc.begin(); // ...
6
6646
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 give me this capability. So I want std::list<T*>::iterator. However, the container is of type std::list<T*>. How to get std::list<const...
0
2667
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 looked for one on the net (I did browse the boost library though). It doesn't matter right now, anyway. To put it simply, Abstract Iterator is...
2
2203
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 interfacing it with other boost libraries (like permutation_iterator, sub_range etc), I get a few errors related to iterator traits. Now my question...
10
1849
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 forward_iterator = myvector.end(); I can still type "--forward_iterator" eventhough "--it" is illegal on forward iterators.
4
1999
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 strange. The implementation looks like this (there is a lot of code, but I have only included it all for consistency. The problem is quite small and...
0
8216
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7974
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8221
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6629
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5719
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5395
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3882
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2364
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1455
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.