зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1716518 - Upgrade fnv to v1.0.7. r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D117789
This commit is contained in:
Родитель
6fe46e2557
Коммит
4e0e951844
|
@ -1538,9 +1538,9 @@ checksum = "edb1016e8c600060e0099218442fff329a204f6316d6ec974d590d3281517a52"
|
|||
|
||||
[[package]]
|
||||
name = "fnv"
|
||||
version = "1.0.6"
|
||||
version = "1.0.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3"
|
||||
checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"
|
||||
|
||||
[[package]]
|
||||
name = "fog"
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"files":{"Cargo.toml":"8a89e16dc6b373aa151fb2d1221c699b39b1dd5599aa616897fa85511b71104f","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"65fdb6c76cd61612070c066eec9ecdb30ee74fb27859d0d9af58b9f499fd0c3e","README.md":"9398b0785fdaf32fe61dca3d6f16e69cf53ab2911c9435053d1ec962cd92b8fa","lib.rs":"0303c8c75e9cf35f5379f67cfc003ba0b51e9643dc8f3bd346322595d7685d97"},"package":"2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3"}
|
||||
{"files":{"Cargo.toml":"0854ced32611c6389356c0b43ae663da9d4480376c5f0825b82eb442dd84e8d8","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"65fdb6c76cd61612070c066eec9ecdb30ee74fb27859d0d9af58b9f499fd0c3e","README.md":"7653d488c5bdf93a3069bf41770650897b85815521f67f69a4a90d0fefb4fa1f","lib.rs":"32bf17ff841b4c285985d9e9df79c5099318c11bf0436ee8582dec30fc9ec826"},"package":"3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1"}
|
|
@ -3,7 +3,7 @@
|
|||
# When uploading crates to the registry Cargo will automatically
|
||||
# "normalize" Cargo.toml files for maximal compatibility
|
||||
# with all versions of Cargo and also rewrite `path` dependencies
|
||||
# to registry (e.g. crates.io) dependencies
|
||||
# to registry (e.g., crates.io) dependencies
|
||||
#
|
||||
# If you believe there's an error in this file please file an
|
||||
# issue against the rust-lang/cargo repository. If you're
|
||||
|
@ -12,7 +12,7 @@
|
|||
|
||||
[package]
|
||||
name = "fnv"
|
||||
version = "1.0.6"
|
||||
version = "1.0.7"
|
||||
authors = ["Alex Crichton <alex@alexcrichton.com>"]
|
||||
description = "Fowler–Noll–Vo hash function"
|
||||
documentation = "https://doc.servo.org/fnv/"
|
||||
|
@ -23,3 +23,7 @@ repository = "https://github.com/servo/rust-fnv"
|
|||
[lib]
|
||||
name = "fnv"
|
||||
path = "lib.rs"
|
||||
|
||||
[features]
|
||||
default = ["std"]
|
||||
std = []
|
||||
|
|
|
@ -78,4 +78,4 @@ set.insert(2);
|
|||
|
||||
[chongo]: http://www.isthe.com/chongo/tech/comp/fnv/index.html
|
||||
[faq]: https://www.rust-lang.org/en-US/faq.html#why-are-rusts-hashmaps-slow
|
||||
[graphs]: http://cglab.ca/~abeinges/blah/hash-rs/
|
||||
[graphs]: https://cglab.ca/~abeinges/blah/hash-rs/
|
||||
|
|
|
@ -21,53 +21,66 @@
|
|||
//! denial-of-service attacks, and can assume that its inputs are going to be
|
||||
//! small—a perfect use case for FNV.
|
||||
//!
|
||||
//!
|
||||
//! ## Using FNV in a `HashMap`
|
||||
//!
|
||||
//! The `FnvHashMap` type alias is the easiest way to use the standard library’s
|
||||
//! `HashMap` with FNV.
|
||||
//!
|
||||
//! ```rust
|
||||
//! use fnv::FnvHashMap;
|
||||
//!
|
||||
//! let mut map = FnvHashMap::default();
|
||||
//! map.insert(1, "one");
|
||||
//! map.insert(2, "two");
|
||||
//!
|
||||
//! map = FnvHashMap::with_capacity_and_hasher(10, Default::default());
|
||||
//! map.insert(1, "one");
|
||||
//! map.insert(2, "two");
|
||||
//! ```
|
||||
//!
|
||||
//! Note, the standard library’s `HashMap::new` and `HashMap::with_capacity`
|
||||
//! are only implemented for the `RandomState` hasher, so using `Default` to
|
||||
//! get the hasher is the next best option.
|
||||
//!
|
||||
//! ## Using FNV in a `HashSet`
|
||||
//!
|
||||
//! Similarly, `FnvHashSet` is a type alias for the standard library’s `HashSet`
|
||||
//! with FNV.
|
||||
//!
|
||||
//! ```rust
|
||||
//! use fnv::FnvHashSet;
|
||||
//!
|
||||
//! let mut set = FnvHashSet::default();
|
||||
//! set.insert(1);
|
||||
//! set.insert(2);
|
||||
//!
|
||||
//! set = FnvHashSet::with_capacity_and_hasher(10, Default::default());
|
||||
//! set.insert(1);
|
||||
//! set.insert(2);
|
||||
//! ```
|
||||
#![cfg_attr(feature = "std", doc = r#"
|
||||
|
||||
## Using FNV in a `HashMap`
|
||||
|
||||
The `FnvHashMap` type alias is the easiest way to use the standard library’s
|
||||
`HashMap` with FNV.
|
||||
|
||||
```rust
|
||||
use fnv::FnvHashMap;
|
||||
|
||||
let mut map = FnvHashMap::default();
|
||||
map.insert(1, "one");
|
||||
map.insert(2, "two");
|
||||
|
||||
map = FnvHashMap::with_capacity_and_hasher(10, Default::default());
|
||||
map.insert(1, "one");
|
||||
map.insert(2, "two");
|
||||
```
|
||||
|
||||
Note, the standard library’s `HashMap::new` and `HashMap::with_capacity`
|
||||
are only implemented for the `RandomState` hasher, so using `Default` to
|
||||
get the hasher is the next best option.
|
||||
|
||||
## Using FNV in a `HashSet`
|
||||
|
||||
Similarly, `FnvHashSet` is a type alias for the standard library’s `HashSet`
|
||||
with FNV.
|
||||
|
||||
```rust
|
||||
use fnv::FnvHashSet;
|
||||
|
||||
let mut set = FnvHashSet::default();
|
||||
set.insert(1);
|
||||
set.insert(2);
|
||||
|
||||
set = FnvHashSet::with_capacity_and_hasher(10, Default::default());
|
||||
set.insert(1);
|
||||
set.insert(2);
|
||||
```
|
||||
"#)]
|
||||
//!
|
||||
//! [chongo]: http://www.isthe.com/chongo/tech/comp/fnv/index.html
|
||||
//! [faq]: https://www.rust-lang.org/en-US/faq.html#why-are-rusts-hashmaps-slow
|
||||
//! [graphs]: http://cglab.ca/~abeinges/blah/hash-rs/
|
||||
//! [graphs]: https://cglab.ca/~abeinges/blah/hash-rs/
|
||||
|
||||
#![cfg_attr(not(feature = "std"), no_std)]
|
||||
|
||||
#[cfg(all(not(feature = "std"), test))]
|
||||
extern crate alloc;
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
use std::default::Default;
|
||||
#[cfg(feature = "std")]
|
||||
use std::hash::{Hasher, BuildHasherDefault};
|
||||
#[cfg(feature = "std")]
|
||||
use std::collections::{HashMap, HashSet};
|
||||
#[cfg(not(feature = "std"))]
|
||||
use core::default::Default;
|
||||
#[cfg(not(feature = "std"))]
|
||||
use core::hash::{Hasher, BuildHasherDefault};
|
||||
|
||||
/// An implementation of the Fowler–Noll–Vo hash function.
|
||||
///
|
||||
|
@ -115,16 +128,21 @@ impl Hasher for FnvHasher {
|
|||
pub type FnvBuildHasher = BuildHasherDefault<FnvHasher>;
|
||||
|
||||
/// A `HashMap` using a default FNV hasher.
|
||||
#[cfg(feature = "std")]
|
||||
pub type FnvHashMap<K, V> = HashMap<K, V, FnvBuildHasher>;
|
||||
|
||||
/// A `HashSet` using a default FNV hasher.
|
||||
#[cfg(feature = "std")]
|
||||
pub type FnvHashSet<T> = HashSet<T, FnvBuildHasher>;
|
||||
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
#[cfg(feature = "std")]
|
||||
use std::hash::Hasher;
|
||||
#[cfg(not(feature = "std"))]
|
||||
use alloc::vec::Vec;
|
||||
|
||||
fn fnv1a(bytes: &[u8]) -> u64 {
|
||||
let mut hasher = FnvHasher::default();
|
||||
|
|
Загрузка…
Ссылка в новой задаче