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

Pages: 1-4041-

feel thread

Name: Anonymous 2012-06-03 13:58

that feel when your handwritten linked_list in C is 5 seconds faster than the STL

Name: sage 2012-06-03 15:44

1/10

Name: Anonymous 2012-06-03 15:45

>>1
So, feels good or something?

Name: Anonymous 2012-06-03 16:14

critique


#include <stdio.h>
#include <string.h>
#include <malloc.h>

struct node_t
{
    int key;
    struct node_t * next;
};

typedef struct node_t node_t;

void list_init(node_t ** head, node_t ** tail, int head_key)
{
    *head = (node_t *) malloc(sizeof(node_t));
    *tail = (node_t *) malloc(sizeof(node_t));

    (**head).next = *tail;
    (**tail).next = *tail;

    (**head).key = head_key;
    (**tail).key = 0;
}

void list_destroy(node_t ** head, node_t ** tail)
{
    node_t * iter = NULL, * temp_next = NULL;

    //traverse and free
    for(iter = *head; iter != *tail; iter = temp_next)
    {
        temp_next = iter->next;
       
        free(iter);
        iter = NULL;
    }
}

node_t * list_insert_after(int key, node_t * before_this)
{
    node_t * this_list = (node_t *) malloc(sizeof(node_t));
    this_list->key = key;
   
    this_list->next = before_this->next;
    before_this->next = this_list;

    return this_list;
}

void list_remove_after(node_t ** before_removed)
{
    node_t * to_remove = (**before_removed).next;
   
    (**before_removed).next = to_remove->next;
    free(to_remove);
}


int main()
{
    node_t * head=NULL, * tail=NULL, * iter=NULL,
        * node1=NULL, * node2=NULL, * node3=NULL, * node4=NULL;
   
    list_init(&head, &tail, 5);
    node1 = list_insert_after(2, head);
    node2 = list_insert_after(9, node1);
    node3 = list_insert_after(7, node2);
    node4 = list_insert_after(8, node3);
    //list_remove_after(&node1);
    for(iter = head; iter != tail; iter = iter->next)
    {
        iter->key++;
    }
    //printf("%d\n", head->next->key);
    list_destroy(&head, &tail);
    return 0;
}

Name: Anonymous 2012-06-03 16:20

>>4
Oh the bloat! This is all you really need:
typedef struct _qListNode
{
    int elem;
    struct _qListNode * next;
}qListN;

void addItem(int item, qListN * listop)
{
    qListN * head = listop;
    while(listop->next != 0) listop = listop->next;
    listop->elem = item;
    listop->next = (qList*)calloc(1,sizeof(qListN));
    listop->next->next = 0;
    listop = head;
}


Removal and sorting can be done when operating on the list and doesn't need a dedicated function.

Name: Anonymous 2012-06-03 18:33

5 seconds faster regardless of number of elements is pretty badass

Name: Anonymous 2012-06-03 19:11

>>6
the 5 seconds is for STL to load into memory

Name: Anonymous 2012-06-03 20:10

>>5
half-assed

Name: Anonymous 2012-06-03 21:38

>>4
Identifiers ending in _t are reserved in the POSIX standard. You should not use them if you have any reason for your code to be POSIX compliant.

Name: Anonymous 2012-06-04 2:40

Name: Anonymous 2012-06-04 3:48

>>4
new to programming, are we?
either that, or you're just another nigger

Name: Anonymous 2012-06-04 4:08

>>11
Assfucker. Tsk.

Name: Anonymous 2012-06-04 4:47

My pet turtle is 5 times faster than STL

Name: Anonymous 2012-06-04 5:29

Once upon a time there lived a guy named STEPANOVSTEPANOV was a
JOKER.  That was his nature.  He loved to MAKE JOKES.  Unlike
STROUSTRUP and ALEXANDRESCU he was mentally healthy, and, naturally,
hated C++ with all his heart.  Once STEPANOV MADE a really tough JOKE.
He drugged himself hard and wrote STLSTL turned out to be comically
absurd.  STEPANOV spent a great deal of time laughing at the miserable
and stupid fecal matter that is C++, and considered his STL merely a
grotesque joke.

