Click here to Skip to main content
15,887,083 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralRe: ConcurrentQueue & FirstOrDefault() and search speed. Pin
Richard Deeming6-Feb-18 2:46
mveRichard Deeming6-Feb-18 2:46 
GeneralRe: ConcurrentQueue & FirstOrDefault() and search speed. Pin
raddevus6-Feb-18 5:41
mvaraddevus6-Feb-18 5:41 
GeneralRe: ConcurrentQueue & FirstOrDefault() and search speed. Pin
Kornfeld Eliyahu Peter6-Feb-18 3:37
professionalKornfeld Eliyahu Peter6-Feb-18 3:37 
GeneralRe: ConcurrentQueue & FirstOrDefault() and search speed. Pin
raddevus6-Feb-18 5:37
mvaraddevus6-Feb-18 5:37 
GeneralRe: ConcurrentQueue & FirstOrDefault() and search speed. Pin
Richard Deeming6-Feb-18 10:11
mveRichard Deeming6-Feb-18 10:11 
GeneralRe: ConcurrentQueue & FirstOrDefault() and search speed. Pin
raddevus6-Feb-18 10:19
mvaraddevus6-Feb-18 10:19 
GeneralRe: ConcurrentQueue & FirstOrDefault() and search speed. Pin
Jörgen Andersson9-Feb-18 2:02
professionalJörgen Andersson9-Feb-18 2:02 
GeneralRe: ConcurrentQueue & FirstOrDefault() and search speed. Pin
raddevus9-Feb-18 4:16
mvaraddevus9-Feb-18 4:16 
Thanks for chiming in on the conversation. The challenge I have here is that I need to insure the item is not currently anywhere in the collection -- an item may have been loaded at any location.

There are probably other ways around this but just attempting to do it the easiest, yet most correct way which uses the least resources.

The collection is used in two ways :
1. caller will request the oldest unique item
2. collection will periodically load newer items into itself

The interesting thing about this is that the Queue makes on of those requirements easy and the Dictionary makes the other requirement easy.

The first one is easy with the Queue since you just get the first in item.
The second one is difficult with a Queue (there is no key) so you have to determine that the object is not already contained in the Queue for every item, each time the items are retrieved from db.

The second one is easy with a Dictionary since you can do TryAdd() with your unique key and it fails fast if the item has already been added).
However, the first one is more difficult with a Dictionary because the items are not (necessarily) ordered in a significant way and we need to get the oldest item.

It's an interesting problem.
GeneralRe: ConcurrentQueue & FirstOrDefault() and search speed. Pin
Richard Deeming9-Feb-18 4:47
mveRichard Deeming9-Feb-18 4:47 
GeneralRe: ConcurrentQueue & FirstOrDefault() and search speed. Pin
raddevus9-Feb-18 8:31
mvaraddevus9-Feb-18 8:31 
GeneralRe: ConcurrentQueue & FirstOrDefault() and search speed. Pin
Richard Deeming12-Feb-18 8:19
mveRichard Deeming12-Feb-18 8:19 
GeneralRe: ConcurrentQueue & FirstOrDefault() and search speed. Pin
Jörgen Andersson9-Feb-18 6:09
professionalJörgen Andersson9-Feb-18 6:09 
GeneralRe: ConcurrentQueue & FirstOrDefault() and search speed. Pin
patbob19-Feb-18 5:42
patbob19-Feb-18 5:42 
Generalsql maths Pin
kmoorevs27-Jan-18 7:17
kmoorevs27-Jan-18 7:17 
GeneralRe: sql maths Pin
RedDk28-Jan-18 11:12
RedDk28-Jan-18 11:12 
GeneralRe: sql maths Pin
kmoorevs29-Jan-18 2:53
kmoorevs29-Jan-18 2:53 
GeneralRe: sql maths Pin
Tomz_KV29-Jan-18 5:43
Tomz_KV29-Jan-18 5:43 
GeneralRe: sql maths Pin
kmoorevs29-Jan-18 5:52
kmoorevs29-Jan-18 5:52 
GeneralHow to add a single item to an array Pin
Marc Clifton23-Jan-18 3:03
mvaMarc Clifton23-Jan-18 3:03 
GeneralRe: How to add a single item to an array Pin
Ehsan Sajjad23-Jan-18 3:18
professionalEhsan Sajjad23-Jan-18 3:18 
GeneralRe: How to add a single item to an array Pin
BillW3323-Jan-18 3:45
professionalBillW3323-Jan-18 3:45 
GeneralRe: How to add a single item to an array Pin
Nelek23-Jan-18 3:50
protectorNelek23-Jan-18 3:50 
GeneralRe: How to add a single item to an array Pin
Marc Clifton23-Jan-18 3:55
mvaMarc Clifton23-Jan-18 3:55 
GeneralRe: How to add a single item to an array Pin
Nelek23-Jan-18 4:13
protectorNelek23-Jan-18 4:13 
GeneralRe: How to add a single item to an array Pin
Bernhard Hiller23-Jan-18 21:50
Bernhard Hiller23-Jan-18 21:50 

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.