|
28 | 28 | //! |
29 | 29 | //! # `HeaderMap` |
30 | 30 | //! |
31 | | -//! `HeaderMap` is a map structure of header names highly optimized for use |
32 | | -//! cases common with HTTP. It is a [multimap] structure, where each header name |
33 | | -//! may have multiple associated header values. Given this, some of the APIs |
34 | | -//! diverge from [`HashMap`]. |
| 31 | +//! The [`HeaderMap`] type is a specialized |
| 32 | +//! [multimap](<https://en.wikipedia.org/wiki/Multimap>) structure for storing |
| 33 | +//! header names and values. It is designed specifically for efficient |
| 34 | +//! manipulation of HTTP headers. It supports multiple values per header name |
| 35 | +//! and provides specialized APIs for insertion, retrieval, and iteration. |
35 | 36 | //! |
36 | | -//! ## Overview |
37 | | -//! |
38 | | -//! Just like `HashMap` in Rust's stdlib, `HeaderMap` is based on [Robin Hood |
39 | | -//! hashing]. This algorithm tends to reduce the worst case search times in the |
40 | | -//! table and enables high load factors without seriously affecting performance. |
41 | | -//! Internally, keys and values are stored in vectors. As such, each insertion |
42 | | -//! will not incur allocation overhead. However, once the underlying vector |
43 | | -//! storage is full, a larger vector must be allocated and all values copied. |
44 | | -//! |
45 | | -//! ## Deterministic ordering |
46 | | -//! |
47 | | -//! Unlike Rust's `HashMap`, values in `HeaderMap` are deterministically |
48 | | -//! ordered. Roughly, values are ordered by insertion. This means that a |
49 | | -//! function that deterministically operates on a header map can rely on the |
50 | | -//! iteration order to remain consistent across processes and platforms. |
51 | | -//! |
52 | | -//! ## Adaptive hashing |
53 | | -//! |
54 | | -//! `HeaderMap` uses an adaptive hashing strategy in order to efficiently handle |
55 | | -//! most common cases. All standard headers have statically computed hash values |
56 | | -//! which removes the need to perform any hashing of these headers at runtime. |
57 | | -//! The default hash function emphasizes performance over robustness. However, |
58 | | -//! `HeaderMap` detects high collision rates and switches to a secure hash |
59 | | -//! function in those events. The threshold is set such that only denial of |
60 | | -//! service attacks should trigger it. |
61 | | -//! |
62 | | -//! ## Limitations |
63 | | -//! |
64 | | -//! `HeaderMap` can store a maximum of 32,768 headers (header name / value |
65 | | -//! pairs). Attempting to insert more will result in a panic. |
66 | | -//! |
67 | | -//! [`HeaderName`]: struct.HeaderName.html |
68 | | -//! [`HeaderMap`]: struct.HeaderMap.html |
69 | | -//! [multimap]: https://en.wikipedia.org/wiki/Multimap |
70 | | -//! [`HashMap`]: https://doc.rust-lang.org/std/collections/struct.HashMap.html |
71 | | -//! [Robin Hood hashing]: https://en.wikipedia.org/wiki/Hash_table#Robin_Hood_hashing |
| 37 | +//! [*See also the `HeaderMap` type.*](HeaderMap) |
72 | 38 |
|
73 | 39 | mod map; |
74 | 40 | mod name; |
|
0 commit comments