Thaum 13th lub caij (tus nqi tseem ceeb) yuav los rau hauv Hashmap, nws yuav nce nws qhov loj los ntawm default 2 4=16 thoob rau 2 5=32 thoob. Lwm txoj hauv kev los xam qhov loj me: Thaum tus nqi thauj khoom sib piv (m / n) nce mus txog 0.75 ntawm lub sijhawm ntawd, hashmap nce nws lub peev xwm.
Yuav ua li cas thaum HashMap hloov pauv?
5 Teb. Lub neej ntawd Load Factor yog 0.75, i.e. 3/4, uas txhais tau hais tias lub rooj sab hauv hash yuav raug hloov pauv thaum 75 ntawm 100 qhov tseem ceeb tau ntxiv. FYI: resize tsuas yog hu ua ob zaug xwb. Ib zaug thaum thawj tus nqi ntxiv, thiab ib zaug thaum nws tau txais 75% tag nrho.
Puas yog HashMap loj cuam tshuam rau kev ua haujlwm ntawm HashMap?
Iteration tshaj sau cov views yuav tsum tau lub sij hawm proportional rau "muaj peev xwm" ntawm HashMap piv txwv (tus naj npawb ntawm thoob) ntxiv rau nws qhov loj me (tus naj npawb ntawm qhov tseem ceeb-tus nqi mappings). Yog li, nws tseem ceeb heev kom tsis txhob teeb tsa lub peev xwm pib siab dhau (lossis qhov khoom thauj khoom tsawg dhau) yog tias qhov ua tau zoo dua yog qhov tseem ceeb.
Dab tsi yog qhov loj me ntawm HashMap?
Lub peev xwm pib pib ntawm HashMap yog 2 4i.e 16. Lub peev xwm ntawm HashMap yog ob npaug txhua zaus nws ncav cuag threshold.
Puas yog HashMap kho qhov loj?
Fixed-Size: Qhov qhov siab tshaj ntawm cov khoom uas tuaj yeem ntxiv rau hauv hashmap yog kho los ntawm tus tsimthiab qhov loj ntawm lub hauv hashmap array kuj yog tsau. Qhov no txhais tau tias tsis muaj resizing lossis rehashing ntawm cov khoom.