In consideration of modern architectures and memory layout, are linked data structures ever worth it?
It feels like an dynamic array is a lot better in every sense.
Name:
Anonymous2011-12-13 8:06
>>39
How are you certain that 2147483647 isn't a valid value for an element in the array?
Name:
F r o z e n V o i d !!mJCwdV5J0Xy2A212011-12-13 8:23
>>41
because its defined to treat any integer which is ARRAY_NULL as invalid value which would trigger an error(actually just add debug message to console, i don't intend to interrupt it unless data is being corrupted)
>>34
C/C++ looks like shit. Thank you, but I'll stick with Lisp.
Name:
Anonymous2011-12-13 11:38
i dont believe op understands the differences between linked lists and dynamic arrays properly
or he is a troll...
Name:
Anonymous2011-12-13 12:32
>>20'
>In case you need fast search:
>1.sort the array. Should be pre-sorted if you want maximum speed.
>2.binary search the array. O(Log N) at worst case O(1) at best
1) Not O(1) at best O(n*log(n))
2) I can bet you your binary search will average over more towards O(log(n)) than O(1) since O(1) requires you to pick something right in the middle
3) Overall you're looking at O(n*log(n)*log(n)) worst case when you need to search for something or O(n*log(n)) at best case
'Insert into array is 2 stage operation:
1.find first empty/deleted slot(fileld with NULL values)
2.overwrite it with your value
1) Not O(1)
You truly are retarded, may i suggest going back to your self-proclaimed expert programmers reddit page and never coming back. I'm sure you can keep yourself company there.
Name:
Anonymous2011-12-13 12:34
>>29 Queues do very well as dynamic arrays, what is your point?
You enjoy O(n) pop/poll everytime?
>>50,51
Except that you can just treat the array as a circular buffer and only need to reallocate when you run out of allocated space, everything else is O(1) and the reallocation stages are amortized O(1).
Just because you're too retarded to do something as simple as use an array for a queue doesn't mean everybody else is, arrays severely outperform linked structures when it comes to things like deques, stacks and queues.
Name:
Anonymous2011-12-13 16:18
>arrays severely outperform linked structures when it comes to things like deques,stacks and queues
[citation required]
Name:
Anonymous2011-12-13 18:07
>>53
They're both O(1) at end-point push, enqueue and pop, but on modern architectures dynamic arrays are more cache efficient and have better locality of reference, so the constant is lower.
Name:
Anonymous2011-12-13 19:25
I wrote a small test, everything is one giant file so FrozenVoid should be happy. I wrote it so that the structures are easily extensible with O(1) peek and size operations and O(n) contains.
>>34 Here is example of Bitmap struct as array:
Here is example of a Bitmap "struct array" as a struct: struct Bitmap {
char magic[2];
uint32_t crfilesize, dummy, bitmapoffset, bhsize, w, h;
uint16_t bitplanes, bitsperpixel;
uint32_t compression, imagesize, xppm, yppm, numcolors, impcolors;
int32_t colors;
char padding[n]; //pad until STDOFFSET
int32_t pixels;
};
Now if you have a compiler that isn't crap, you can do this: bitmap = (struct Bitmap){
.magic = "BM",
.crfilesize = FILESIZE,
.bitmapoffset = STDOFFSET,
.bhsize = HEADERINFOSIZE,
.w = DEFWRES,
.h = DEFHRES,
.bitplanes = 1,
.bitsperpixel = BITSPERPIXEL,
.compression = 0,
.imagesize = SIZE,
.xppm = STDPPM,
.yppm = STDPPM,
.numcolors = 256,
.impcolors = 256
};
double off = 0;
uint32_t currframe = 0;
uint32_t i,c,m;
uint32_t x,y,height = bitmap.h, width = bitmap.w;
>>64 No initializer shall attempt to provide a value for an object not contained within the entity being initialized. The language here is awful. "contained"? Really?
>>66
Because the total number of elements is unknown, and it would make the proponents of linked data structures even more mad if the array stack got even faster.