473,324 Members | 2,400 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,324 software developers and data experts.

How do I get sorted key/value pairs from a hastable

Hi,

I have a hastable with key/value pairs. I want to iterate thru the
collection in descending order by value. What is the 'best practice' for
handling this problem?

Thanks in advance for your help,
Hal Heinrich
VP Technology
Aralan Solutions Inc.
Nov 21 '05 #1
1 1450
Hal,
Consider using a System.Collections.SortedList instead of a HashTable.

The SortedList represents "a collection of key-and-value pairs that are
sorted by the keys and accessible by key and by index". In other words its
an ordered HashTable.

Unfortunately the SortedList will only get sort the keys & not the values.

If you want sorted values, I would put all the values into an ArrayList,
then sort the ArrayList in descending order (using a custom IComparable
object). If my app needed to "repeatedly" do this sort I would consider
creating a custom collection that maintained both the index (the descending
value arraylist) and the original hashtable...

Post if you need samples.

Hope this helps
Jay

"Hal Heinrich" <Ha*********@discussions.microsoft.com> wrote in message
news:DF**********************************@microsof t.com...
Hi,

I have a hastable with key/value pairs. I want to iterate thru the
collection in descending order by value. What is the 'best practice' for
handling this problem?

Thanks in advance for your help,
Hal Heinrich
VP Technology
Aralan Solutions Inc.

Nov 21 '05 #2

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

Similar topics

24
by: Lasse Vågsæther Karlsen | last post by:
I need to merge several sources of values into one stream of values. All of the sources are sorted already and I need to retrieve the values from them all in sorted order. In other words: s1 = ...
2
by: PABLO | last post by:
Hello I have a Hastable, which I need to order it by value and not by key. Regards
4
by: Vladimir C. | last post by:
Hashtable map = new Hashtable(); map = 10; map = 20; foreach(DictionaryEntry e in map) { e.Value = 100; Console.WriteLine("{0}: {1}", key, map); }
6
by: Kamilche | last post by:
I have a code snippet here that prints a dict in an arbitrary order. (Certain keys first, with rest appearing in sorted order). I didn't want to subclass dict, that's error-prone, and overkill for...
13
by: vd12005 | last post by:
Hello, i would like to sort(ed) and reverse(d) the result of many huge dictionaries (a single dictionary will contain ~ 150000 entries). Keys are words, values are count (integer). i'm...
12
by: =?UTF-8?B?TWFydGluIFDDtnBwaW5n?= | last post by:
Hello, I´ve a problem with my Key-Value SortedList. Is there a way to sort a list (or any other data structure) by value? I have a list with 1000 key-value pairs and want to get the pairs...
18
by: Hunk | last post by:
Would like some advice on the fillowing I have a sorted list of items on which i require to search and retrieve the said item and also modify an item based on its identity. I think an Map stl...
2
by: Sehboo | last post by:
I am trying to use key value pair list, but I don't want to use sorted list because it messes up my order. I am not sure what other options I have. Can anybody point? Thanks
7
by: Matthias Pfeifer | last post by:
Hi there, a std::map is build from std::pair elements where for a pair p p.first is called the key and p.second the value. Is there a way to keep the map sorted by the values? Ie is there a...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.