STEPANOV had already forgotten about STL, but suddenly he was summoned
to a session of Standartisation Committee.  When STEPANOV left the
building he started laughing like crazy.  ``These fucktards!'' ---
thought STEPANOV, convulsing in laughter.  ``They included STL into
the standard, holy fucking shit''.  He couldn't stop laughing and fell
to the floor.  The laughter didn't leave him even on the floor.  Its
sound shifted from normal human laughter to a dreadful mix of crows
croaking and rhinos vomiting.  Because of the laughter STEPANOV got
arrhythmia and had to call a doctor.  When he returned home, he didn't
laugh anymore, because he imagined the terrible consequences of his
JOKE.  It finally occured to STEPANOV that actual living humans will
be writing STL code.  And what if someone gets inspiration from STL
and invents something even more idiotic?  STEPANOV knew that STL is a
JOKE, but there definitely are people who can take it seriously.
STEPANOV didn't know what to do.  But, being a JOKER, he decided to
play his classic: KNOCK-ON-STROUSTUP'S-DOOR-AND-RUN-AWAY.  STEPANOV
giggled at the thought of such COMEDY, because STROUSTUP, like a
retarded cow, always bought it.  He went to STROUSTRUP's house and hid
behind a bush.  Nobody saw him, and he was ready to walk up to the
house and knock, but suddenly he saw LAMBDA approaching the house.
STEPANOV liked LAMBDA.  They often had a drink together, and were good
friends.  But STEPANOV didn't want to spoil his JOKE and didn't reveal
himself.  Amusingly, LAMBDA flew up to the house, knocked on the door,
and then hid herself under the stairs.  When STEPANOV saw it he was
slightly disappointed because LAMBDA stole his trademark trick.  But
then he recalled that LAMBDA promised to do so to avenge her inclusion
into the STANDARDSTEPANOV crawled out of the bushes and went home.
He was in a dark mood.  He knew that STROUSTROP does evil things, but
couldn't make himself do something about it.  ``At least this son of a
bitch ALEXANDRESCU is in the mental clinic'' --- thought STEPANOV.  He
felt that something will have to be done now that the STL is included
into the STANDARD.  He needed only a single spark.  But, suddenly, he
saw his friends, PAUL GRAHAM and PETER NORVIG.  The three started
discussing something furiously, looking around cautiously.  They
traded news.  STEPANOV now knew that ALEXANDRESCU was discharged from
the mental clinic, GRAM and NORVIG found out that STL was included
into the STANDARD.  They expected these times long ago, and it was
decided that it is the time for extreme measures.

Name: Anonymous 2012-06-04 5:46

>>1
but uses 5 times the memory STL uses
dat feeeel

>>5
you do realize however that your solution does STL-tier times.

Name: Anonymous 2012-06-04 6:19

that feel when you realize you can safely throw away a shitton of useless code that took your colleagues months to assemble.

Name: Anonymous 2012-06-04 7:26



STROUSTRUP posted a story to 4chan and climbed onto his mommy.  He
didn't yet find out that she is long gone.  The only thing he noticed
is that she started smelling funny, but it only turned him on.  Also,
his mommy was moaning passionately when he was furiously fucking her.
He did not understand that these ``moans'' are actually sounds of
putrefaction gases escaping through various orifices.  STROUSTRUP felt
a hit to his head and lost consciousness.

ALEXANDRESCU, beaten up and covered in excrement, approached his
house.  Suddenly, three masked men grabbed him.  The last thing he saw
was a gauze soaked in chloroform near his face.  Then everything went
dark.

Name: Anonymous 2012-06-04 7:33

that feel when black jewish feminist pythonistas on proggles

Name: Anonymous 2012-06-04 11:52

Russians and C++ go hand in hand.

Name: Anonymous 2012-06-04 12:00

HE PLUGS IT INTO A DUCK? WHAT A WEIRD KID.

http://www.youtube.com/watch?v=tj8BoOYvo00

Name: Anonymous 2012-06-04 12:06


STROUSTRUP and ALEXANDRESCU woke up in a dark wet basement.  STEPANOV
noticed it and turned on the light.  NORVIG walked up to them and
yanked cloth potato bags from their heads.  STROUSTRUP and
ALEXANDRESCU understood everything.  Awareness of imminent end
instantly came to them.  STEPANOV and GRAHAM held a brief dialogue:

 --- Bring out the ugly bastard.
 --- The ugly bastard is asleep.
 --- Then wake him up, duh.

GRAHAM went up to a door and opened it.  Behind the door there was a
1x1 m space with a man in a leather costume and a mask.  GRAHAM
casually kicked the person, who woke up and asked for water.  ``Here
you go, drink it!'' --- said GRAHAM and urinated on the person's face.
STEPANOV kicked the person out of the small enclosure into the center
of the basement room and said: ``Dig, bitch.''  The person started
digging.  After 10 minutes the pit was ready.  STEPANOV took out a
large caliber Magnum and pointed it at the person.  STEPANOV told
GRAHAM to take the leather mask off the person.  STROUSTRUP and
ALEXANDRESCU inhaled loudly in fear.  They knew this man.  STEPANOV
aimed carefully at the person's head and pulled the trigger.  Brains
were thrown out of his head and all over the walls, and the lifeless
body fell into the pit.  STEPANOV observed it all with a smile of a
true JOKER.  Then he looked at NORVIG and GRAHAM and said:

 --- Bury SUTTER while I finish these two shits.

NORVIG and GRAHAM started working.  STEPANOV, mimicking the gait of
Madsen from Reservoir Dogs, walked up to STROUSTRUP and ALEXANDRESCU.
Both were gazing at the floor in silence.  STEPANOV took out a KATANA
and, with the zeal of the author of STL, sliced up both of them.

STEPANOV, NORVIG and GRAHAM stood above the bodies.

STEPANOV broke the silence and suggested feeding the corpses to pigs.
STEPANOV then walked up the stairs to the first floor and continued to
write a DSL in COMMON LISP.

