![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#11 | |
|
Professional Programmer
Join Date: May 2006
Location: UK - London
Posts: 330
Rep Power: 3
![]() |
Lect, I read through your pseudo code, it took a while for the penny to drop, but when it dropped it dropped good, as I saw that in proposal I was manipulating items that have not been de-queued (the whole subtraction thing), while with yours it was just comparing two times.
I got I more questions about this, what happens if I would like to remove an item from the queue, which is not at the head of the queue(It’s a requirement that an item can be deleted at any time, though i don't think it's a event that will frequently occur). I had two proposals, loop through each item (I know O(n)) and when you find the item delete it and re-heap from that point on. Or change the data structure to a balanced tree which enforces total order in which the above operation should be much faster. Or keep a list of deleted items and when an item is de-queued check if it’s in the deleted list.
__________________
Quote:
|
|
|
|
|
|
|
#12 | |||
|
Caffeinated Neural Net
![]() Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 1,033
Rep Power: 5
![]() |
Quote:
Quote:
Quote:
Perhaps the best solution is to have your heap hold references to items, rather than the items themselves. Presumably, to delete event X, you require some means of identifying event X. In other words, say you have a deleteEvent() method- what will you pass to it? Thus, if you can specify an event to delete, you already have a reference to the event, and can adjust its properties to deactivate it (setting Handled to true, if it's the .NET Event class or a derivative, or doing something similar for your own class). If you are using a structure, rather than a class, it will be a value type, so you will need to muck with pointers directly (generally not the best practice in C#). If you're using a class for your event type, it will be a reference type, so no problem. Perhaps you could give me some more details on what you're trying to do. When you say 'event', do you mean the Event class from the .NET framework, one derived from this, or a totally unrelated class used to represent logical events? How critical is it that events are handled? Mouse movement events, for example, aren't too critical- if the system drops (ignores) one of every few hundred movement events, the user probably won't even notice. Key press/release events for the keyboard keys or mouse buttons, on the other hand, are critical; missing these events will cause obvious problems. Likewise, what will be the result of handling an event that has been cancelled? Will it simply waste a bit of CPU time, or will it mean the event gets handled multiple times (say, by different handlers, with one earlier in the chain cancelling the event to prevent later handling)? If the latter, what are the consequences? If the former, it's probably acceptable to ignore cancellations, especially if the event code executes quickly.
__________________
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 |
|||
|
|
|
|
|
#13 | ||||
|
Professional Programmer
Join Date: May 2006
Location: UK - London
Posts: 330
Rep Power: 3
![]() |
Quote:
I was thinking one way to eliminate the O(n) of the deletion operation is to put all queue items in hash table, let the queue item structure hold a key (duetime) and the hash value of the item, so when i want to delete an item i would get the hash of the item, and change it's status to deleted, hopefully with no collisions this should take O(1) best case right? Quote:
Sorry I think I used the term event incorrectly, I think it's better described as an update or refresh task. I would say for something like this is of a critical level 3-4 (5 being the max), because if the ttl is pretty big, then you don't want to miss an update, and update a day late or something. Quote:
__________________
Quote:
|
||||
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Implementation of Mouse Events. | smita | Existing Project Development | 3 | Mar 15th, 2007 3:11 PM |
| Clone Node Events | Eryk | JavaScript and Client-Side Browser Scripting | 2 | Feb 24th, 2006 2:15 PM |
| question: usage of delagates and custom events | melbolt | C# | 1 | Oct 3rd, 2005 7:17 PM |
| Get base priority of a program | tedbauer | C++ | 7 | Aug 22nd, 2005 6:30 PM |
| Get base priority of a program | tedbauer | C | 3 | Aug 20th, 2005 7:28 PM |