အပိုင်း(၄)- HashMap ထဲက Node များအကြောင်း (Data Structures in Action)

Node<K,V>[] table;//internal array of hashmap

HashMap ရဲ့ အထဲမှာ Node တွေကို သိမ်းတဲ့ table array ရှိပါတယ်။ ယခင် bix ming က h ကို အောက်ပါအတိုင်း လုပ်ရင် array ရဲ့ index ကို ရတာပါ။ index ညွုန်ထားတဲ့ အခန်းကို bucket လို့ခေါ်ပါတယ်။

int index = (n - 1) & hash

HashMap မှာ internal array တစ်ခုတည်းရှိတာကို သတိချပ်ပါ။
Node မှာ Linked List တစ်ခုလုံးကို ညွုန်တာပါ။ ဒီနေရာမှာ သိထားဖို့က Linked list တခုလုံးကို ညွုန်တယ်ဆိုတာ Linked List ရဲ့ root node ကို သိမ်းပြီး လိုမှ next နဲ့ ပြန်ယူတာ (traverse) လုပ်တာကို ဆိုလိုတာပါ။

TreeNode မှာတော့ Red Black Tree ကို သိမ်းပါတယ်။ ထို့အတူပါပဲ root node ကို သိမ်းတာပါ။

Linked List နဲ့ Red Black Tree treversal ကိုတော့ ချန်လှပ်ထားပါမယ်။ သူတို့က တခြား လေ့လာရမယ့် data structures တွေမို့ပါ။

Leave a Reply