Name: Anonymous 2012-06-04 12:07

who want a may tricks? it will trick you if you not careful. you'll think you got a rectangular may trick and it turn out you got a triangle on your hands.

http://www.youtube.com/watch?v=KlPC3O1DVcg

so expert, why is mr. physicist not want to learn to be programmer?

me and dennis ritchie use to play TWO doors down mr. expert. u fink u cleverer dan me?

Name: Anonymous 2012-06-04 13:01

>>11
what's wrong with it?

Name: Anonymous 2012-06-04 13:31

that feel when you smoke weed everyday because it makes programming less annoying

Name: Anonymous 2012-06-05 10:49

>>24
Never thought about it.  Programmers aren't tested for drugs in my company, so it might even make me a better employee, as I will spend less time raging.

Name: Anonymous 2012-06-05 10:51

>>25
Enjoy your lack of motivation, concentration, sanity and social skills.

Name: Anonymous 2012-06-05 11:03

>>26
Thanks, my MSGful ramen soup never tasted better!

Name: Anonymous 2012-06-05 11:12

>>1,4
Hey OP, here's my list implementation in C++11, minus a few routines.

http://codepad.org/zPovb3LR

Allocation of nodes is outside of the scope of the library, it's left up to the user, that way they can use different allocation strategies. Concrete implementations have their node structs inherit the base list_node type. I use templates and lambda functions to generalize a few algorithms where the actual node type needs to be known.

struct log_sink_node : list_node
{
    log_handler handler;
    void* user_data;
    unsigned int min_level;
    unsigned int max_level;
    char category[196];
};

list_foreach<log_sink_node>(&context->sinks_head, [&](log_sink_node* sink) {
    if ( (sink->category[0] == '\0' || !strcmp(sink->category, record.category))
        && (sink->min_level <= record.level) && (record.level <= sink->max_level)
    ) {
        sink->handler(&record, sink->user_data);
    }
});

list_clear<log_sink_node>(&context->sinks_head, [](log_sink_node* sink) {
    free(sink);
});

Name: Anonymous 2012-06-05 11:17

>>1
Learn to use STL properly ``faggot''

Name: Anonymous 2012-06-05 11:23

>>29
The problem is that both the libstdc++ and Dinkumware (used by MSVC/ICC) Standard C++ Library implementations are shit, full of slow as fuck code-paths, and it results in bloated code. STLport and Apache stdcxx don't support C++11. Clang's libc++ is much better, but it's still incomplete and a work in progress.

Name: Anonymous 2012-06-05 12:23

>>28
That's fucking hot

Name: Anonymous 2012-06-05 13:23

>>28
ten minutes and still puking.

Name: Anonymous 2012-06-05 13:30

Why? That's the C way of doing things, with a few extra C++ language features. Everything other way of doing it is bloated as fuck. Even Lisp, it's slow as shit underneath.

Name: Anonymous 2012-06-05 14:51

>>32
You forget that C and the C subset of C++ are essentially a ``portable assembler.'' It's not supposed to look good, it's supposed to run fast with no or little overhead, once compiled for the target platform. That's what his code does. It's not supposed to look pretty or elegant like Lisp. Just because your sexprs look so clean doesn't mean that it runs fast.

Sometimes you need raw performance, and that's when you get your hands dirty with C or C++ and even a bit of assembly or compiler intrinsics for hardware specific instruction sets.

Name: Anonymous 2012-06-05 16:21

>>34
When I want to use assembler, I use assembler.

Name: Anonymous 2012-06-05 16:28

>>23
well you haven't really decide what kind of list you want, and at the same time you are trying to semi-sort nodes.Which is kinda weird

Name: Anonymous 2012-06-05 16:37

>>35
Assembler is the program that assembles assembly, not the language it assembles.

Name: Anonymous 2012-06-05 17:04

>>35
When I want to use a portable assembly language, I use C.

Name: Anonymous 2012-06-05 17:39

This thread needs more FIOC

class LinkedNode(object):
    def __init__(self, data=None):
        self.data = data
        self.link = None

    def __iter__(self):
        return self

    def next(self):
        if not self.link:
            raise StopIteration
        return self.link

    def append(self, data):
        after = self.link
        self.link = LinkedNode(data)
        self.link.link = after

    def delAfter(self):
        if self.link:
            self.link = self.link.link

Name: Anonymous 2012-06-05 18:10

>>37
Sorry. English is my third language.  We good?

>>38
Too bad it's riddled with plenty of undefined behaviour that makes it utterly useless.

Name: Anonymous 2012-06-05 18:55

>>39
FIOC
now it will take 5 seconds per node

Name: Anonymous 2012-06-05 19:17

hey prog sup?

Name: Anonymous 2012-06-05 19:17

e

Name: Anonymous 2012-06-05 19:18

<--- dubs check 'em

Name: Anonymous 2012-06-06 4:37

>>26
Enjoy your lack of motivation, concentration, sanity and social skills.
I don't have any of those things without weed either

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