storing iterator in a class

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • toton

    #1

    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<Character will 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<Pointwhic h 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

  • Ivan Vecerina

    #2
    Re: storing iterator in a class

    "toton" <abirbasak@gmai l.comwrote in message
    news:1162554751 .268280.122860@ k70g2000cwa.goo glegroups.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<Character will 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<Pointwhic h 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_typ e 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

    Comment

    • toton

      #3
      Re: storing iterator in a class


      Ivan Vecerina wrote:
      "toton" <abirbasak@gmai l.comwrote in message
      news:1162554751 .268280.122860@ k70g2000cwa.goo glegroups.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<Character will 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<Pointwhic h 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_typ e 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

      Comment

      • Daniel T.

        #4
        Re: storing iterator in a class

        "toton" <abirbasak@gmai l.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<Character will 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<Pointwhic h 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.

        Comment

        • Ivan Vecerina

          #5
          Re: storing iterator in a class

          "toton" <abirbasak@gmai l.comwrote in message
          news:1162561095 .991077.231920@ h48g2000cwc.goo glegroups.com.. .
          : If you only work with the end of the deque, storing indices (e.g.
          : two deque::size_typ e 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
          :

          Comment

          • toton

            #6
            Re: storing iterator in a class


            Daniel T. wrote:
            "toton" <abirbasak@gmai l.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<Character will 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<Pointwhic h 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

            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.

            Comment

            Working...