3 ms·
Is there a reason the keep the data and the indices in different arrays? Unless you're navigating to an item by its position in the linked list, you're going to
by ziml77 4y ago
Is there a reason the keep the data and the indices in different arrays? Unless you're navigating to an item by its position in the linked list, you're going to be checking the data at each node and then reading the next index to traverse forward. Since you're reading both, wouldn't it be better to make the index of the next node intrusive?
- marginalia_nu 4y agoThe design is mostly to provide a clear enough example, you can of course interlace them. It depends on the use case. If you're doing a lot of navigating over links before you reach the destination, maybe you want them separate. Could also be the data is large, even maybe stored on disk while the links are in memory, or whatever. There's a thousand different scenarios with different optimal arrangements.
- magicalhippo 4y agoIt allows you to reorder the data, say sorting it, without moving the actual data. If the element type is say a struct, this can be a huge performance win. It also allows you to keep multiple different lists to the same data, say sorted by different fields in the struct.