Qhov txawv ntawm Hashtable thiab Hashmap

Qhov txawv ntawm Hashtable thiab Hashmap
Qhov txawv ntawm Hashtable thiab Hashmap

Video: Qhov txawv ntawm Hashtable thiab Hashmap

Video: Qhov txawv ntawm Hashtable thiab Hashmap
Video: Ib Sim Niam Txiv Tsis Txawj Sib Hlub by Paj Nyiag Lauj ( Nkauj Tawm Tshiab.2022 ) 2024, Hlis ntuj nqeg
Anonim

Hashtable vs Hashmap

Hashtable thiab cov hashmaps yog cov ntaub ntawv siv tau zoo hnub no rau feem ntau ntawm cov ntawv thov hauv web thiab ntau lwm daim ntawv thov ib yam nkaus. Cov qauv ntaub ntawv no pab txheeb cov ntaub ntawv tshwj xeeb raws li nws cov cim thiab cov txiaj ntsig cuam tshuam. Yeej, cov qauv ntaub ntawv no pab cov neeg tsim khoom kom yooj yim thiab ua tau zoo txheeb xyuas feem ntau ntawm cov cim, tseem hu ua cov yuam sij, raws li lawv cov txiaj ntsig. Tag nrho cov txheej txheem kev tsim cov ntaub ntawv no tau ua tiav nrog kev pab ntawm hash functions.

Hashtable Data Structure

Hauv kev tshawb fawb hauv computer, lub hashtable tuaj yeem txhais tau tias yog cov qauv ntaub ntawv, uas muaj peev xwm khaws cov ntaub ntawv loj uas muaj qee qhov tseem ceeb, tseem hu ua cov yuam sij. Thaum khaws cov yuam sij no, lawv yuav tsum tau ua ke nrog lwm daim ntawv teev npe, hu ua array. Qhov kev sib txuas tag nrho ntawm cov yuam sij nrog arrays ua tiav los ntawm kev siv cov haujlwm hash.

Lub hom phiaj tseem ceeb ntawm cov haujlwm hash no yog txhawm rau txuas txhua tus yuam sij muab rau nws qhov sib raug thiab sib piv tus nqi hauv cov array. Cov txheej txheem no hu ua hashing. Thiab qhov no feem ntau yog ua tiav tom qab kom raug thiab ua tiav formatting lub hashtable, kom tsis muaj teeb meem tsis xwm yeem tshwm sim thaum nws ua haujlwm.

Kev ua tiav thiab ua haujlwm tau zoo ntawm lub hashtable yog nyob ntawm qhov ua tau zoo tsim thiab formatted hash functions. Feem ntau muaj txiaj ntsig hash muaj nuj nqi muab kev kuaj xyuas tag nrho ntawm cov yuam sij thiab ntawm kev faib tawm hauv cov npe ntawm array. Qee zaum thaum lub sijhawm ua haujlwm ntawm hash functions, hash kev sib tsoo yuav tshwm sim. Yog vim li cas rau qhov kev sib tsoo no yog qhov tshwm sim ntawm ob qhov sib txawv ntawm cov yuam sij sib raug rau tib tus nqi tam sim no hauv array.

Yuav daws qhov teeb meem kev sib tsoo no, cov haujlwm hash feem ntau rov ua tiav cov qauv ntaub ntawv kom pom qee qhov sib txawv ntawm qhov tseem ceeb rau tib tus yuam sij. Txawm hais tias cov yuam sij hashable raug kho nyob rau hauv tus lej, tab sis tseem cov yuam sij sib npaug kuj tuaj yeem dhau los ua qhov laj thawj ntawm kev sib tsoo hash.

Hashmap Cov Ntaub Ntawv Structures

Txawm hais tias lub hashtable thiab hashmap yog cov npe muab rau tib cov ntaub ntawv qauv vim tias lawv lub hom phiaj ntawm kev teeb tsa yog tib yam, tab sis tseem muaj qhov sib txawv ntawm ib feeb uas cov no tuaj yeem faib tau yooj yim. Thaum tham txog cov haujlwm hash thiab cov hash sib tsoo, ces tus hashmap kuj pom cov khoom zoo sib xws li ntawm hashable. Ib yam li ntawd, qhov tseem ceeb thiab cov yuam sij tam sim no nyob rau hauv cov ntaub ntawv qauv tsis yog serialized zoo li ntawm cov hashtable, qhov twg cov txiaj ntsig no tau txheeb xyuas.

Qhov txawv ntawm Hashtable thiab Hashmap:

Qhov sib txawv feeb uas muaj nyob nruab nrab ntawm cov hashtable thiab cov ntaub ntawv hashmap yog muab hauv qab no:

• Hashmap tso cai rau qhov tsis muaj nuj nqis los ua ob qho ntawm nws cov yuam sij thiab cov txiaj ntsig, thaum lub hashtable tsis tso cai rau qhov tsis muaj nuj nqis hauv cov ntaub ntawv tsim qauv.

• Lub hashmap tsis tuaj yeem muaj cov yuam sij sib npaug hauv nws vim li cas thiaj li muaj cov yuam sij tsuas yog yuav tsum tau kos npe nrog tus nqi nkaus xwb. Tab sis lub hashtable tso cai rau cov yuam sij sib npaug hauv nws.

• Lub hashmap muaj ib qho iterator uas yog qhov yooj yim tsis muaj kev nyab xeeb tab sis tus hashtable muaj tus lej suav, uas tsis muaj kev nyab xeeb.

• Kev nkag mus rau hashtable yog synchronized ntawm lub rooj thaum nkag mus rau hashmap tsis synchronized.

Pom zoo: