Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

sort

Name: Anonymous 2010-02-15 17:09

sort() can be compared to the qsort() function in the C standard library (in stdlib.h). sort is templated, so it uses the correct comparison function for whatever data type you are sorting, which is already implemented for standard data types. Otherwise you can specify your own comparison function, which can be type-checked by the compiler; whereas for qsort, you must manually cast pointers to the desired type in an unsafe way. Also, qsort accesses the comparison function using a function pointer, necessitating large numbers of repeated function calls, which can take a lot of time; whereas in C++, comparison functions are usually inlined, removing the need for function calls. In practice, C++ code using sort is often many times faster at sorting simple data like integers than equivalent C code using qsort.

Name: !iN.MY.aRMs 2010-02-15 17:10

use FORTRAN77

Name: Anonymous 2010-02-15 17:11

this is bush league trolling

Name: Anonymous 2010-02-15 22:22

You are now unsafeCastingPointers manually

Name: Anonymous 2010-02-15 22:38

Why not just write your own sort?

Name: Anonymous 2010-02-15 23:14

Is this some Bjarne babble? Like when he said C++ was faster than C providing an example of a program in which the C version realloc()'d once for every byte read?

Name: Anonymous 2010-02-16 1:03

>>5
Yeah no shit, it's not like qsort() is hard. The Wikipedia pseudo-code is like eight lines. More importantly though, in the same amount of code you can write a macro version of qsort which does inline the comparison function. Hell you can pretty much just take std::sort, write #define at the top and put \ at the end of every line.

Every time C/C++ speed comparisons are mentioned, someone brings up this argument. It's such a ridiculous esoteric special case; in practice the 'possible inlining' is radically overshadowed by template bloat causing shitty cache performance.

Name: !iN.MY.aRMs 2010-02-16 1:17

take qsort.c replace data type with MACRO and get same speed as C++ anal shablons
or use FORTRAN77

Name: Anonymous 2010-02-16 1:35

>>8
why fortran77?

Name: Anonymous 2010-02-16 1:48

>>9
The forced 80 column lines fit in the cache better

Name: Anonymous 2010-02-16 2:35

>>10
Heh. IIRC from my particle simulation days, Fortran77 is 72 columns, not 80. I learned the column limits the very hard way; it truncated a variable name in a math expression, and since you don't need to declare variables before using them, the truncated variable name was treated as a new variable with value zero. Spent fucking ages trying to figure out why my results were wrong.

Name: Anonymous 2010-02-16 6:25

FORCED LINE BREAKING OF CODE

Name: Anonymous 2010-02-16 7:38

sort in CL is quite nice: it can sort a sequence( a list, some kind of vector whose internal representation can vary (such as boxed, unboxed, displaced, depending on what your implementation supports), or even a custom sequence (again, if implementation supports)) using a user-given predicate(either your own, or builtins like >, <, string> and so on), it can also apply a keying function to the array, which allows you to filter elements individually in some way without actually modifying them (result is used when comparing). It's very easy to use(like: (sort sequence #'<)), picks a better algorithm depending the underlying sequence (qsort is good for arrays, but not so smart for linked lists, since random access costs O(n), not O(1)). Obviously, one can always implement a superior sort if they so wish, but this is pretty good. And whoever mentioned inlining being a problem: it's pretty easy to do in CL, just declare the function as inline, and you can also do local declarations if you want a declaration to not apply or apply to a specific block of code.

Name: Anonymous 2010-02-16 7:47

>>13
shitposting

Name: Anonymous 2010-02-16 8:15

>>11
It should be 77 columns.

Name: Anonymous 2010-02-16 16:06

Pointers are unsafe.

Name: Anonymous 2010-02-16 16:16

>>16
So is sex

Name: Anonymous 2010-02-17 15:37

>>17
So is ide

Name: Anonymous 2010-11-13 23:54

Name: Anonymous 2011-02-02 22:36

Name: Anonymous 2011-02-17 20:28

that's cool and all, but check my doubles over there

Don't change these.
Name: Email:
Entire Thread Thread List