473,320 Members | 1,799 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,320 software developers and data experts.

storing iterator in a class

Hi,
I have a deque of Point class,. Point class have two fields x, and y.
Now I want another class Character should point to a portion of the
deque, and allow iteration only on the portion.
Thus a deque<Characterwill point on the deque<Pointover different
ranges.
Both are dynamic in the sense, new character, and hence new point gets
added, while old character and old points get removed.

My question is, what the Character will store as pointer to
deque<Point>? Two size_t / or int as start and past end pointer, or two
iterator? With iterator, I am facing problem is that they are not
default construct able. Like Character class can point to another
deque<Pointwhich stores some modified set of points, and are
available only after performing some computation.

In general, I need different views on same set of data. Say the
deque<Pointcan be viewed as Page = Character =Point. or even Page
=Stroke =Point or something else.

Thanks for help
abir

Nov 3 '06 #1
5 1833
"toton" <ab*******@gmail.comwrote in message
news:11**********************@k70g2000cwa.googlegr oups.com...
: I have a deque of Point class,. Point class have two fields x, and y.
: Now I want another class Character should point to a portion of the
: deque, and allow iteration only on the portion.
: Thus a deque<Characterwill point on the deque<Pointover different
: ranges.
: Both are dynamic in the sense, new character, and hence new point gets
: added, while old character and old points get removed.
Caveat: any insertion/removal in a deque will invalidate all iterators
(including any call to a pop or push function).

Because of this, std::deque is not the ideal container if you work
with a lot of iterators. (also because deque iterators do not
provide the best performance...).

: My question is, what the Character will store as pointer to
: deque<Point>? Two size_t / or int as start and past end pointer, or
two
: iterator? With iterator, I am facing problem is that they are not
: default construct able. Like Character class can point to another
: deque<Pointwhich stores some modified set of points, and are
: available only after performing some computation.

If you only work with the end of the deque, storing indices (e.g.
two deque::size_type values), is probably a better choice.

hth -Ivan
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form
Brainbench MVP for C++ <http://www.brainbench.com

Nov 3 '06 #2

Ivan Vecerina wrote:
"toton" <ab*******@gmail.comwrote in message
news:11**********************@k70g2000cwa.googlegr oups.com...
: I have a deque of Point class,. Point class have two fields x, and y.
: Now I want another class Character should point to a portion of the
: deque, and allow iteration only on the portion.
: Thus a deque<Characterwill point on the deque<Pointover different
: ranges.
: Both are dynamic in the sense, new character, and hence new point gets
: added, while old character and old points get removed.
Caveat: any insertion/removal in a deque will invalidate all iterators
(including any call to a pop or push function).
I don't use deque in actual implementation a circular_buffer much like
http://www.goodliffe.net/cbuf.html. It has a advantage, that it wraps
the index with a modulo. In my case, it can also change the size (which
of course needs copy ) if required. i.e it is semi-fixed sized, while
allows index wrapping.
Because of this, std::deque is not the ideal container if you work
with a lot of iterators. (also because deque iterators do not
provide the best performance...).
Thanks for making this point.
: My question is, what the Character will store as pointer to
: deque<Point>? Two size_t / or int as start and past end pointer, or
two
: iterator? With iterator, I am facing problem is that they are not
: default construct able. Like Character class can point to another
: deque<Pointwhich stores some modified set of points, and are
: available only after performing some computation.

If you only work with the end of the deque, storing indices (e.g.
two deque::size_type values), is probably a better choice.
Thanks. Then I will store indices (size_t or size_type) . However it
stores only a range of the deque (or my container) not the whole thing.
In when I need points from the deque, I need to create two iterators
from the indices and return them. Probably I need to store a reference
to the container also. Then when I need points, I can return
container.begin()+begin_index , and container.begin()+end_index as two
iterator. As the container is random access, hope it won't cost more.
Am I on the write track?
Once again , thanks for the answer.
abir
hth -Ivan
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form
Brainbench MVP for C++ <http://www.brainbench.com
Nov 3 '06 #3
"toton" <ab*******@gmail.comwrote:
I have a deque of Point class,. Point class have two fields x, and y.
Now I want another class Character should point to a portion of the
deque, and allow iteration only on the portion.
Thus a deque<Characterwill point on the deque<Pointover different
ranges.
Both are dynamic in the sense, new character, and hence new point gets
added, while old character and old points get removed.

My question is, what the Character will store as pointer to
deque<Point>? Two size_t / or int as start and past end pointer, or two
iterator? With iterator, I am facing problem is that they are not
default construct able. Like Character class can point to another
deque<Pointwhich stores some modified set of points, and are
available only after performing some computation.

