in reply to Re^6: Array VS Linked List (reality)
in thread Array VS Linked List

I'll concede that splice, as currently implemented, is O(N) (much as I hate to say that).

That said, splice, shift, and unshift could all become O(1) if the following were to happen:

I suppose I could write up a Tie::Array that would do this. In thinking about it, this may sound like a proper solution for DBM::Deep's arrays. What do you think?


My criteria for good software:
  1. Does it work?
  2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?

Replies are listed 'Best First'.
Re^8: Array VS Linked List (reality)
by gleepglop (Novice) on Nov 16, 2007 at 22:41 UTC
    I don't believe that bookkeeping would work very well. I think with very many inserts you'd quickly end up with nothing more than a linked list that wastes a a lot of memory. But I would honestly be delighted if you could prove me wrong. I'm not completely sure I'm right, I just haven't been able to come up with an algorithm in my head that would really make sense. I mean, I am wrong a lot, an awful lot of the time, but I'm going out on a limb here and saying there's no way you can implement that random access linked list you're talking about there. It would be squirrelly as all get-out, and it would quickly devolve into a mess where the accesses are indeed O(n). So I dare you to try and implement an example.