473,399 Members | 4,254 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Optimizing custom collection for access?

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
6 1600
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: PK | last post by:
Hello, I am looking for help on the following. I'm trying to create a custom browser toolbar button that will do a few things. One that I'm trying to do at the moment is just simply return the...
3
by: GrumpyDev | last post by:
what is the best way to implement collection of custom entities?
0
by: Stephen Haeney via .NET 247 | last post by:
I have developed a Custom Collection of objects that implementsthe ITypedList interface, which allows a DataGrid to bind to thecollection while giving me control over the TableStyles. Theobjects...
0
by: Khuzema | last post by:
Dear All, I am using issue tracker architecture and developed business object for my application. Now, in VS Beta 2, I humbly want to know how i can have same feature as dataset, in my business...
7
by: Shimon Sim | last post by:
I have a custom composite control I have following property
1
by: Sanjay Pais | last post by:
I built a custom control for all the basic web.ui.controls like textbox, label, checkbox etc etc. I added my custom attribute called ApplySecurity to the html in the page. However, when I cycle...
5
by: Graham | last post by:
I have created a custom MembershipProvider called "LassieMembershipProvider" that derives from "MembershipProvider". This providor is located in a Businesslogic layer dll called...
19
by: Jamey Shuemaker | last post by:
I'm in the process of expanding my knowledge and use of Class Modules. I've perused MSDN and this and other sites, and I'm pretty comfortable with my understanding of Class Modules with the...
7
by: James Kanze | last post by:
On Apr 10, 4:06 pm, Jerry Coffin <jcof...@taeus.comwrote: Just a note, but in all of these languages, *all* objects are dynamically allocated. I wonder if this isn't more what caused you...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.