why should the SGI set provide the following function

Discussion in 'C++' started by hpsoar, Mar 31, 2009.

  1. hpsoar

    hpsoar Guest

    I'm reading a book on STL, It provides many source codes of STL's SGI
    implementation. I found the following function in class set: iterator
    insert(iterator position, const value_type& x);
    As I know, the position of a value inserted to is determined by the
    red-black tree, which is used when implementing class set. So why
    should it provide this function here?
     
    hpsoar, Mar 31, 2009
    #1
    1. Advertisements

  2. * hpsoar:
    This looks like an internal implementation detail.

    At some level of implementation an item has to be inserted at some specific
    position in the internal data structure (whatever that structure is), and
    naturally there must be some code for that -- used internally.

    It's not something that you should be concerned with as a user.


    Cheers & hth.,

    - Alf
     
    Alf P. Steinbach, Mar 31, 2009
    #2
    1. Advertisements

  3. * James Kanze:
    Thanks.

    Learned smth new! :)


    Cheers,

    - Alf
     
    Alf P. Steinbach, Mar 31, 2009
    #3
  4. From an algorithmic point of view it also allows reusing previous
    results. Having read Alexander Stepanov's papers, it wouldn't be surprising.
     
    Michael DOUBEZ, Mar 31, 2009
    #4
  5. hpsoar

    coal Guest

    I believe Boost Multi-index uses the hinted version in it's
    internal serialization code. However, Boost Serialization
    (1.38) doesn't take advantage of the function when dealing
    with (multi)set or (multi)map.
    http://webEbenezer.net/comparison.html -- see the section
    on loading/receiving data.

    If someone wanted to marshall a non-sorted
    boost::intrusive::list<int> to a std::set<int> it would
    probably be better to not use the function that takes
    a hint. So I think it makes sense for users to be to
    specifiy if they don't want to use the hinted insert
    function with these containers.

    Brian Wood
    Ebenezer Enterprises
    www.webEbenezer.net
     
    coal, Mar 31, 2009
    #5
  6. hpsoar

    coal Guest

    Oops. I should say:

    class abc : public list_base_hook<>
    {
    int a_;

    };

    and then boost::intrusive::list<abc>.


    Brian Wood
    Ebenezer Enterprises
    www.webEbenezer.net
     
    coal, Mar 31, 2009
    #6
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.