In general, I need different views on same set of data. Say the
deque<Pointcan be viewed as Page = Character =Point. or even Page
=Stroke =Point or something else.
I suggest you reverse things. Instead of having a single deque and then
several containers representing parts of the deque, try creating several
deques (one for each part) and another class that knows how to jump from
deque to deque thus treating them as one.

--
To send me email, put "sheltie" in the subject.
Nov 4 '06 #4
"toton" <ab*******@gmail.comwrote in message
news:11**********************@h48g2000cwc.googlegr oups.com...
: If you only work with the end of the deque, storing indices (e.g.
: two deque::size_type values), is probably a better choice.
: Thanks. Then I will store indices (size_t or size_type) . However it
: stores only a range of the deque (or my container) not the whole
thing.
: In when I need points from the deque, I need to create two iterators
: from the indices and return them. Probably I need to store a reference
: to the container also. Then when I need points, I can return
: container.begin()+begin_index , and container.begin()+end_index as two
: iterator. As the container is random access, hope it won't cost more.
std::deque is random access, so performance will be ok.
[ a deque iterator has at least a size of 2-pointers, so this won't
be more expensive size-wise either ]

: Am I on the write track?
At this technical level yet. I can't speak for the whole design ... ;)

Cheers,
Ivan

: Once again , thanks for the answer.
: abir
:
: hth -Ivan
: --
: http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact
form
: Brainbench MVP for C++ <http://www.brainbench.com
:

Nov 4 '06 #5

Daniel T. wrote:
"toton" <ab*******@gmail.comwrote:
I have a deque of Point class,. Point class have two fields x, and y.
Now I want another class Character should point to a portion of the
deque, and allow iteration only on the portion.
Thus a deque<Characterwill point on the deque<Pointover different
ranges.
Both are dynamic in the sense, new character, and hence new point gets
added, while old character and old points get removed.

My question is, what the Character will store as pointer to
deque<Point>? Two size_t / or int as start and past end pointer, or two
iterator? With iterator, I am facing problem is that they are not
default construct able. Like Character class can point to another
deque<Pointwhich stores some modified set of points, and are
available only after performing some computation.

In general, I need different views on same set of data. Say the
deque<Pointcan be viewed as Page = Character =Point. or even Page
=Stroke =Point or something else.

I suggest you reverse things. Instead of having a single deque and then
several containers representing parts of the deque, try creating several
deques (one for each part) and another class that knows how to jump from
deque to deque thus treating them as one.
That is certainly an alternative. However I frequently need a uniform
treatment to all of the points, and such jump are needed, while
sometimes need to have a character-wise access.
Also I need different views of the points, other than character. In
that case, it is problematic if I store the points inside the character
as a deque. The problem is which view the data ( the deque of Point)
should represent? Will it store deque of Points for character, or
stroke or anything else. In any case, for any other view the same
problem arrives. That's why I decided to have a single deque. I raised
the issue in a separate thread
http://groups.google.com/group/comp....59255dcd4915e0
though , no one replied :(
And the program is supposed to run in a low memory device (PDA's ) ,
thus I want to make the caching effect as dominating as possible.

Thanks again for reply.
abir
--
To send me email, put "sheltie" in the subject.
Nov 6 '06 #6

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...
4
by: Scott Smedley | last post by:
Hi all, I'm trying to write a special adaptor iterator for my program. I have *almost* succeeded, though it fails under some circumstances. See the for-loop in main(). Any pointers/help...
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...
2
by: prasanthag | last post by:
Hi, I am a newbie to this group. I have a problem in handling the variable arguments passed to a function. My requirement is like this. I have 2 functions say, void funcX(int i, int j);...
0
by: toton | last post by:
Hi, I have a little design related problem, and finding a good way to resolve it. To state the problem, I have points from writing of several documents. Each document represents a Session class ,...
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...
20
by: Martin Jørgensen | last post by:
Hi, I'm reading a number of double values from a file. It's a 2D-array: 1 2 3 4 5 6 7 ------------- 1 3.2 2 0 2.1 3 9.3 4
8
by: Mike Jolley | last post by:
Hello First off, I'm a student so I'm pretty new to C++, and therefore I have probably made a stupid mistake somewhere. Anyway Ive been trying to fix this 5 hours straight now, so i need a...
2
by: jeet232 | last post by:
I've a class 'Parent' I declare a map using map<Parent, Parent> mymap; Now I derive one child 'Child' and I've to add it to this map, so I do a static_cast like this: Child* key = new...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.