1 //! This crate is a Rust port of Google's high-performance [SwissTable] hash
2 //! map, adapted to make it a drop-in replacement for Rust's standard `HashMap`
3 //! and `HashSet` types.
5 //! The original C++ version of [SwissTable] can be found [here], and this
6 //! [CppCon talk] gives an overview of how the algorithm works.
8 //! [SwissTable]: https://abseil.io/blog/20180927-swisstables
9 //! [here]: https://github.com/abseil/abseil-cpp/blob/master/absl/container/internal/raw_hash_set.h
10 //! [CppCon talk]: https://www.youtube.com/watch?v=ncHmEUmJZf4
23 nonnull_slice_from_raw_parts
,
24 maybe_uninit_array_assume_init
,
25 build_hasher_simple_hash_one
30 clippy
::module_name_repetitions
,
31 clippy
::must_use_candidate
,
32 clippy
::option_if_let_else
,
33 clippy
::redundant_else
,
35 clippy
::missing_safety_doc
,
36 clippy
::missing_errors_doc
38 #![warn(missing_docs)]
39 #![warn(rust_2018_idioms)]
45 #[cfg_attr(test, macro_use)]
48 #[cfg(feature = "nightly")]
50 doc_comment
::doctest
!("../README.md");
55 #[cfg(feature = "raw")]
56 /// Experimental and unsafe `RawTable` API. This module is only available if the
57 /// `raw` feature is enabled.
59 // The RawTable API is still experimental and is not properly documented yet.
60 #[allow(missing_docs)]
65 #[cfg(feature = "rayon")]
66 /// [rayon]-based parallel iterator types for hash maps.
67 /// You will rarely need to interact with it directly unless you have need
68 /// to name one of the iterator types.
70 /// [rayon]: https://docs.rs/rayon/1.0/rayon
72 pub use crate::external_trait_impls
::rayon
::raw
::*;
75 #[cfg(not(feature = "raw"))]
78 mod external_trait_impls
;
80 #[cfg(feature = "rustc-internal-api")]
86 //! A hash map implemented with quadratic probing and SIMD lookup.
87 pub use crate::map
::*;
89 #[cfg(feature = "rustc-internal-api")]
90 pub use crate::rustc_entry
::*;
92 #[cfg(feature = "rayon")]
93 /// [rayon]-based parallel iterator types for hash maps.
94 /// You will rarely need to interact with it directly unless you have need
95 /// to name one of the iterator types.
97 /// [rayon]: https://docs.rs/rayon/1.0/rayon
99 pub use crate::external_trait_impls
::rayon
::map
::*;
103 //! A hash set implemented as a `HashMap` where the value is `()`.
104 pub use crate::set
::*;
106 #[cfg(feature = "rayon")]
107 /// [rayon]-based parallel iterator types for hash sets.
108 /// You will rarely need to interact with it directly unless you have need
109 /// to name one of the iterator types.
111 /// [rayon]: https://docs.rs/rayon/1.0/rayon
113 pub use crate::external_trait_impls
::rayon
::set
::*;
117 pub use crate::map
::HashMap
;
118 pub use crate::set
::HashSet
;
120 /// The error type for `try_reserve` methods.
121 #[derive(Clone, PartialEq, Eq, Debug)]
122 pub enum TryReserveError
{
123 /// Error due to the computed capacity exceeding the collection's maximum
124 /// (usually `isize::MAX` bytes).
127 /// The memory allocator returned an error
129 /// The layout of the allocation request that failed.
130 layout
: alloc
::alloc
::Layout
,
134 /// Wrapper around `Bump` which allows it to be used as an allocator for
135 /// `HashMap`, `HashSet` and `RawTable`.
137 /// `Bump` can be used directly without this wrapper on nightly if you enable
138 /// the `allocator-api` feature of the `bumpalo` crate.
139 #[cfg(feature = "bumpalo")]
140 #[derive(Clone, Copy, Debug)]
141 pub struct BumpWrapper
<'a
>(pub &'a bumpalo
::Bump
);
143 #[cfg(feature = "bumpalo")]
147 let bump
= Bump
::new();
148 let mut map
= HashMap
::new_in(BumpWrapper(&bump
));