Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / .NET SDK / December 2004

Tip: Looking for answers? Try searching our database.

Remove Hashtable Values Based on DateTime?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
localhost - 17 Dec 2004 03:43 GMT
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?

Thanks.
Jon Shemitz - 17 Dec 2004 06:44 GMT
> 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?

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.

Signature

programmer, author  http://www.midnightbeach.com
and father          http://www.midnightbeach.com/hs

localhost - 17 Dec 2004 14:50 GMT
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?

>> 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
[quoted text clipped - 3 lines]
>structures. Each has a Key and a Value. If the Value is an expired
>DateTime, then Remove() the Key.
Jon Shemitz - 17 Dec 2004 19:10 GMT

> >> 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
[quoted text clipped - 9 lines]
>
> Would I be better off using a DataTable or an ArrayList?

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.

Signature

programmer, author  http://www.midnightbeach.com
and father          http://www.midnightbeach.com/hs


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.