D
desktop
I am currently trying to implement std::set::insert(hint p, e).
On this page:
http://gcc.gnu.org/onlinedocs/libstdc++/23_containers/howto.html#4
3 cases are mentioned and if they are fulfilled the new element e can be
inserted in amortized constant time:
# begin(), then the item being inserted should have a key less than all
the other keys in the container. The item will be inserted at the
beginning of the container, becoming the new entry at begin().
# end(), then the item being inserted should have a key greater than all
the other keys in the container. The item will be inserted at the end of
the container, becoming the new entry at end().
# neither begin() nor end(), then: Let h be the entry in the container
pointed to by hint, that is, h = *hint. Then the item being inserted
should have a key less than that of h, and greater than that of the item
preceding h. The new item will be inserted between h and h's predecessor
I the last case it only applies if the key e are less that *h but
greater than --*h corresponding to this example:
4 6 8
--h h
if e = 5 insert between 4 and 6 in amortized constant time.
But what if e = 7 why is it not possible to insert in amortized constant
time between 6 and 8?
On this page:
http://gcc.gnu.org/onlinedocs/libstdc++/23_containers/howto.html#4
3 cases are mentioned and if they are fulfilled the new element e can be
inserted in amortized constant time:
# begin(), then the item being inserted should have a key less than all
the other keys in the container. The item will be inserted at the
beginning of the container, becoming the new entry at begin().
# end(), then the item being inserted should have a key greater than all
the other keys in the container. The item will be inserted at the end of
the container, becoming the new entry at end().
# neither begin() nor end(), then: Let h be the entry in the container
pointed to by hint, that is, h = *hint. Then the item being inserted
should have a key less than that of h, and greater than that of the item
preceding h. The new item will be inserted between h and h's predecessor
I the last case it only applies if the key e are less that *h but
greater than --*h corresponding to this example:
4 6 8
--h h
if e = 5 insert between 4 and 6 in amortized constant time.
But what if e = 7 why is it not possible to insert in amortized constant
time between 6 and 8?