Skip to content

Commit

Permalink
Code diet 2
Browse files Browse the repository at this point in the history
  • Loading branch information
ehuss committed Nov 11, 2020
1 parent 7f0c826 commit 9053cfb
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions pretty-std-collections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,18 @@
use std::collections::HashMap;
// use std::collections::HashSet;
// use std::collections::VecDeque;
use std::hash::{BuildHasherDefault, Hasher};
// use std::hash::{BuildHasherDefault, Hasher};

struct MyLeafNode(i32); // helps to ensure we don't blindly replace substring "LeafNode"
// struct MyLeafNode(i32); // helps to ensure we don't blindly replace substring "LeafNode"

#[derive(Default)]
struct SimpleHasher { hash: u64 }
// #[derive(Default)]
// struct SimpleHasher { hash: u64 }

impl Hasher for SimpleHasher {
fn finish(&self) -> u64 { self.hash }
fn write(&mut self, bytes: &[u8]) {}
fn write_u64(&mut self, i: u64) { self.hash = i }
}
// impl Hasher for SimpleHasher {
// fn finish(&self) -> u64 { self.hash }
// fn write(&mut self, bytes: &[u8]) {}
// fn write_u64(&mut self, i: u64) { self.hash = i }
// }

fn main() {
// BTreeSet
Expand Down Expand Up @@ -144,7 +144,7 @@ fn main() {
// vec_deque2.push_back(8);

// HashMap
let mut hash_map = HashMap::<u64, u64, BuildHasherDefault<SimpleHasher>>::default();
let mut hash_map = HashMap::new();
for i in 1..5 {
hash_map.insert(i, i * 10);
}
Expand Down

0 comments on commit 9053cfb

Please sign in to comment.