From 8e3b00415dea87cc6e1d2e70709af2c02f735a48 Mon Sep 17 00:00:00 2001 From: Jason Staten Date: Wed, 16 Jan 2019 22:35:41 -0700 Subject: [PATCH] clippy fixes --- src/ch04_machinery/turing.rs | 2 +- src/ch05_bigo/search.rs | 7 +------ src/ch06_datastructures/heap.rs | 6 +++++- src/ch06_datastructures/queue.rs | 6 +++++- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/ch04_machinery/turing.rs b/src/ch04_machinery/turing.rs index 7c0ecce..b2caeda 100644 --- a/src/ch04_machinery/turing.rs +++ b/src/ch04_machinery/turing.rs @@ -55,7 +55,7 @@ pub fn run(machine: Machine, code: Tape) -> Tape { }; } - return tape; + tape } #[test] diff --git a/src/ch05_bigo/search.rs b/src/ch05_bigo/search.rs index e34d1be..ebbebe8 100644 --- a/src/ch05_bigo/search.rs +++ b/src/ch05_bigo/search.rs @@ -2,12 +2,7 @@ #[allow(unused_imports)] pub fn brute_force_search(arr: &[T], el: T) -> bool { - for i in 0..arr.len() { - if arr[i] == el { - return true; - } - } - return false; + arr.contains(&el) } pub fn binary_search(arr: &[T], el: T) -> bool { diff --git a/src/ch06_datastructures/heap.rs b/src/ch06_datastructures/heap.rs index ee3e0d3..1283a7d 100644 --- a/src/ch06_datastructures/heap.rs +++ b/src/ch06_datastructures/heap.rs @@ -20,6 +20,10 @@ impl Heap { self.elements.len() } + pub fn is_empty(&self) -> bool { + self.elements.is_empty() + } + pub fn push(&mut self, item: T) { self.elements.push(item); let mut i = self.len() - 1; @@ -30,7 +34,7 @@ impl Heap { } pub fn pop(&mut self) -> Option { - if self.len() > 0 { + if !self.is_empty() { let result = self.elements.swap_remove(0); self.heapify(0); Some(result) diff --git a/src/ch06_datastructures/queue.rs b/src/ch06_datastructures/queue.rs index 4d9b8a1..a62e0fd 100644 --- a/src/ch06_datastructures/queue.rs +++ b/src/ch06_datastructures/queue.rs @@ -26,6 +26,10 @@ impl Queue { self.length } + pub fn is_empty(&self) -> bool { + self.length == 0 + } + pub fn enqueue(&mut self, value: T) { let mut item = Box::new(Node { value, @@ -44,7 +48,7 @@ impl Queue { self.rear = raw_rear; - self.length = self.length + 1; + self.length += 1; } pub fn dequeue(&mut self) -> Option {