[DA] Hash Table

Hash Table: 킀와 값을 λ°›μ•„ ν‚€λ₯Ό ν•΄μ‹±ν•˜μ—¬ λ‚˜μ˜¨ index에 값을 μ €μž₯ν•˜λŠ” μ„ ν˜• 자료ꡬ쑰

Hash Func: μž…λ ₯받은 값을 νŠΉμ • λ²”μœ„ λ‚΄ 숫자둜 λ³€κ²½ν•˜λŠ” ν•¨μˆ˜

Array, Map, Set 으둜 ν‘œν˜„ κ°€λŠ₯

Code

// Array
const table = [];
table['key'] = 100;
console.log(table['key']);

// Map
const table2 = new Map();
table2.set('key', 100);
console.log(table2['key']); // 잘λͺ»λœ 방법
console.log(table2.get('key'));
console.log(table2.keys());
console.log(table2.values());
table2.clear();
console.log(table2.keys());
console.log(table2.values());

// Set
const table3 = new Set();
table3.add('key');
console.log(table.has('key'));

Categories:

Updated:

Leave a comment