HashMap

HashDoS1 ๊ณต๊ฒฉ์œผ๋กœ๋ถ€ํ„ฐ ๋ณดํ˜ธ๋˜๋Š” ํ‘œ์ค€ ํ•ด์‹œ ๋งต์ž…๋‹ˆ๋‹ค.

Standard hash map with protection against HashDoS attacks:

use std::collections::HashMap;

fn main() {
    let mut page_counts = HashMap::new();
    page_counts.insert("Adventures of Huckleberry Finn".to_string(), 207);
    page_counts.insert("Grimms' Fairy Tales".to_string(), 751);
    page_counts.insert("Pride and Prejudice".to_string(), 303);

    if !page_counts.contains_key("Les Misรฉrables") {
        println!("We've know about {} books, but not Les Misรฉrables.",
                 page_counts.len());
    }

    for book in ["Pride and Prejudice", "Alice's Adventure in Wonderland"] {
        match page_counts.get(book) {
            Some(count) => println!("{book}: {count} pages"),
            None => println!("{book} is unknown.")
        }
    }
}

์—ญ์ฃผ

1

Hash table์„ ์‚ฌ์šฉํ•˜๋Š” ์›น์„œ๋ฒ„์— ํŒŒ๋ผ๋ฏธํ„ฐ๊ฐ€ ๋งŽ์€ POST๋ฅผ ํ˜ธ์ถœํ•˜์—ฌ Hash table ์ถฉ๋Œ์„ ์œ ๋„ํ•˜์—ฌ CPU ๋ถ€ํ•˜๋ฅผ ๋ฐœ์ƒ์‹œํ‚ค๋Š” ๊ณต๊ฒฉ ๋ฐฉ๋ฒ•.

  • POST, GET ์š”์ฒญ์˜ ํŒŒ๋ผ๋ฉ”ํ„ฐ์˜ ๋น ๋ฅธ ์ ‘๊ทผ์„ ์œ„ํ•ด ์›น์„œ๋ฒ„๋Š” ํŒŒ๋ผ๋ฉ”ํ„ฐ๋ฅผ Hash table๋กœ ๊ด€๋ฆฌํ•˜๋Š”๋ฐ, POST ์š”์ฒญ์‹œ ์ „๋‹ฌํ•  ์ˆ˜ ์žˆ๋Š” ํŒŒ๋ผ๋ฉ”ํ„ฐ์˜ ์ˆ˜์˜ ์ œํ•œ์ด ์—†๋‹ค๋Š” ์ ์„ ์ด์šฉํ•œ ๊ณต๊ฒฉ ๋ฐฉ๋ฒ•