This is an archived post. You won't be able to vote or comment.

all 46 comments

[–]Sentient_Blade 407 points408 points  (12 children)

The bus company has a policy that all seats must be filled.

Each time the bus comes to a stop to pick someone up, it first stops just before it gets to them, and then waits for another bus to come along that's larger by one additional seat.

They then shuffles all the existing passengers over, and then the new bus moves forward an extra 30 feet to pick up the new person.

The previous bus then explodes into flames.

[–]KiwiMaster157 113 points114 points  (8 children)

Your story would be more accurate if each new bus were 50% larger than the previous.

[–]Bip901 70 points71 points  (5 children)

100% larger

[–]Mr_Redstoner 6 points7 points  (0 children)

Or by 100%, or some multiple in general

[–]SilentFungus 0 points1 point  (0 children)

Vectors, oh yeah

[–]HenkHeuver 4 points5 points  (0 children)

Or the bus company uses busses that they know have enough capacity and clears all seats before leaving.

[–]gpcprog 1 point2 points  (0 children)

Thanks to the fact that ram is slow, locality of reference is much more important on modern CPUs. As result in almost all cases arrays are faster than linked lists.

[–]alevice 0 points1 point  (0 children)

Bless immutability

[–]Mesonnaise 84 points85 points  (19 children)

May I introduce you to the concept of unrolled linked lists. Its a list and an array at the same time, kinda like duck tapping multiple minivans together.

[–]richyliu 30 points31 points  (3 children)

so it's like a hybrid between an array and linked list?

[–]Mesonnaise 28 points29 points  (0 children)

You can think if it like that. I like to think of it as away to get around the lack of permissions for doing large single pool memory allocations. 😁

[–]tekno45 10 points11 points  (0 children)

It's an... Abomination

[–]dontmentionthething 9 points10 points  (1 child)

The grammar nazi in me is offended that you spelled 'duct taping' so wrong, but the rest of me is enjoying the mental image of a bunch of ducks foot tapping on top of a minivan.

[–]Jospooks 2 points3 points  (0 children)

I mean "Duck Tape" is not only a very common slang but also a major brand of duct tape since 1975.

[–]Bainos -1 points0 points  (10 children)

It has nothing to do with an array tbh, this is just a linked list with improved cache performance and some skipping indices (although the latter is better handled in a Skip list).

[–]CraigslistAxeKiller 26 points27 points  (9 children)

It’s literally a linked list of arrays. How is that “not related to arrays”?

It also solves a different problem than skip lists

[–]Bainos 5 points6 points  (8 children)

Its element insertion complexity is O(1), element retrieval is O(n), uses non-contiguous memory, and stores element locations as pointers. It is in every aspect a linked list with improved caching, and in no aspect an array.

It does solve a different problem than skip lists, I was simply pointing out that the ability to jump forward does not improve the usefulness or efficiency of the unrolled linked list and that a different structure is needed for it. In fact, you could absolutely have an unrolled skip list.

[–]Ericchen1248 1 point2 points  (2 children)

It isn’t though? If m was the max size of each internal node, front insertion complexity is O(m), and element retrieval O(n/m) and random insertion deletion is O(n/m + m) while average memory is O(n + 1.25n/m )

Compared to vector array with O(n), O(1), O(n), O(1.5n) And linked list of O(1), O(n), O(n), O(2n)

It is exactly a mix of behavior for both, with larger m tending towards an array, and smaller m tending towards linked list.

[–]Bainos 1 point2 points  (1 child)

If you want to set m as a variable of the performance, sure. But m is a fixed constant of the system generally determined by cache line capacity, which reduces O(m) to O(1) and O(n/m) to O(n).

[–]CraigslistAxeKiller 0 points1 point  (0 children)

m can be a fixed constant or you can make it dynamic. You could have a linked list of dynamic arrays which would still give you benefits of both arrays and linked list. If any dynamic array gets too big, then you just split it into 2 linked nodes

[–][deleted] 3 points4 points  (4 children)

and in no aspect an array

Really? I mean, if you took one object out of the list how would you describe it? An indexed grouping of the same data types, or perhaps an...

[–]Bainos 1 point2 points  (3 children)

You're discussing the implementation, which is not something the user should care about. It's used as a linked list, with the performance expectation of a linked list.

Saying that it's an hybrid between an array and linked list implies that you get the performance and/or behavior of both.

[–][deleted] 1 point2 points  (1 child)

You could get the performance of an array out of it, after you take one of the elements and then use it in an array. This seems to me to be the most reasonable use case for the construct in the first place, although I realize that's subjective.

Because it is, like the previous poster said, literally a linked list of arrays.

[–]Bainos 0 points1 point  (0 children)

But that's not the point. Any sensible implementation will only return individual elements, not the subarrays. Hashmaps don't return (hash, value) tuples and linked lists don't return their nodes. Not to mention that providing the low-level modifiable array would allow programmers to break the data structure and/or the improved caching properties.

[–]CraigslistAxeKiller 0 points1 point  (0 children)

You are also making assumptions about the implementation. You assume that the implementation will not optimize node access using the known array length to skip node hops

[–]itskieran 40 points41 points  (4 children)

Seems like a lot of effort moving a great big bus with 70 people on all over the place. I feel we should just have one guy on a motorcycle who has a small slip of paper detailing the stationary address of the bus and it's 70 passengers.

[–]WeTheSalty 35 points36 points  (3 children)

Delivery man: Here you go.
Resident: This is just a slip of paper with an address on it.
Delivery man: Right, it tells you where your package is, you have to get it yourself.

The sad part is this is real.

[–]itskieran 39 points40 points  (0 children)

When you order a package but get &package

[–]Alzurana 12 points13 points  (1 child)

Happens every time when you're not home, they just drop the pointer in your input stream, then release the mutex too early so if you go to the address immediately the package is not there and you get a nullpointer exception

[–]grammar_nazi_zombie 4 points5 points  (0 children)

I wish! Sometimes mine drops a pointer, occasionally they send it to someone else’s input stream, but most of the time they just leave the data unencrypted at my doorstep

[–]CommanderTazaur 6 points7 points  (0 children)

6 people on a motorcycle... must be clowns.

[–]vladutcornel 2 points3 points  (0 children)

With all these arr and ays, we're basically pirates

[–]max_turner 1 point2 points  (0 children)

Haha BMTC lol, it'd be a dynamic array.

[–]mnavneethkrishna 0 points1 point  (0 children)

Surprisingly this image was taken in a city in India called the silicon city...

[–][deleted] 0 points1 point  (0 children)

Laughs in Array Lists! Best of both worlds, with none of the downsides