esseddirectlyHashingisusedwhenpossibledatasetsaretoobigforarrays,buttheactualdatasetsarequitesmallWhenishashingused?,(1)?Hashingfollowsanumberofsteps:First,thedataitemsareconvertedtoanaturalnumberThisnumberisthenconverted,usingahashfunction,toadifferentnumberwhichfallswithinthehashtableTheoriginaldataisthenstoredinthehashtable,whereitcanbequicklyretrievedConvertingtonaturalnumbersIfnumericaldataisbeinghashed,itcaneasilybeconvertedtonaturalnumbersIftextisbeingconverted,putea“value”:Thestringcanbetakenasanumberbase256,“hello”-takethevalueofh,addtoitthevalueoftheemultipliedbyaprime,eg29,thenaddthevalueofthel,multipliedby29and31,,eachelementwasgivenakey,,,andisbeinginsertedintoahashtableofsizem,thefollowingisasimpleandreasonablyeffectivehashfunction:h(k)=kmodmIfthishashfunctionisused,mshouldbeprimetoincreasethespreadofdataInsertingdataintoahashtableBeforedatacanbeadded,,,anditssizeshouldbeaprime(orspaceiswasted)InsertingdataOncethekeyhasbeenhashed,itgivessomevalueh(k).TheoriginaldatacanthenbeinsertedintothearraywiththisasindexIfthisspaceisfull,
H a s h i n g 来自淘豆网www.taodocs.com转载请标明出处.