473,770 Members | 4,553 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Extended Sorted List

Hi !

I would like to make an array of structure (collection ?) that would
behave like an advanced sorted list : a sorted list with one key but
with multiple values (sorted lists are key/value items).

- indexed by value index or by key (2 indexers)
- sortable by key or a secondary key
- supporting foreach loops
Is there a class my 'ExtendedList' could inherit from that would make
the most part of the job ?

Any hints to do it ?
Any Example ?
Regards,
Cybertof.
Nov 15 '05 #1
4 5154
Cybertof,

It sounds like you want a stongly-typed dictionary. You can extend
DictionaryBase. However, you would have to implement the functionality that
would sort the list based on a field in the value (that field being a public
field or a property). Managing this is going to have a performance impact
as well.

On top of that, you will have to change the enumerator so that it
returns the items in the dictionary in the order you want. Like the
Hashtable, it should return a structure with the key/value pair, and not
just the value.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- nick(dot)paldin o=at=exisconsul ting<dot>com

"Cybertof" <cy************ ****@gmx.net> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
Hi !

I would like to make an array of structure (collection ?) that would
behave like an advanced sorted list : a sorted list with one key but
with multiple values (sorted lists are key/value items).

- indexed by value index or by key (2 indexers)
- sortable by key or a secondary key
- supporting foreach loops
Is there a class my 'ExtendedList' could inherit from that would make
the most part of the job ?

Any hints to do it ?
Any Example ?
Regards,
Cybertof.

Nov 15 '05 #2
Nicholas,

What do you mean with
'Managing this is going to have a perfomance impact' ?

Is there a more efficient way ?

What is the restriction you are speaking about when you say
"Like the Hashtable, it should return a structure with the key/value
pair, and not just the value."

Regards,
Cybertof.

In article <#K************ *@tk2msftngp13. phx.gbl>,
ni************* *@exisconsultin g.com says...
Cybertof,

It sounds like you want a stongly-typed dictionary. You can extend
DictionaryBase. However, you would have to implement the functionality that
would sort the list based on a field in the value (that field being a public
field or a property). Managing this is going to have a performance impact
as well.

On top of that, you will have to change the enumerator so that it
returns the items in the dictionary in the order you want. Like the
Hashtable, it should return a structure with the key/value pair, and not
just the value.

Hope this helps.

Nov 15 '05 #3
Cybertof,

The reason it will have a performance impact is that in addition to
storing the value, on each add, insert, and removal of an item, you are
going to have to calculate where in the list it belongs, and that takes
time.

If you do a foreach on a Hashtable, you will be returned an instance of
type DictionaryEntry , which has a field for the key, and a field for the
value in the Hashtable. Your object should reflect this as well, instead of
just returning a value.
--
- Nicholas Paldino [.NET/C# MVP]
- nick(dot)paldin o=at=exisconsul ting<dot>com
"Cybertof" <cy************ ****@gmx.net> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
Nicholas,

What do you mean with
'Managing this is going to have a perfomance impact' ?

Is there a more efficient way ?

What is the restriction you are speaking about when you say
"Like the Hashtable, it should return a structure with the key/value
pair, and not just the value."

Regards,
Cybertof.

In article <#K************ *@tk2msftngp13. phx.gbl>,
ni************* *@exisconsultin g.com says...
Cybertof,

It sounds like you want a stongly-typed dictionary. You can extend
DictionaryBase. However, you would have to implement the functionality that would sort the list based on a field in the value (that field being a public field or a property). Managing this is going to have a performance impact as well.

On top of that, you will have to change the enumerator so that it
returns the items in the dictionary in the order you want. Like the
Hashtable, it should return a structure with the key/value pair, and not
just the value.

Hope this helps.

Nov 15 '05 #4
Maybe there is something i don't understand, but why should my object
return a (key,value) pair if i already know the key itself (because i
use it during the 'call' to the search through the key indexer) ?

Cybertof.
In article <ey************ **@TK2MSFTNGP11 .phx.gbl>,
ni************* *@exisconsultin g.com says...
If you do a foreach on a Hashtable, you will be returned an instance of
type DictionaryEntry , which has a field for the key, and a field for the
value in the Hashtable. Your object should reflect this as well, instead of
just returning a value.

Nov 15 '05 #5

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

Similar topics

0
1590
by: Daniele Varrazzo | last post by:
If you need a container to look into, there is the sets module that provides a couple of them. If you need a sorted list, there is the bisect module. But i don't think it fits your need for a quick lookup: it's a python module so probably it's slower. Furthermore you can __hash__ almost everything, but you can __cmp__ in a consistent way much less stuff. Take definitely a look at sets.
57
3617
by: Egor Bolonev | last post by:
why functions created with lambda forms cannot contain statements? how to get unnamed function with statements?
5
52120
by: MackS | last post by:
Dear all, I've got several large sets in my program. After performing several operations on these I wish to present one set to the user sorted according to a certain criterion. Is there any direct way to do so? Or must I list = for item in set1:
10
15138
by: Der Andere | last post by:
I need to implement a sorted (ordered) list. STL has no sorted list type as far as I know. Is there a (straight) way to implement a sorted list using STL? BTW: The type of items in the list will be a class. Is it necessary to implement the > or < operators or to write a compare-function that returns the larger or smaller of two classes? Ideally, the list begins with the smallest element. Cheers, Matthias
3
22075
by: Andrew Clark | last post by:
*** post for FREE via your newsreader at post.newsfeed.com *** it's been a while since i have poseted to this newsgroup, but for a long time i was not programming at all. but now that i am out of college and facing the prospect of getting a real job, i need to get back into the game. anyway, i don't know if some of you know the stanford CS library. i took the problem set a while back and have recently rediscovered it adn have been trying...
1
1648
by: J L | last post by:
I want to create a sorted list whose values are themselves sorted lists. I wrote the following simple test program but it does not behave as I would expect. What I wanted to do was have the doorConflictList be keyed on a door ID and contain a sorted list called conFlictList. I wrote this expecting the following doorConflictList should end up with 3 items. Item 1 would be a sorted list with 1 item
4
1862
by: shrishjain | last post by:
Hi All, I need a type where I can store my items in sorted order. And I want to keep adding items to it, and want it to remain sorted. Is there any type in .net which I can make use of. I see there is SortedList<key, value> for hash tables, but could find anything for a sorted list. Currently I am using List<string> and whenever I add an item, I need to
1
1590
by: Khayrat | last post by:
Hi folks, please help I have a xml file with a list of items. The list is sorted during xslt processing. Based on this sorted list I want a navigation facility to walk through the sorted list starting from a choosen item via <back> and <next>. Say this is the list: <a>
8
2596
by: Guy | last post by:
Is there a better way to search identical elements in a sorted array list than the following: iIndex = Array.BinarySearch( m_Array, 0, m_Array.Count, aSearchedObject ); aFoundObject= m_Array; m_ResultArray.Add ( aFoundObject);
0
9439
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10071
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9882
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8905
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7431
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5326
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5467
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3987
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 we have to send another system
2
3589
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.