Skip to content

Commit

Permalink
Minor codestyle fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
TalhaKhatri committed Oct 22, 2017
1 parent 1e64e5d commit 1946ac2
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/distance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fn max_length(str1: &str, str2: &str) -> usize {
fn get_common_chars(str1: &str, str2: &str, ordering: bool) -> Vec<char> {
let mut common_chars = Vec::new();

if str1.len() == 0 || str2.len() == 0 {
if str1.is_empty() || str2.is_empty() {
return common_chars;
}

Expand Down Expand Up @@ -88,7 +88,7 @@ pub fn levenshtein_distance(str1: &str, str2: &str) -> usize {
let delete = column[j - 1] + 1;
let mut change = previous[j - 1];
if a_vec[j - 1] != b_vec[i - 1] {
change = change + 1
change += 1
}
column[j] = min3(add, delete, change);
}
Expand Down
4 changes: 2 additions & 2 deletions src/phonetics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ impl SoundexWord {
chars.push(c);
}
chars = soundex_encoding(chars);
let s = SoundexWord { word: chars };
s
SoundexWord { word: chars }

}

pub fn sounds_like(&self, second_word: SoundexWord) -> bool {
Expand Down
31 changes: 12 additions & 19 deletions src/stem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ impl Stemmer {

#[inline]
fn double_consonant(&self, i: usize) -> bool {
if i < 1 {
false
} else if self.b[i] != self.b[i - 1] {
if i < 1 || self.b[i] != self.b[i - 1] {
false
} else {
self.is_consonant(i)
Expand Down Expand Up @@ -108,13 +106,11 @@ impl Stemmer {
let len = s.len();
if len > self.k {
false
} else if &self.b[self.k - len..self.k] == s {
self.j = self.k - len;
true
} else {
if &self.b[self.k - len..self.k] == s {
self.j = self.k - len;
true
} else {
false
}
false
}
}

Expand Down Expand Up @@ -244,8 +240,7 @@ impl Stemmer {
else { return }
}
b'c' => {
if self.ends("ance") {}
else if self.ends("ence") {}
if self.ends("ance") || self.ends("ence") {}
else { return }
}
b'e' => {
Expand All @@ -257,15 +252,14 @@ impl Stemmer {
else { return }
}
b'l' => {
if self.ends("able") {}
else if self.ends("ible") {}
if self.ends("able") || self.ends("ible") {}
else { return }
}
b'n' => {
if self.ends("ant") {}
else if self.ends("ement") {}
else if self.ends("ment") {}
else if self.ends("ent") {}
if self.ends("ant")
|| self.ends("ement")
|| self.ends("ment")
|| self.ends("ent") {}
else { return }
}
b'o' => {
Expand All @@ -280,8 +274,7 @@ impl Stemmer {
else { return }
}
b't' => {
if self.ends("ate") {}
else if self.ends("iti") {}
if self.ends("ate") || self.ends("iti") {}
else { return }
}
b'u' => {
Expand Down
2 changes: 1 addition & 1 deletion src/tokenize.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

pub fn tokenize(text: &str) -> Vec<&str> {
text.split(Splitter::is_match)
.filter(|s| s.len() > 0)
.filter(|s| !s.is_empty())
.collect()
}

Expand Down

0 comments on commit 1946ac2

Please sign in to comment.