What I feel about STL.

Y

Yin Zhu

Hello all,
I haved used STL in writing some arithmetic programs for a while now.
There are some very convenient to use, such as
map(use it as a mapping array), set(use it as a dictionary for Insert,
Delete, Exist query ..), vector(a varying length array, O(1) push under
amortization)

but STL didn't support other function , such as
*)findKth in set, althought rb-tree can easily be augmented to support
this
function.

*)sort strings(we often use a radix sort method or ternary searching
tree to
do the string sorting efficently)

now My question comes to
1) Does STL encourge people to augment them? (it seems to me that STL
codes
are so integrated that modifying it will be more difficult to write a
new one)

2) Or STL is just a set of solid examples to show how you write your
own library
from scratch.

thanks in advance.
 
V

Victor Bazarov

Yin said:
Hello all,
I haved used STL in writing some arithmetic programs for a while now.
There are some very convenient to use, such as
map(use it as a mapping array), set(use it as a dictionary for Insert,
Delete, Exist query ..), vector(a varying length array, O(1) push
under amortization)

but STL didn't support other function , such as
*)findKth in set, althought rb-tree can easily be augmented to support
this
function.

*)sort strings(we often use a radix sort method or ternary searching
tree to
do the string sorting efficently)

now My question comes to
1) Does STL encourge people to augment them? (it seems to me that STL
codes
are so integrated that modifying it will be more difficult to write a
new one)

2) Or STL is just a set of solid examples to show how you write your
own library
from scratch.

The Standard library is neigher for making changes to it, nor a set of
examples. It's a small but significant stepping stone to the next part
of your programming. It has many things most people need all the time.
It has some things some people need some of the time. At no point was
it conceived to be an example or a sandbox. It's definitely extensible
and definitely generic enough so your own mechanisms adhering to the
Standard rules (like iterators, for example) will work nicely with the
algorithms in the Standard Library. Or, vice versa, if you write your
algorithm to accept standard iterators, it should just as nicely work
with iterators provided by the Standard containers as well as any other
iterators or even plain pointers.

V
 
I

IndyStef

Yin said:
Hello all,
I haved used STL in writing some arithmetic programs for a while now.
There are some very convenient to use, such as
map(use it as a mapping array), set(use it as a dictionary for Insert,
Delete, Exist query ..), vector(a varying length array, O(1) push under
amortization)

but STL didn't support other function , such as
*)findKth in set, althought rb-tree can easily be augmented to support
this
function.

*)sort strings(we often use a radix sort method or ternary searching
tree to
do the string sorting efficently)

now My question comes to
1) Does STL encourge people to augment them? (it seems to me that STL
codes
are so integrated that modifying it will be more difficult to write a
new one)

2) Or STL is just a set of solid examples to show how you write your
own library
from scratch.

thanks in advance.

If you need to get behavior like findKth then you can use the STL
algorithms with user defined functors to act on you data. However, STL
does not really encourage direct access to its internal workings. If
that is required, then you have to come up with your own solutions.
STL was designed to satisfy 90% of the people that needed it, and it
does. The remaining 10% may have to come up with their own solutions.

Stefan
 
B

Bernd Strieder

Hello,

Yin said:
but STL didn't support other function , such as
*)findKth in set, althought rb-tree can easily be augmented to support
this
function.

There is nth_element, but it works on RandomAccessIterators, i.e.
std::vector. An rb-tree augmented with information to support findKth
would no more be a rb-tree, perhaps some hybrid rb-weight-balanced
tree. I think weight balanced binary trees have bad worst case
behaviour on erase, so rb-trees have been chosen by all implementors.
*)sort strings(we often use a radix sort method or ternary searching
tree to
do the string sorting efficently)

STL cannot offer all existing data structures, especially those which
might be not optimal in the general case (e.g. radix sort has bad
worst-case behaviour)
now My question comes to
1) Does STL encourge people to augment them? (it seems to me that STL
codes
are so integrated that modifying it will be more difficult to write a
new one)

There are rules to follow to create your own templates integrating with
the STL, howto define iterators, and tons of examples howto roll
algorithms of your own. Look at boost, they have tons of extensions of
all kinds.
2) Or STL is just a set of solid examples to show how you write your
own library
from scratch.

I think this is some important thought. STL has not been designed to be
inherited and patched, but to be easily usable, and to serve as an
example.

Bernd Strieder
 
D

Daniel T.

"Yin Zhu said:
Hello all,
I haved used STL in writing some arithmetic programs for a while now.
There are some very convenient to use, such as
map(use it as a mapping array), set(use it as a dictionary for Insert,
Delete, Exist query ..), vector(a varying length array, O(1) push under
amortization)

but STL didn't support other function , such as
*)findKth in set, althought rb-tree can easily be augmented to support
this function.

std::advance will do that.
*)sort strings(we often use a radix sort method or ternary searching
tree to
do the string sorting efficently)

As I understand it, only quicksort is in the library. If you want to
implement other sort algorithms, you would have to do that yourself. I'd
suggest you use the same basic interface as std::sort just with a
different function name.
 
K

Kai-Uwe Bux

Daniel said:
std::advance will do that.

Yes, but not necessarily with the complexity that the OP is thinking of.

As I understand it, only quicksort is in the library.
[snip]

The sorting algorithm from the standard library is not necessarily
quicksort, although the complexity specifications for std::sort are
designed to allow quicksort as an implementation. However, the HP/SGI based
implementation of the standard library are likely to use introsort, which
is an improvement of quicksort that preserves the average run-time and
still has n log(n) worst case complexity.


Best

Kai-Uwe Bux
 
?

=?ISO-8859-1?Q?Jens_M=FCller?=

Kai-Uwe Bux said:
Yes, but not necessarily with the complexity that the OP is thinking of.

But IF the underlying data structure is a red-black-tree, and
std::advance can be done cheaper than the standard requires, it SHOULD
be done so.

That is of course an issue with the stdlib _implementation_, so the OP
should contact his compiler vendor.
 

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

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top