Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Generally, if you must have the BEST indexed lookup performance it's best to build a List first and then turn it into a array thus paying a small penalty at first but avoiding any later. If the issue is that you will be continually adding new data and removing old data then you may want to use a ArrayList or List for convenience but keep in mind that they are just special case Arrays. When they "grow" they allocate a completely new array and copy everything into it which is extremely slow.</p> <p><a href="http://blogs.msdn.com/bclteam/articles/273454.aspx" rel="nofollow noreferrer">ArrayList</a> is just an Array which grows when needed. Add is amortized O(1), just be careful to make sure the resize won't happen at a bad time. Insert is O(n) all items to the right must be moved over. Remove is O(n) all items to the right must be moved over.</p> <p>Also important to keep in mind that List is not a linked list. It's just a typed ArrayList. The List <a href="http://msdn.microsoft.com/en-us/library/6sh2ey19.aspx" rel="nofollow noreferrer">documentation</a> does note that it performs better in most cases but does not say why.</p> <p>The best thing to do is to pick a data structure which is appropriate to your problem. This depends one a LOT of things and so you may want to browse the <a href="http://msdn.microsoft.com/en-us/library/system.collections.generic.aspx" rel="nofollow noreferrer">System.Collections.Generic</a> Namespace. </p> <p>In this particular case I would say that if you can come up with a good key value <a href="http://msdn.microsoft.com/en-us/library/xfhwa508.aspx" rel="nofollow noreferrer">Dictionary</a> would be your best bet. It has insert and remove that approaches O(1). However, even with a Dictionary you have to be careful not to let it resize it's internal array (an O(n) operation). It's best to give them a lot of room by specifying a larger-then-you-expect-to-use initial capacity in the constructor. </p> <p>-Rick</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload