Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 18th, 2007, 12:15 PM   #1
Druid
Programmer
 
Join Date: Mar 2006
Posts: 40
Rep Power: 0 Druid is on a distinguished road
C# Comparing Timestamps to Timer Value

I have a timer in one of my forms, then an ArrayList of timestamps. I am curious as to if there is a more optimized way to see if the timer value equates to one of the entries in the timestamp array without having to call a comparison function each time the interval ticks.

The timestamps will more than likely never exceed 5. But calling a function to compare the timestamp list each time the interval of the timer triggers, seems to be a bit excessive. Is there a better way to do this?
Druid is offline   Reply With Quote
Old Apr 18th, 2007, 9:39 PM   #2
lectricpharaoh
Caffeinated Neural Net
 
lectricpharaoh's Avatar
 
Join Date: Jun 2005
Location: Wet west coast of Canada
Posts: 1,120
Rep Power: 5 lectricpharaoh will become famous soon enough
Okay, I don't think there's enough information there for me to have a clear idea of your problem, so let me see if I have this right:

Your timestamp values can be thought of as nonzero integer values, and may represent the number of seconds, milliseconds, or whatever that have elapsed since some defined point in time.

Your timer ticks once every so often, and increments a counter. You want to compare this counter to see if it is equal to any of the timestamp values.

Here's how I might do it. First, sort the values, and put them into a collection. Then, when going through the list, you start at the beginning, and traverse it until you either reach the end, find a match, or hit a timestamp value that is greater than your counter. If a match was found, do whatever processing is needed. Whether you hit the end or find a match, save the index of this position for subsequent searches. If your collection can contain duplicate timestamp values, repeat the search (but note it will start from where the last one ended, so the performance should be good). Given that your timer count will only increment (well, until it wraps), you cannot find a match in elements you've already checked. New ones will be added to the collection at the end, assuming that new ones will have greater time stamp values.

If there will not be duplicate entries, you might want to consider a SortedList or similar collection; retrieval may be slower, but this a) allows you to associate the keys (timestamps) with whatever objects (files, for example), and b) do the operation with one retrieval. I'm not sure if this is appropriate for your application, but I figured I'd mention it.
__________________
And once again, Probability proves itself willing to sneak into a back alley and service Drama as would a copper-piece harlot.
- Vaarsuvius, Order of the Stick
lectricpharaoh is offline   Reply With Quote
Old Apr 19th, 2007, 4:52 PM   #3
Druid
Programmer
 
Join Date: Mar 2006
Posts: 40
Rep Power: 0 Druid is on a distinguished road
The timestamp values are strings, in a time format of HH:MMS stored in an ArrayList collection.

The time ticks once every second, each time it ticks, the ArrayList of timestamps is processed top-to-bottom to check for equality.

Your example is similar to high I am currently undergoing the process. Although, I don't store the index of the timestamp. I like the idea of a SortedList though, should make the search faster.

I'm beginning to think I'm splitting atoms. I mean the max amount of timestamps may be around 5, but definitely less than 10. My main concern was just making that comparison every second that the timer control ticks.
Druid is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Updating the database with the timer value Iftikhar ASP.NET 0 Dec 4th, 2006 10:22 AM
Computer Based Chess Timer ZeeMan Other Programming Languages 6 Oct 29th, 2006 10:43 PM
Timer Isues crawforddavid2006 C# 9 Sep 20th, 2006 1:45 AM
.NET Timer Form closing issue MBirchmeier C# 4 Nov 21st, 2005 11:00 AM
How to program a timer? linuxpimp20 Other Programming Languages 9 Jul 5th, 2005 5:32 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 11:36 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC