Re: How to count value in a ArrayList
- From: Arne Vajhøj <arne@xxxxxxxxxx>
- Date: Sat, 24 May 2008 18:31:49 -0400
j1mb0jay wrote:
From reading the OP, i thought that they where inserting double values into a data structure and wanted to make sure that the value that they were adding was not already stored in the data structure. To me this means they will need to compare every insert item with ever single item in the list O(n). Doing this with a ArrayList is a lot slower than a hash table, as you could hash the double value to find out which linked list the value would be stored in, then just check the few values in the list.
That makes sense, but that was not the statement of yours we
disagreed with.
We disagreed with the suggestion that ArrayList was slower than
Hashtable due to the reallocate and copy at expansion of the backing
array.
When an array list is full is needs to be cloned to another larger array list. I thought that hash tables where are array of linked lists
It is not.
And I suspect it would be significant slower doing it that way. The
reason Hashtable is fast is the ability to lookup directly based on
hash value.
If the OP is using a ArrayList and would like to keep the items in order when inserting a new item this would mean moving all of items along one in the list, again another slow process, maybe a tree of some kind would be a better option.
ArrayList is not a good choice to insert sorted into.
I was always taught to stay away from ArrayList at all costs.
You were taugth wrong.
ArrayList (or List<> in newer .NET versions) is in most cases
a very good choice of data structure.
Arne
.
- References:
- How to count value in a ArrayList
- From: Tony
- Re: How to count value in a ArrayList
- From: Ignacio Machin ( .NET/ C# MVP )
- Re: How to count value in a ArrayList
- From: Arne Vajhøj
- Re: How to count value in a ArrayList
- From: Arne Vajhøj
- Re: How to count value in a ArrayList
- From: Peter Duniho
- How to count value in a ArrayList
- Prev by Date: Re: Encapsulation
- Next by Date: Re: Encapsulation
- Previous by thread: Re: How to count value in a ArrayList
- Next by thread: Re: How to count value in a ArrayList
- Index(es):
Relevant Pages
|