Re: How can I create a 2D ArrayList? String usually.

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Dan V. (danv_at_yah.com)
Date: 06/10/04


Date: Thu, 10 Jun 2004 09:54:19 -0400

Thanks for the informative reply.
I basically would like a 2 column array or whatever that will be static, as
in values won't change after I load them and I would like to fairly quickly
search for a value in either column and either: 1. See if the value exists
or 2. get the value in the other column. I like the features of ArrayList
where you can add info easily initially and use IndexOf to quickly find if
value exists and if it does to get the other value. Basically something
faster than a DataTable and a query everytime. A Hash table would be
overkill for me at this point.

"J.Marsch" <jeremy@ctcdeveloper.com> wrote in message
news:OrAjzynTEHA.4048@TK2MSFTNGP12.phx.gbl...
> I don't think that you can use the ArrayList class for a rank 2 array - it
> only seems to manage a single dimensional array. For what it's worth, the
> DataRowCollection uses an arraylist for its underlying storage (based on
> what I've seen in Reflector).
>
> I'm not entirely sure that I understand what you are after, but you might
> try using the Select() method on the datatable -- I believe that it uses
> some built-in indexing to return rows. Or, if what you are doing is more
> custom than that, you might experiment with using a HashTable rather than
> using Array.IndexOf.
>
> Array.IndexOf is probably going to yield linear performance as you add
items
> to the array (unless you are doing sorting/binary searches). However, a
> HashTable yields sublinear performance. I was load testing a
> NameObjectCollectionBase derivitiave (which uses a HashTable under the
> covers) for some performance testing, and found that it made virtually no
> difference in avg lookup time between a collection of 100,000, and
1,000,000
> members (avg time on my machine with 1,000,000 entries in a
> NameObjectCollect -- basically a HashTable -- was around 0.0000013 seconds
> per access).
>
> Which is better (HashTable vs. DataTable.Select()) probably depends upon
how
> you are doing your searches. If you load up your datatable first, and
then
> search, I would guess (but it is a guess) that you could get by with
> DataTable.Select. However, if you are searching as you load (duplicate
> checks or something), you might be better off using hashtables. When we
> were doing testing, we found that the datatable indexes seem to be rebuilt
> any time you do a select after an add, so add | select | add | select,
> wasn't a great option for some dup checking algorithm that someone here
was
> working on.
>
>
> "Dan V." <danv@yah.com> wrote in message
> news:ezhX0llTEHA.3140@tk2msftngp13.phx.gbl...
> > I would like to create a 2D string list (2D ArrayList ???). I would
like
> to
> > pass in a table or query as a parameter and have both columns transform
> into
> > a 2D ArrayList. When I sort the one 'column' in the ArrayList, the
other
> is
> > automatically sorted and so I can use IndexOf without fear. This is
> because
> > I will be going through 20,000 some odd records and don't want to use a
> > Lookup type of table/query; I figure an ArrayList.IndexOf method is
> faster.
> >
> >
>
>



Relevant Pages

  • Re: How can I create a 2D ArrayList? String usually.
    ... I don't think that you can use the ArrayList class for a rank 2 array - it ... If you load up your datatable first, ... you might be better off using hashtables. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: fast stable sort
    ... For fastest load, at expense of slower sort, you ask the operating ... and you memory-map the file directly into that array. ... memory of your big array. ... possible to assure locality of reference and thus avoid thrashing ...
    (comp.programming)
  • Re: Controller for Switching current sink
    ... The load, includes ... the switch closed with my monster-FET array. ... So, I'm gonna precharge the cap, then throw the switch at 0v. ... I calculate 1.5 joules in the cap, so the fet has to dump the same 1.5 ...
    (sci.electronics.design)
  • Re: problem with [array get ...] -> file -> string -> [array set ...]
    ... I'm pulling my hair out trying to save and load data to a file. ... got a large array (probably filled with all sorts of "special" ... puts "saving test to test.save" ...
    (comp.lang.tcl)
  • Re: Hashtable or array of structs?
    ... > implement the cache as an array of structs. ... If I understand this correctly you will need three arrays / hashtables for ... Make the hashtables store pointers to reduce memory overhead and avoid ...
    (comp.lang.c)