c++


What would be a good hash function for this list of English words?


Here's my code on Github if anyone would like to see it :
https://github.com/daicain/Hashing-Project
Currently, I am using a tablesize of 80, since I have about 73 words in the file.
My current method of hashing is pretty basic and generic. I add up the ASCII value of the letters after I make them all lowercase, then I mod (%) by the tablesize (80 currently). I am getting a lot of collisions, and a lot of unused bucket/indexes. Since I know exactly which words I need to hash and how many, are there better methods to use, for the least possible collisions? My goal is to get 6 or less.
Also, side question. Once the words are in the hashtable, if I want to look up a certain word, but type that word incorrectly, or scrambled up, how would I find it in the hashtable?
For example, if I have "apple" in the hashtable, and for my search, I use "leppa", which is apple spells backward, whats a good way to unscramble "leppa" in such a way that, apple would come out?
Please ask me if you're unsure about what I just ask, sorry if I'm not clear!
Murmur hash is considered fast and will probably give good distribution
http://en.wikipedia.org/wiki/MurmurHash
In order to look for a "scrambled" text in a hash, you need to use hash-function that is agnostic to the letters order - pretty bad idea since all permutations will be in the same hash bucket
Try md5, you won't have collisions in your dictionary.
You may simply use std::hash:
#include <string>
#include <iostream>
#include <functional>
int main()
{
std::string str = "air conditioner";
size_t h = std::hash<std::string>()(str);
std::cout << "hash of \"" << str << "\" is " << h << std::endl;
}
commonly it might be implemented as fnv1 hash. Another good hash function is murmur. Check related question on stackexchange for other common hash functions.

Related Links

Best practice to set up qt application that works for different DPI
openssl fips error on arm Linux
C++ - Pretty way to make frequencies add up to 1
integerset obtaining the given array
Arduino Invalid conversion from 'char' to 'char*'
virtual ClistCtrl with checkboxes on displayed report list style
Error when modifying vector member of another class
Interrupt Service Routine can't be called directly
Lambda capture by default reference vs named
convert bitset<64> to string every 8 bit
argument of type “int” incompatible with parameter of type “int”
When is the correct time to call restoreState for QHeaderView?
How does it pass lvalue reference to std::forward with CRTP?
Using lower_bound function in loop is giving runtime error?
Problems with rand(), always taking the same random generated number [duplicate]
Reading Credentials file fails with error 32

Categories

HOME
web
loadrunner
loops
recaptcha
sendmail
bloomberg
mariadb
mapkit
android-animation
inform7
aurelia-router
sage
soundcloud
worksheet-function
bpm
ccache
relation
salt-stack
affinity
axon
xamarin.mac
conv-neural-network
ietf-netmod-yang
smt
systemml
laravel-blade
media
virtuoso
indexof
webcam
uppaal
inorder
radio
appery.io
google-tv
sqlcmd
sphero-api
devexpress-wpf
khan-academy
winlims
evosuite
snobol
prime-factoring
sceditor
cpio
aide-ide
compass
spoon
client-side
lunrjs
snap-lang
into-outfile
assignment-operator
cmfctoolbar
objdump
apache-roller
google-client
visual-studio-2010-sp1
jxa
grunt-contrib-cssmin
mongojs
sapb1
sql-job
comfortable-mexican-sofa
jaggery-js
bonsaijs
restkit-0.20
cxf-client
form-helpers
start-stop-daemon
triples
invalidation
opendocument
maptiler
citrix-access-gateway
gideros
mic-1
jvm-crash
ruby-on-rails-plugins
pmp
alpha-five
struts-config
actinic
bionic
ubuntu-9.10
iphone-3gs
alasset
habari
progressive-enhancement
sqlmetal

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile