all groups > dotnet windows forms > march 2006 >
You're in the

dotnet windows forms

group:

Fast Searches of a Thread Safe Collection of Structs


Fast Searches of a Thread Safe Collection of Structs Jeff S.
3/28/2006 9:35:05 PM
dotnet windows forms:
In a Windows Forms application I plan to have a collection of structs - each
of which contains a bunch of properties describing a person (e.g., LastName,
FirstName, EmployeeID, HomeAddress, ZipCode, etc). So each instance of the
struct will describe a person - and about 900 instances (people) will be
contained in the collection.

Users must be able to search for a specific person by any of the properties
(e.g., LastName, FirstName, EmployeeID, HomeAddress, ZipCode, etc). So the
collection must be searchable by all of the properties of the contained
struct instances.

Please note that the comparison will be between (1) a string the user is
typing into a textbox, and (2) the specified property (e.g., LastName) --
such that AS the user types, a list displayed elsewhere on the form will
dynamically show ALL of the closest matches (closest to the string the user
is typing AS the user types).

The collection will periodically be updated on a background thread (every 15
or so minutes) - so the collection must be "thread safe."

MY QUESTIONS:
1. How do I make the collection of structs searchable by *each* of its
properties (LastName, FirstName, Zip, etc...). Of course only one property
at a time would be searched on. I would think implementing IComparable would
work - but apparently doing so would let me enable searching on only one of
the properties (but I need to enable searching on ALL of the properties).

2. How do I make the collection "thread safe" so that the collection can be
updated by a background thread while users may be searching for a person in
the collection. Note: people [in the collection] will almost never be
deleted - so phantom matches are not really a concern.

Just looking for high-level direction on this.

Thank you very much!



Re: Fast Searches of a Thread Safe Collection of Structs Jeff S.
3/28/2006 11:15:42 PM
Thanks William... can you expand just a bit? I'm not clear on [... Predicate
delegates... ].

-Jeff


[quoted text, click to view]

Re: Fast Searches of a Thread Safe Collection of Structs Jon Skeet [C# MVP]
3/29/2006 12:00:00 AM
[quoted text, click to view]

Just to check before too much detail is gone into - are you using .NET
2.0 or 1.1? You won't be able to use List<T> if you're only using 1.1.

Also, do you *have* to use structs? Why are you using structs rather
than classes?

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
Re: Fast Searches of a Thread Safe Collection of Structs Nick Hounsome
3/29/2006 12:00:00 AM
And you almost certainly shouldn't be using use structs for a Person class.

Your post talks about the string that the person is "typing" into a box -
this sounds like an incremental search to me - if so you would need to sort
the list for the particular property instead of using predicates.

[quoted text, click to view]

Re: Fast Searches of a Thread Safe Collection of Structs William Stacey [MVP]
3/29/2006 12:52:23 AM
Lock the list during reads and writes. Use List<struct> and Find() using
different Predicate delegates for your different search needs.

--
William Stacey [MVP]

[quoted text, click to view]
| In a Windows Forms application I plan to have a collection of structs -
each
| of which contains a bunch of properties describing a person (e.g.,
LastName,
| FirstName, EmployeeID, HomeAddress, ZipCode, etc). So each instance of the
| struct will describe a person - and about 900 instances (people) will be
| contained in the collection.
|
| Users must be able to search for a specific person by any of the
properties
| (e.g., LastName, FirstName, EmployeeID, HomeAddress, ZipCode, etc). So the
| collection must be searchable by all of the properties of the contained
| struct instances.
|
| Please note that the comparison will be between (1) a string the user is
| typing into a textbox, and (2) the specified property (e.g., LastName) --
| such that AS the user types, a list displayed elsewhere on the form will
| dynamically show ALL of the closest matches (closest to the string the
user
| is typing AS the user types).
|
| The collection will periodically be updated on a background thread (every
15
| or so minutes) - so the collection must be "thread safe."
|
| MY QUESTIONS:
| 1. How do I make the collection of structs searchable by *each* of its
| properties (LastName, FirstName, Zip, etc...). Of course only one property
| at a time would be searched on. I would think implementing IComparable
would
| work - but apparently doing so would let me enable searching on only one
of
| the properties (but I need to enable searching on ALL of the properties).
|
| 2. How do I make the collection "thread safe" so that the collection can
be
| updated by a background thread while users may be searching for a person
in
| the collection. Note: people [in the collection] will almost never be
| deleted - so phantom matches are not really a concern.
|
| Just looking for high-level direction on this.
|
| Thank you very much!
|
|
|
|

AddThis Social Bookmark Button