index = (n-1) & hash;
ဒါက HashMap မှာ index ကိုရှာတဲ့ Algorithm ပါ။
ရှင်းပြရရင်
(n-1) = 0b1001; // number 9(assumed n = 10)
hash = 0b1010 //number 9
// 1 တူတာတွေမီးလင်းတော့
1001
&
1010 = 1000
စာကြွင်း
တခြား bitwise opertaion တွေက
union operation (OR gate) ရောလိုက်တာနဲ့
invert operation(XOR gate) ပြောင်းပြန်လှန်လိုက်တာ တို့ဖြစ်ပါတယ်။
Union Operation (OR gate sample)
1001
OR
1010 = 1011
Invert Operation
1001
OR
1010 = 0110
တို့ဖြစ်ကြပါတယ်။ နောက်ဆုံး XOR ကလွယ်ပါတယ်။ 1001 x bit mask(1010) လို့ မှတ်ထားလိုက်ပါ။ ပြီးရင် 1010 ရဲ့ ပြောင်းပြန်ဂဏန်းကို ချရေးလိုက်ရုံပါပဲ။
Top comments (0)