@@ -139,11 +139,8 @@ impl Command for PickCommand {
139
139
let fid = match m. contains_id ( "name" ) {
140
140
// check for name specified, or closest name
141
141
true => {
142
- match m. get_one :: < String > ( "name" ) . map ( |name| name) {
143
- Some ( quesname) => match closest_named_problem ( & problems, quesname) {
144
- Some ( p) => p,
145
- None => 1 ,
146
- } ,
142
+ match m. get_one :: < String > ( "name" ) {
143
+ Some ( quesname) => closest_named_problem ( & problems, quesname) . unwrap_or ( 1 ) ,
147
144
None => {
148
145
// Pick random without specify id
149
146
let problem = & problems[ rand:: thread_rng ( ) . gen_range ( 0 ..problems. len ( ) ) ] ;
@@ -190,7 +187,7 @@ fn closest_named_problem(problems: &Vec<Problem>, lookup_name: &str) -> Option<i
190
187
let mut table: Vec < usize > = vec ! [ 0 ; ( max_name_size + 1 ) * ( lookup_name. len( ) + 1 ) ] ;
191
188
192
189
// this is guaranteed because of the earlier max None propegation
193
- assert ! ( problems. len ( ) > 0 ) ;
190
+ assert ! ( ! problems. is_empty ( ) ) ;
194
191
let mut max_score = 0 ;
195
192
let mut current_problem = & problems[ 0 ] ;
196
193
for problem in problems {
@@ -204,7 +201,7 @@ fn closest_named_problem(problems: &Vec<Problem>, lookup_name: &str) -> Option<i
204
201
205
202
if this_score > max_score {
206
203
max_score = this_score;
207
- current_problem = & problem;
204
+ current_problem = problem;
208
205
}
209
206
}
210
207
@@ -213,7 +210,7 @@ fn closest_named_problem(problems: &Vec<Problem>, lookup_name: &str) -> Option<i
213
210
214
211
// Longest commong subsequence DP approach O(nm) space and time. Table must be at least
215
212
// (text1.len() + 1) * (text2.len() + 1) length or greater and is mutated every call
216
- fn longest_common_subsequence ( table : & mut Vec < usize > , text1 : & str , text2 : & str ) -> usize {
213
+ fn longest_common_subsequence ( table : & mut [ usize ] , text1 : & str , text2 : & str ) -> usize {
217
214
assert ! ( table. len( ) >= ( text1. len( ) + 1 ) * ( text2. len( ) + 1 ) ) ;
218
215
let height: usize = text1. len ( ) + 1 ;
219
216
let width: usize = text2. len ( ) + 1 ;
0 commit comments