all groups > dotnet sdk > december 2004 >
You're in the

dotnet sdk

group:

Remove Hashtable Values Based on DateTime?



Re: Remove Hashtable Values Based on DateTime? Jon Shemitz
12/16/2004 10:44:21 PM
dotnet sdk: [quoted text, click to view]

Do a foreach on the Hashtable. You'll get a series of DictionaryEntry
structures. Each has a Key and a Value. If the Value is an expired
DateTime, then Remove() the Key.

--

programmer, author http://www.midnightbeach.com
Remove Hashtable Values Based on DateTime? localhost
12/16/2004 10:44:33 PM
I have a Hashtable with 1000 items in it, string key and DateTime
value. I want to find all that have a DateTime that are older than 30
minutes. How can I do that?

Re: Remove Hashtable Values Based on DateTime? localhost
12/17/2004 9:50:37 AM
I was under the impression that doing what you suggest is "slow" (put
in quotes because I know slow is always a relative term). What if I
have 5000 items? 20,000?

Would I be better off using a DataTable or an ArrayList?



On Thu, 16 Dec 2004 22:44:21 -0800, Jon Shemitz
[quoted text, click to view]
Re: Remove Hashtable Values Based on DateTime? Jon Shemitz
12/17/2004 11:10:04 AM
[quoted text, click to view]

Well, enumerating the Hashtable should be fast enough. There is
certainly some overhead in boxing and unboxing the DictionaryEntry
structure, but I'd expect that that's less than enumerating Keys and
reading each Hashtable[Key]. (Of course, my expectation may be wrong;
you should run some tests.)

I don't know what the performamce characteristics of a DataTable are
like; thankfully, I've managed to not yet need to touch a db from
..NET. But I find it hard to imagine that a table-based structure could
be faster than a simple, purpose-built data structure like a Hashtable
or ArrayList.

Could an ArrayList be faster? I'm sure it would be faster to walk the
list, looking for expired entries, but shifting 1000 (or 20,000)
key/value references to the left is going to be expensive - lots of
memory access at bus speed, and it'll purge the cache, too. Similarly,
finding your string Key is going to be a lot cheaper in a Hashtable
than in an ArrayList.

--

programmer, author http://www.midnightbeach.com
AddThis Social Bookmark Button