Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Sorting a hash table based on value (not key)

Reply
Thread Tools

Sorting a hash table based on value (not key)

 
 
vikas
Guest
Posts: n/a
 
      08-16-2007
Hi,

I want to sort a hash table based on value, not key. (key is of type
string which hashes to some value and in each node i am maintaining
frequency of that word(string) which is to be updated when that word
is found. Now i want to print the words in decreasing order of
frequency.

 
Reply With Quote
 
 
 
 
Mark Bluemel
Guest
Posts: n/a
 
      08-16-2007
vikas wrote:
> Hi,
>
> I want to sort a hash table based on value, not key.


Good luck. Did you have a question?
 
Reply With Quote
 
 
 
 
Chris Dollin
Guest
Posts: n/a
 
      08-16-2007
vikas wrote:

> I want to sort a hash table based on value, not key. (key is of type
> string which hashes to some value and in each node i am maintaining
> frequency of that word(string) which is to be updated when that word
> is found. Now i want to print the words in decreasing order of
> frequency.


So what's not working?

--
Chris "crystal ball in use elsewhere" Dollin

Hewlett-Packard Limited Cain Road, Bracknell, registered no:
registered office: Berks RG12 1HN 690597 England

 
Reply With Quote
 
CBFalconer
Guest
Posts: n/a
 
      08-16-2007
vikas wrote:
>
> I want to sort a hash table based on value, not key. (key is of
> type string which hashes to some value and in each node i am
> maintaining frequency of that word(string) which is to be
> updated when that word is found. Now i want to print the words
> in decreasing order of frequency.


Take a look at the wdfreq.c demonstration application in
hashlib.zip release. See:

<http://cbfalconer.home.att.net/download/>

The leading comment in that source is:

/* Demonstration filter.
This scans an input file for words, which consist of alpha-
characters only, delimited by anything else. Each word is
converted into lower case, and entered into a database with
an occurance count. When all entry is complete the word
list is formed and sorted, and the results dumped in order
of number of occurances.

The database is implemented through use of the hashlib
package. When loaded, a singly linked list is formed from
the content by the hashwalk feature, and sorted with a
mergesort.

by C.B. Falconer, 2002-03-12
Put in public domain. Attribution appreciated.
*/

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>



--
Posted via a free Usenet account from http://www.teranews.com

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
hash of hash of hash of hash in c++ rp C++ 1 11-10-2011 04:45 PM
Sorting keys of hash based on value Aldric Giacomoni Ruby 4 03-22-2010 08:35 PM
hash key to var name of value hash key value Une bévue Ruby 5 08-10-2006 04:05 PM
Sorting a hash containing a hash of hashes IanW Perl Misc 3 12-14-2005 03:02 PM
[Nuby] Sorting a Hash and keepint it as a Hash? Williams, Chris Ruby 3 12-13-2004 09:04 PM



Advertisments