[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: finding keys in a table
- From: Jelle Huisman <jelle@...>
- Date: Thu, 21 Feb 2008 14:24:58 +0000
I need a frequency list of all characters in a text file and I try to
use a table for this but I'm not totally sure if this is the best way to
solve my problem. Anyway I setup a table "count" with the characters as
key and a counter as value. When I iterate over my data I want to:
(1) lookup if the current character already exists as a key in the table.
(2a) If it does exist I increment the value for key currentchar with 1
(2b) else I add a new entry: currentchar=1
(3) Later I sort the table and print my freq.list.
The two questions I have are: is this the best/most efficient/fastest
way to do this?
Second: How do I check if a key exists? (I don't think I can use an
inverted table because I'll end up with duplicate keys, or not?)
Thanks for some advice,