Click here to Skip to main content
15,884,083 members
Home / Discussions / C#
   

C#

 
GeneralRe: Getting ASCII value for Characters? Pin
Richard MacCutchan20-Nov-15 3:07
mveRichard MacCutchan20-Nov-15 3:07 
GeneralRe: Getting ASCII value for Characters? Pin
OriginalGriff20-Nov-15 2:49
mveOriginalGriff20-Nov-15 2:49 
AnswerRe: Getting ASCII value for Characters? Pin
Richard MacCutchan19-Nov-15 23:20
mveRichard MacCutchan19-Nov-15 23:20 
QuestionLeap Motion Integration problem Pin
Alpa2419-Nov-15 14:44
Alpa2419-Nov-15 14:44 
AnswerRe: Leap Motion Integration problem Pin
OriginalGriff19-Nov-15 21:31
mveOriginalGriff19-Nov-15 21:31 
QuestionWriting HtmlHelper to Render all action methods Pin
roxcon18-Nov-15 17:53
roxcon18-Nov-15 17:53 
AnswerRe: Writing HtmlHelper to Render all action methods Pin
Dave Kreskowiak19-Nov-15 2:28
mveDave Kreskowiak19-Nov-15 2:28 
Questionsorting information from several threads - is my algorithm correct? Pin
John Torjo17-Nov-15 12:48
professionalJohn Torjo17-Nov-15 12:48 
Hi guys,

I want to sort in real time (by datetime) information coming from several threads.

There is a thread the constantly polls for latest items. The polling thread appends whatever I return to his existing list of items. I need to returns items in such a way that polling thread's list is sorted at all times.

Here are my requirements:
1. I have several threads, each reading a different event log.
2. Each thread reads all items (events) from this log, and pushes them in a list (specific to that thread)
3. There is a client asking periodically for the "latest" events (sorted by datetime).
Once I put an item into this latest events list, it will disappear from my internal list.
4. The client appends this list to his existing items, and the new resulting list has to be sorted (the client starts with an empty list).

My current algorithm is:
Each time the client asks for "latest" events:
a. Look at all thread's lists
b. If there is one or more threads that doesn't have at least one element, return an empty list
c. Look through all lists, and take the "earliest" element.
d. If the list contains the "earliest" element, contains at least one more element, add this to the "latest" events and go back to step a.
e. Otherwise, return existing list

My take and current tests say that the algorithm is correct.

Can you find a counterexample?
Is my algorithm wrong?


Best,
John
-- LogWizard Meet the Log Viewer that makes monitoring log files a joy!


modified 18-Nov-15 16:55pm.

AnswerRe: sorting information from several threads - is my algorithm correct? Pin
Matt T Heffron17-Nov-15 13:38
professionalMatt T Heffron17-Nov-15 13:38 
GeneralRe: sorting information from several threads - is my algorithm correct? Pin
John Torjo17-Nov-15 13:42
professionalJohn Torjo17-Nov-15 13:42 
QuestionRe: sorting information from several threads - is my algorithm correct? Pin
Matt T Heffron17-Nov-15 14:00
professionalMatt T Heffron17-Nov-15 14:00 
AnswerRe: sorting information from several threads - is my algorithm correct? Pin
John Torjo17-Nov-15 14:03
professionalJohn Torjo17-Nov-15 14:03 
AnswerRe: sorting information from several threads - is my algorithm correct? Pin
BillWoodruff17-Nov-15 14:49
professionalBillWoodruff17-Nov-15 14:49 
GeneralRe: sorting information from several threads - is my algorithm correct? Pin
John Torjo17-Nov-15 14:59
professionalJohn Torjo17-Nov-15 14:59 
GeneralRe: sorting information from several threads - is my algorithm correct? Pin
BillWoodruff18-Nov-15 0:05
professionalBillWoodruff18-Nov-15 0:05 
GeneralRe: sorting information from several threads - is my algorithm correct? Pin
John Torjo18-Nov-15 0:07
professionalJohn Torjo18-Nov-15 0:07 
GeneralRe: sorting information from several threads - is my algorithm correct? Pin
John Torjo18-Nov-15 10:58
professionalJohn Torjo18-Nov-15 10:58 
AnswerRe: sorting information from several threads - is my algorithm correct? Pin
Gerry Schmitz17-Nov-15 16:13
mveGerry Schmitz17-Nov-15 16:13 
GeneralRe: sorting information from several threads - is my algorithm correct? Pin
John Torjo17-Nov-15 22:12
professionalJohn Torjo17-Nov-15 22:12 
GeneralRe: sorting information from several threads - is my algorithm correct? Pin
Gerry Schmitz18-Nov-15 0:17
mveGerry Schmitz18-Nov-15 0:17 
GeneralRe: sorting information from several threads - is my algorithm correct? Pin
John Torjo18-Nov-15 0:23
professionalJohn Torjo18-Nov-15 0:23 
GeneralRe: sorting information from several threads - is my algorithm correct? Pin
Gerry Schmitz18-Nov-15 0:50
mveGerry Schmitz18-Nov-15 0:50 
GeneralRe: sorting information from several threads - is my algorithm correct? Pin
John Torjo18-Nov-15 4:10
professionalJohn Torjo18-Nov-15 4:10 
AnswerRe: sorting information from several threads - is my algorithm correct? Pin
Daniel Pfeffer18-Nov-15 9:24
professionalDaniel Pfeffer18-Nov-15 9:24 
GeneralRe: sorting information from several threads - is my algorithm correct? Pin
John Torjo18-Nov-15 10:38
professionalJohn Torjo18-Nov-15 10:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.