C
1
Name:
Anonymous
2011-01-27 4:38
strlen(3) is FUCKING O(n)!
2
Name:
Anonymous
2011-01-27 4:50
Nothing wrong here.
3
Name:
Anonymous
2011-01-27 4:56
Wow, they must use an expert algorithm
4
Name:
Anonymous
2011-01-27 5:02
What is the complexity of your strlen (3)?
5
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_;
//...
};
6
Name:
Anonymous
2011-01-27 5:36
warning: passing argument 1 of ‘strlen’ makes pointer from integer without a cast!
7
Name:
Anonymous
2011-01-27 5:39
>>5
virtual std::size_t length() const
8
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.
9
Name:
Anonymous
2011-01-27 6:11
>>8
Get the fuck back to Pascál.
10
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)
11
Name:
Anonymous
2011-01-27 7:25
O(1) = autism
12
Name:
Anonymous
2011-01-27 10:51
printing from 1 to n! is fucking O(n!)!!!!!1
13
Name:
Anonymous
2011-01-27 10:54
>>8
it requires two memory access for each character fetch!!!11!
14
Name:
Anonymous
2011-01-27 10:58
15
Name:
Anonymous
2011-01-27 11:06
16
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 )
17
Name:
Anonymous
2011-01-27 19:28
18
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
19
Name:
Anonymous
2011-01-27 20:01
>>18
Forgot my add my
#pragma OMG_OPTIMIZED(9001) at the top of the file. Apologies.
20
Name:
Anonymous
2011-01-27 20:16
21
Name:
Anonymous
2011-01-27 20:18
22
Name:
Anonymous
2011-01-27 20:19
>>21
BACK TO MY ANUS, VIPPER .
23
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.
24
Name:
Anonymous
2011-01-27 20:22
25
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.
26
Name:
Anonymous
2011-01-27 20:28
>>25
see
>>8 to understand
>>23
27
Name:
>>25
2011-01-27 20:29
string[1]
Should read string[sizeof(int)].
28
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.
29
Name:
Anonymous
2011-01-27 20:37
/*!
What is this abomination.
30
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
31
Name:
Anonymous
2011-01-27 20:41
32
Name:
Anonymous
2011-01-27 20:55
Little did you know, but the "hax my anus" ``meme'' came from /g/.
33
Name:
Anonymous
2011-01-27 21:06
>>32
That's why it sucks, but I like the word ''anus´´.
34
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.
35
Name:
Anonymous
2011-01-28 4:30
>>34
I already wrote it when I was 12. It also had continuations and lambdas.
36
Name:
Anonymous
2011-01-28 4:58
>>35
Hello,
Benjamin Button .