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

Pages: 1-

C

Name: Anonymous 2011-01-27 4:38

strlen(3) is FUCKING O(n)!

Name: Anonymous 2011-01-27 4:50

Nothing wrong here.

Name: Anonymous 2011-01-27 4:56

Wow, they must use an expert algorithm

Name: Anonymous 2011-01-27 5:02

What is the complexity of your strlen (3)?

Name: Anonymous 2011-01-27 5:25

>>4
Mine is running in O(1)

class string
{
//...
std::size_t length()
{
  return length_;
}

std::size_t length_;
//...
};

Name: Anonymous 2011-01-27 5:36

warning: passing argument 1 of ‘strlen’ makes pointer from integer without a cast!

Name: Anonymous 2011-01-27 5:39

>>5
virtual std::size_t length() const

Name: Anonymous 2011-01-27 5:59

>>4
Mine is O(1)


struct string {
    char *data;
    size_t length;
};


The char *data is first because I can just do (char *)string to pass it as a normal char pointer.

>>1 is bloated shit.

Name: Anonymous 2011-01-27 6:11

>>8
Get the fuck back to Pascál.

Name: Anonymous 2011-01-27 6:24

>>9
Enjoy yo'ure O(n) strlen(3). (Also, in Paskell, they usually put the length before the data)

Name: Anonymous 2011-01-27 7:25

O(1) = autism

Name: Anonymous 2011-01-27 10:51

printing from 1 to n! is fucking O(n!)!!!!!1

Name: Anonymous 2011-01-27 10:54

>>8
it requires two memory access for each character fetch!!!11!

Name: Anonymous 2011-01-27 10:58

>>13
wat

Name: Anonymous 2011-01-27 11:06

>>13
OPTIMISE YOUR CODE

Name: Anonymous 2011-01-27 19:06

class string
{
//...
std::size_t length()
{
  return length_ / 2;
}

std::size_t length_;
//...
};


suck that faggots, O(1/2)

Name: Anonymous 2011-01-27 19:28

>>16
FAGGOT

Name: Anonymous 2011-01-27 19:58

>>16

/*!
 * string.hpp
 * A basic string class.
 * \author John van der Haeden van der Vogen
 */

typedef char* CharacterPointer;
typedef unsigned int UInt_t;

namespace std
{
class String
{
    // stuff

    /// Returns the length of the string (number of characters)
    /// Side effects: none.
    public: const UInt_t Length() const
    {
        return 4; // Chosen by running tests with strlen()
        // Seems to always return 4 with the test string
        // we used.
    }
    private: CharacterPointer _data;
} // class String
} // namespace std

Name: Anonymous 2011-01-27 20:01

>>18
Forgot my add my #pragma OMG_OPTIMIZED(9001) at the top of the file. Apologies.

Name: Anonymous 2011-01-27 20:16

>>19
9001
Back to /b/.

Name: Anonymous 2011-01-27 20:18

>>20
Back to bed, Timmy.

Name: Anonymous 2011-01-27 20:19

>>21
BACK TO MY ANUS, VIPPER.

Name: Anonymous 2011-01-27 20:19

I keep the length of my strings in a 32-bit field at the end, after the null byte.
That way I can easily pass them to functions that expect a standard C string.

Name: Anonymous 2011-01-27 20:22

>>23
see >>8

Name: Anonymous 2011-01-27 20:26

>>23
No, that's O(n + k) unless you pass two pointers. Keep it in string[0] and pass string[1] to library functions. Better yet, don't write code that calls strlen more often than it does something meaningful with the contents.

Name: Anonymous 2011-01-27 20:28

>>25
see >>8 to understand >>23

Name: >>25 2011-01-27 20:29

string[1]
Should read string[sizeof(int)].

Name: Anonymous 2011-01-27 20:31

>>26
Nah, >>8 sucks. Keeping it before the pointer means all the information can be found from the one char array, and in O(1) at that.

Name: Anonymous 2011-01-27 20:37

/*!
What is this abomination.

Name: Anonymous 2011-01-27 20:40

>>28
>>8 sucks
before the pointer


char *anus = malloc(256);
anus += sizeof(size_t);
#define len(x) ((size_t)(x)-(sizeof(size_t)))
len(anus) = 256;
myfaggotfunction(anus, len(anus));
free(anus-4);

vs

string anus = malloc(sizeof(string));
anus.length = 256;
anus.data = malloc(sizeof(anus.length));
myfaggotfunction((char *)anus, anus->length);
free(anus->data);
free(anus);


Yeah, it sucks, it consumes sizeof(*) more than yo'ure´s

Name: Anonymous 2011-01-27 20:41

>>30
* string *anus

Name: Anonymous 2011-01-27 20:55

Little did you know, but the "hax my anus" ``meme'' came from /g/.

Name: Anonymous 2011-01-27 21:06

>>32
That's why it sucks, but I like the word ''anus´´.

Name: Anonymous 2011-01-28 0:10

>>33
That's a phase many five-year-olds go through. Don't worry, you'll grow out of it before you write your first C compiler and your balls drop.

Name: Anonymous 2011-01-28 4:30

>>34
I already wrote it when I was 12. It also had continuations and lambdas.

Name: Anonymous 2011-01-28 4:58

>>35
Hello, Benjamin Button.

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