diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index d70b2b5..d6d7742 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -1,40 +1,3 @@ # The Rust Code of Conduct -A version of this document [can be found online](https://www.rust-lang.org/conduct.html). - -## Conduct - -**Contact**: [rust-mods@rust-lang.org](mailto:rust-mods@rust-lang.org) - -* We are committed to providing a friendly, safe and welcoming environment for all, regardless of level of experience, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, religion, nationality, or other similar characteristic. -* On IRC, please avoid using overtly sexual nicknames or other nicknames that might detract from a friendly, safe and welcoming environment for all. -* Please be kind and courteous. There's no need to be mean or rude. -* Respect that people have differences of opinion and that every design or implementation choice carries a trade-off and numerous costs. There is seldom a right answer. -* Please keep unstructured critique to a minimum. If you have solid ideas you want to experiment with, make a fork and see how it works. -* We will exclude you from interaction if you insult, demean or harass anyone. That is not welcome behavior. We interpret the term "harassment" as including the definition in the Citizen Code of Conduct; if you have any lack of clarity about what might be included in that concept, please read their definition. In particular, we don't tolerate behavior that excludes people in socially marginalized groups. -* Private harassment is also unacceptable. No matter who you are, if you feel you have been or are being harassed or made uncomfortable by a community member, please contact one of the channel ops or any of the [Rust moderation team][mod_team] immediately. Whether you're a regular contributor or a newcomer, we care about making this community a safe place for you and we've got your back. -* Likewise any spamming, trolling, flaming, baiting or other attention-stealing behavior is not welcome. - -## Moderation - - -These are the policies for upholding our community's standards of conduct. If you feel that a thread needs moderation, please contact the [Rust moderation team][mod_team]. - -1. Remarks that violate the Rust standards of conduct, including hateful, hurtful, oppressive, or exclusionary remarks, are not allowed. (Cursing is allowed, but never targeting another user, and never in a hateful manner.) -2. Remarks that moderators find inappropriate, whether listed in the code of conduct or not, are also not allowed. -3. Moderators will first respond to such remarks with a warning. -4. If the warning is unheeded, the user will be "kicked," i.e., kicked out of the communication channel to cool off. -5. If the user comes back and continues to make trouble, they will be banned, i.e., indefinitely excluded. -6. Moderators may choose at their discretion to un-ban the user if it was a first offense and they offer the offended party a genuine apology. -7. If a moderator bans someone and you think it was unjustified, please take it up with that moderator, or with a different moderator, **in private**. Complaints about bans in-channel are not allowed. -8. Moderators are held to a higher standard than other community members. If a moderator creates an inappropriate situation, they should expect less leeway than others. - -In the Rust community we strive to go the extra step to look out for each other. Don't just aim to be technically unimpeachable, try to be your best self. In particular, avoid flirting with offensive or sensitive issues, particularly if they're off-topic; this all too often leads to unnecessary fights, hurt feelings, and damaged trust; worse, it can drive people away from the community entirely. - -And if someone takes issue with something you said or did, resist the urge to be defensive. Just stop doing what it was they complained about and apologize. Even if you feel you were misinterpreted or unfairly accused, chances are good there was something you could've communicated better — remember that it's your responsibility to make your fellow Rustaceans comfortable. Everyone wants to get along and we are all here first and foremost because we want to talk about cool technology. You will find that people will be eager to assume good intent and forgive as long as you earn their trust. - -The enforcement policies listed above apply to all official Rust venues; including official IRC channels (#rust, #rust-internals, #rust-tools, #rust-libs, #rustc, #rust-beginners, #rust-docs, #rust-community, #rust-lang, and #cargo); GitHub repositories under rust-lang, rust-lang-nursery, and rust-lang-deprecated; and all forums under rust-lang.org (users.rust-lang.org, internals.rust-lang.org). For other projects adopting the Rust Code of Conduct, please contact the maintainers of those projects for enforcement. If you wish to use this code of conduct for your own project, consider explicitly mentioning your moderation policy or making a copy with your own moderation policy so as to avoid confusion. - -*Adapted from the [Node.js Policy on Trolling](http://blog.izs.me/post/30036893703/policy-on-trolling) as well as the [Contributor Covenant v1.3.0](https://www.contributor-covenant.org/version/1/3/0/).* - -[mod_team]: https://www.rust-lang.org/team.html#Moderation-team +The Code of Conduct for this repository [can be found online](https://www.rust-lang.org/conduct.html). \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index bc4fb16..191ef72 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,11 +2,12 @@ name = "rustc-hash" version = "1.1.0" authors = ["The Rust Project Developers"] -description = "speedy, non-cryptographic hash used in rustc" +description = "A speedy, non-cryptographic hashing algorithm used by rustc and Firefox" license = "Apache-2.0/MIT" readme = "README.md" keywords = ["hash", "hasher", "fxhash", "rustc"] repository = "https://github.com/rust-lang/rustc-hash" +edition = "2018" [features] default = ["std"] diff --git a/LICENSE-APACHE b/LICENSE-APACHE index 16fe87b..a7e77cb 100644 --- a/LICENSE-APACHE +++ b/LICENSE-APACHE @@ -173,29 +173,4 @@ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. -END OF TERMS AND CONDITIONS - -APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - -Copyright [yyyy] [name of copyright owner] - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. +END OF TERMS AND CONDITIONS \ No newline at end of file diff --git a/LICENSE-MIT b/LICENSE-MIT index 31aa793..468cd79 100644 --- a/LICENSE-MIT +++ b/LICENSE-MIT @@ -20,4 +20,4 @@ SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. +DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md index b79f8a2..05991b6 100644 --- a/README.md +++ b/README.md @@ -3,21 +3,19 @@ [![crates.io](https://img.shields.io/crates/v/rustc-hash.svg)](https://crates.io/crates/rustc-hash) [![Documentation](https://docs.rs/rustc-hash/badge.svg)](https://docs.rs/rustc-hash) -A speedy hash algorithm used within rustc. The hashmap in liballoc by -default uses SipHash which isn't quite as speedy as we want. In the -compiler we're not really worried about DOS attempts, so we use a fast -non-cryptographic hash. - -This is the same as the algorithm used by Firefox -- which is a -homespun one not based on any widely-known algorithm -- though -modified to produce 64-bit hash values instead of 32-bit hash -values. It consistently out-performs an FNV-based hash within rustc -itself -- the collision rate is similar or slightly worse than FNV, -but the speed of the hash function itself is much higher because it -works on up to 8 bytes at a time. +A speedy, non-cryptographic hashing algorithm used by `rustc` and Firefox. +The [hash map in `std`](https://doc.rust-lang.org/std/collections/struct.HashMap.html) uses SipHash by default, which provides resistance against DOS attacks. +These attacks aren't as much of a concern in the compiler so we prefer to use the quicker, non-cryptographic Fx algorithm. + +The Fx algorithm is a unique one used by Firefox. It is fast because it can hash eight bytes at a time. +Within `rustc`, it consistently outperforms every other tested algorithm (such as FNV). +The collision rate is similar or slightly worse than other low-quality hash functions. ## Usage +This crate provides `FxHashMap` and `FxHashSet` as collections. +They are simply type aliases for their `std::collection` counterparts using the Fx hasher. + ```rust use rustc_hash::FxHashMap; @@ -27,12 +25,9 @@ map.insert(22, 44); ### `no_std` -This crate can be used as a `no_std` crate by disabling the `std` -feature, which is on by default, as follows: +The `std` feature is on by default to enable collections. +It can be turned off in `Cargo.toml` like so: ```toml rustc-hash = { version = "1.1", default-features = false } ``` - -In this configuration, `FxHasher` is the only export, and the -`FxHashMap`/`FxHashSet` type aliases are omitted. diff --git a/src/lib.rs b/src/lib.rs index 15dc6ff..e765144 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,14 +1,4 @@ -// Copyright 2015 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Fast, non-cryptographic hash used by rustc and Firefox. +//! A speedy, non-cryptographic hashing algorithm used by `rustc` and Firefox. //! //! # Example //! @@ -16,6 +6,7 @@ //! # #[cfg(feature = "std")] //! # fn main() { //! use rustc_hash::FxHashMap; +//! //! let mut map: FxHashMap = FxHashMap::default(); //! map.insert(22, 44); //! # } @@ -46,11 +37,11 @@ use core::ops::BitXor; #[cfg(feature = "std")] use std::collections::{HashMap, HashSet}; -/// Type alias for a hashmap using the `fx` hash algorithm. +/// Type alias for a hash map that uses the Fx hashing algorithm. #[cfg(feature = "std")] pub type FxHashMap = HashMap>; -/// Type alias for a hashset using the `fx` hash algorithm. +/// Type alias for a hash set that uses the Fx hashing algorithm. #[cfg(feature = "std")] pub type FxHashSet = HashSet>;