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

Match key, sort on value in key/value pair

P: n/a
I'm counting the frequency of word occurances and would like to return
a key/value list sorted descending by frequency.

So I need to quickly see if a word (key) is in the list, but later
sort the list descending by values.

Any ideas on how to do this efficiently?

Thanks,

Jim
Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Jim,

I think that the datatable with primary keys can exactly do what you want.

\\\just typed in, nothing checked
Dim dt As New DataTable
Dim keys(0) As DataColumn
dt.Columns.Add("Key")
dt.Columns.Add("Value")
keys(0) = dt.Columns(0)
dim dvValues as dataview(dt)
dv.sort = "Value"
etc
etc
///

You can use the dt.rows.find to find a key and the dv with the select for
the value.

I hope this helps?

Cor

Jim Adams" <ji*******@hotmail.com>

I'm counting the frequency of word occurances and would like to return
a key/value list sorted descending by frequency.

So I need to quickly see if a word (key) is in the list, but later
sort the list descending by values.

Any ideas on how to do this efficiently?

Thanks,

Jim

Nov 21 '05 #2

P: n/a
Hi Jay,

Thanks for the tip.

-Jim

"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> wrote in message news:<er**************@TK2MSFTNGP11.phx.gbl>...
Jim,
Unfortunately the Framework has no predefined classes that do that, however
you can create a custom collection that encapsulates a Hashtable to allow
key/value, and an ArrayList that you can sort to return descending values.

There are any number of ways to implement this depending on what the
requirements of your program are.

1. Use a DictionaryBase with a method that populates & sorts the ArrayList
as needed.
2. Use a DictionaryBase with a private field for the ArrayList. The Add
method would add the object to both collections.
3. Use a CollectionBase with a private field for a HashTable. The Add method
would add the object to both collections.
4. Create a custom object that contains both a HashTable & ArrayList.

Note in #2, #3 & #4 above I would use an insertion sort to maintain a sorted
array as I added elements...

Hope this helps
Jay

"Jim Adams" <ji*******@hotmail.com> wrote in message
news:49**************************@posting.google.c om...
I'm counting the frequency of word occurances and would like to return
a key/value list sorted descending by frequency.

So I need to quickly see if a word (key) is in the list, but later
sort the list descending by values.

Any ideas on how to do this efficiently?

Thanks,

Jim

Nov 21 '05 #3

P: n/a
Hi Cor,

Thanks for the tip.

Jim

"Cor Ligthert" <no************@planet.nl> wrote in message news:<ON**************@tk2msftngp13.phx.gbl>...
Jim,

I think that the datatable with primary keys can exactly do what you want.

\\\just typed in, nothing checked
Dim dt As New DataTable
Dim keys(0) As DataColumn
dt.Columns.Add("Key")
dt.Columns.Add("Value")
keys(0) = dt.Columns(0)
dim dvValues as dataview(dt)
dv.sort = "Value"
etc
etc
///

You can use the dt.rows.find to find a key and the dv with the select for
the value.

I hope this helps?

Cor

Jim Adams" <ji*******@hotmail.com>

I'm counting the frequency of word occurances and would like to return
a key/value list sorted descending by frequency.

So I need to quickly see if a word (key) is in the list, but later
sort the list descending by values.

Any ideas on how to do this efficiently?

Thanks,

Jim

Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.