473,473 Members | 1,807 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Collection Types

I am looking for some help on the best type of collection to use and/
or best way to implement the collection with the following
functionality:

I have defined an object to represent an interest rate:
Public Class IRFcast
Public CloseDate As Date
Public RateIndex As String
Public RateClose As Double
End Class

I would like to define a collection of these interest rate objects
(there could be a large number of them - tens of thousands) such that
they can be quickly searched on a CloseDate and RateIndex combination.
Furthermore, I need to implement a search that will return (again, as
quickly as possible) the IRFcast object with a RateIndex=the searched
RateIndex and the maximum CloseDate<=the searched CloseDate.

Any suggestions on the best path to pursue here would be much
appreciated.

Feb 20 '07 #1
5 1503
On Feb 20, 11:31 am, "jwilson128" <jwilson...@yahoo.comwrote:
I am looking for some help on the best type of collection to use and/
or best way to implement the collection with the following
functionality:

I have defined an object to represent an interest rate:
Public Class IRFcast
Public CloseDate As Date
Public RateIndex As String
Public RateClose As Double
End Class

I would like to define a collection of these interest rate objects
(there could be a large number of them - tens of thousands) such that
they can be quickly searched on a CloseDate and RateIndex combination.
Furthermore, I need to implement a search that will return (again, as
quickly as possible) the IRFcast object with a RateIndex=the searched
RateIndex and the maximum CloseDate<=the searched CloseDate.

Any suggestions on the best path to pursue here would be much
appreciated.
As far as lists go, I would use List(Of T). It has search functions
like find and findall, etc that take delegates that can aid in your
search. Since you seem to want to define multiple search criteria....

But, I have to ask, might it not be more effiecient to store these in
a db and then use a query to get at the ones you need? Just a
thought.

--
Tom Shelton

Feb 20 '07 #2
On Feb 20, 12:31 pm, "jwilson128" <jwilson...@yahoo.comwrote:
I am looking for some help on the best type of collection to use and/
or best way to implement the collection with the following
functionality:

I have defined an object to represent an interest rate:
Public Class IRFcast
Public CloseDate As Date
Public RateIndex As String
Public RateClose As Double
End Class

I would like to define a collection of these interest rate objects
(there could be a large number of them - tens of thousands) such that
they can be quickly searched on a CloseDate and RateIndex combination.
Furthermore, I need to implement a search that will return (again, as
quickly as possible) the IRFcast object with a RateIndex=the searched
RateIndex and the maximum CloseDate<=the searched CloseDate.

Any suggestions on the best path to pursue here would be much
appreciated.
Hi,

I'm assuming that CloseDate and RateIndex can uniquely identify an
IRFcast object. Write a custom collection that internally uses two
hashtables (Dictionary<Of Tor Hashtable). We'll call them A and B.
The first hashtable (A) will cross reference a combination the
CloseDate and RateIndex fields to an IRFcast object. The second
hashtable (B) will cross reference the RateIndex field to a sorted
list (SortedList, SortedList<Of T>, or an array that is manually
sorted) of IRFcast objects with the same RateIndex field.

The first search use case can be done by using hashtable A. It is a
O(1) operation.

The second search use case can be done by using hashtable B to locate
the sorted list of IRFcast objects of like RateIndex and then doing a
binary search on that list. That is a O(log(n')) average case
operation where n' is the average distribution of IRFcast objects to a
RateIndex.

Brian

Feb 20 '07 #3
Brian - thanks for the info. A couple follow-up questions:

1) does this mean storing all of the IRFcast objects twice (once for
each use case). I'm assuming that I would just think about the
tradeoff in storing the info twice vs the performance benefit of
accessing an object quicker?

2) when doing the suggested binary search on IRFcast objects with like
RateIndex, is there a better way to do it than to cycle through the
list? something comparable to the SQL logic of SELECT MAX(closedate)
WHERE closedate<=search date?

-Jeff

Feb 27 '07 #4
On Feb 26, 6:57 pm, "jwilson128" <jwilson...@yahoo.comwrote:
Brian - thanks for the info. A couple follow-up questions:

1) does this mean storing all of the IRFcast objects twice (once for
each use case). I'm assuming that I would just think about the
tradeoff in storing the info twice vs the performance benefit of
accessing an object quicker?
Well, you're not exactly storing the IRFcast objects twice. You're
storing the references to those objects twice. But, yeah, that's
basically true. You just need to determine if the memory trade off is
worth it.
2) when doing the suggested binary search on IRFcast objects with like
RateIndex, is there a better way to do it than to cycle through the
list? something comparable to the SQL logic of SELECT MAX(closedate)
WHERE closedate<=search date?
Not really. LINQ promises to offer this kind of SQL-like syntax, but
you'll have to wait since it's not available in VB 2005. I'm afraid
you'll have to implement your own binary search. It's really not that
difficult though. If you're not comfortable with the binary search
then you could always traverse the sorted list (or array) from the
tail one at a time to find the correct object. It would be slower,
but simpler.
Feb 27 '07 #5
jwilson128 wrote:
2) when doing the suggested binary search on IRFcast objects with like
RateIndex, is there a better way to do it than to cycle through the
list? something comparable to the SQL logic of SELECT MAX(closedate)
WHERE closedate<=search date?
You don't have to loop through the list. Using a binary seach means that
you use the fact that the list is sorted to rule out half of the list
for each comparison that you do. Finding a value in a list of 1000 items
can be done with just ten comparisons.

http://en.wikipedia.org/wiki/Binary_search_algorithm

--
Göran Andersson
_____
http://www.guffa.com
Feb 27 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: KN | last post by:
I know both are pretty much the same and it comes down to personal choice. But I have to make the choice for the team. Things so far that I am considering 1. XML documentation in C# -- thats...
11
by: Pavils Jurjans | last post by:
Hello, There's some confusion about the purpose and difference between these handy classes... First, both of them are holding number of key - value pairs, right? Then, I see that there may be...
5
by: aa7im | last post by:
I am attempting to create a base collection that I can use to derive strongly typed collection. My base collection class will derive from CollectionBase and I want my typed collections to be...
2
by: Edward Diener | last post by:
In C++ an overridden virtual function in a derived class must have the exact same signature of the function which is overridden in the base class, except for the return type which may return a...
5
by: NotABug | last post by:
Is it possible to do collections of struct __values in MC++ 2003? How can I translate the following C# example to C++: public sealed class PointsCollection : CollectionBase { public void...
4
by: Michael | last post by:
Dear all .. If I want to use develop a user control and declare a public property which the type is System.Windows.Forms.GridTableStylesCollection For example : Public Class LookAndView...
6
by: Scott M. Lyon | last post by:
As I mentioned in my other post, I'm attempting to, using COM Interop so I can update existing VB6 code to (for several specific functions) return a Hashtable from a .NET library. I've had...
14
by: Jeff S. | last post by:
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,...
1
by: kevinwolfe | last post by:
Hello all, I have a class which inherits 'Collection' and I use this class to store different data types. I'd like to have a method inside the class that does the following: For Each obj As...
3
by: jacob navia | last post by:
Abstract: Continuing the discussion about abstract data types, in this discussion group, a string collection data type is presented, patterned after the collection in C# and similar languages...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.