By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,501 Members | 1,678 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,501 IT Pros & Developers. It's quick & easy.

Optimizing custom collection for access?

P: n/a
Mel
I have a large collection of custom objects, each representing a period in
time with each having a start datetime and an end datetime. I frequently
need to query this collection to return a subset of the objects that fall
completely or partially between two specified dates. The way I'm doing this
at the moment is to iterate thru the entire collection on each query and
pull out the valid objects, but this is hardly an optimal way to do it. How
can I set up my collection to make this sort of operation most efficient?

Thx
Nov 16 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
The only way to filter a collection of objects based on specified criteria
is to loop through all the objects the way you are. The only alternative
would be to provide a static class that accepts certain parameters, does the
filtering at your database (I'm assuming you are using one here) and then
return a collection based on those return results.

The expensive part of your taks is the searching, something SQL was designed
for.

If you are not using a database then your best approach I would think would
be to optimize your looping logic.

MattC
"Mel" <me*@no-reply.com> wrote in message
news:uY**************@TK2MSFTNGP11.phx.gbl...
I have a large collection of custom objects, each representing a period in
time with each having a start datetime and an end datetime. I frequently
need to query this collection to return a subset of the objects that fall
completely or partially between two specified dates. The way I'm doing this
at the moment is to iterate thru the entire collection on each query and
pull out the valid objects, but this is hardly an optimal way to do it. How
can I set up my collection to make this sort of operation most efficient?

Thx

Nov 16 '05 #2

P: n/a
Mel,

In addition to what MattC said, you might want to consider storing the
details of each object in a data set, and then having the collection hold
the dataset itself. The objects themselves can know what their ids are, and
then just have a reference to the parent data set, pulling out the details
when needed (searching themselves on the unique id).

Once you do that, you can then use the filtering abilities of the
dataview class (or the Select method on the data table class) to filter your
queries by a certain criteria.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Mel" <me*@no-reply.com> wrote in message
news:uY**************@TK2MSFTNGP11.phx.gbl...
I have a large collection of custom objects, each representing a period in
time with each having a start datetime and an end datetime. I frequently
need to query this collection to return a subset of the objects that fall
completely or partially between two specified dates. The way I'm doing this
at the moment is to iterate thru the entire collection on each query and
pull out the valid objects, but this is hardly an optimal way to do it. How
can I set up my collection to make this sort of operation most efficient?

Thx

Nov 16 '05 #3

P: n/a
Mel wrote:
I have a large collection of custom objects, each representing a period in
time with each having a start datetime and an end datetime. I frequently
need to query this collection to return a subset of the objects that fall
completely or partially between two specified dates. The way I'm doing this
at the moment is to iterate thru the entire collection on each query and
pull out the valid objects, but this is hardly an optimal way to do it. How
can I set up my collection to make this sort of operation most efficient?

Thx


Hi,

Isn't it possible to sort the collection in some way, and perform some
binary searching on it, to (roughly or exactly) find the first and last
valid object. This might give you a smaller subrange of objects for
further evaluation.

Cheers,
Benoit.
Nov 16 '05 #4

P: n/a
Benoit,

Once you have sorted the data and as you say found the first an last valid
objects could you simply then just create a new collection using the objects
between the indexes found?

Is this what you mean?

MattC

"Benoit Vreuninckx" <bv*****@nospam.skynet.be> wrote in message
news:41***********************@news.skynet.be...
Mel wrote:
I have a large collection of custom objects, each representing a period
in time with each having a start datetime and an end datetime. I
frequently need to query this collection to return a subset of the
objects that fall completely or partially between two specified dates.
The way I'm doing this at the moment is to iterate thru the entire
collection on each query and pull out the valid objects, but this is
hardly an optimal way to do it. How can I set up my collection to make
this sort of operation most efficient?

Thx


Hi,

Isn't it possible to sort the collection in some way, and perform some
binary searching on it, to (roughly or exactly) find the first and last
valid object. This might give you a smaller subrange of objects for
further evaluation.

Cheers,
Benoit.

Nov 16 '05 #5

P: n/a
Mel
Thanks guys. There seems to be no obvious/easy way of improving efficiency
that I was overlooking. Probably the best approach would be to sort the
collection in chrono order and implement binary searches for both the start
and end items in the sought-after range. For now I'll just leave it as it is
and revisit it if need be.
Nov 16 '05 #6

P: n/a
Nicholas,

I've been toying with this idea on my current BLL object collections. It
seems a good idea on the whole. However, how would you suggest persisting
the DataSet over postbacks when used in an ASP.NET application. Would not
placing the Collection and DataSet in the Session/ViewState be expensive? I
guess it comes down to the Time to load by recreating the DataSet with DB
call versus the memory usage hit and serialisation/deserialisation of
Session/ViewState.

Any thoughts.

TIA

MattC

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:ub**************@TK2MSFTNGP12.phx.gbl...
Mel,

In addition to what MattC said, you might want to consider storing the
details of each object in a data set, and then having the collection hold
the dataset itself. The objects themselves can know what their ids are,
and then just have a reference to the parent data set, pulling out the
details when needed (searching themselves on the unique id).

Once you do that, you can then use the filtering abilities of the
dataview class (or the Select method on the data table class) to filter
your queries by a certain criteria.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Mel" <me*@no-reply.com> wrote in message
news:uY**************@TK2MSFTNGP11.phx.gbl...
I have a large collection of custom objects, each representing a period in
time with each having a start datetime and an end datetime. I frequently
need to query this collection to return a subset of the objects that fall
completely or partially between two specified dates. The way I'm doing
this at the moment is to iterate thru the entire collection on each query
and pull out the valid objects, but this is hardly an optimal way to do
it. How can I set up my collection to make this sort of operation most
efficient?

Thx


Nov 16 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.