chore: Little clean ups of meilidb-core

This commit is contained in:
Clément Renault 2019-07-01 14:34:06 +02:00
parent 4f4b630ae9
commit e8afca614c
No known key found for this signature in database
GPG Key ID: 0151CDAB43460DAE
4 changed files with 6 additions and 3 deletions

View File

@ -1,5 +1,4 @@
use std::hash::Hash; use std::hash::Hash;
use hashbrown::HashMap; use hashbrown::HashMap;
pub struct DistinctMap<K> { pub struct DistinctMap<K> {

View File

@ -162,7 +162,7 @@ impl fmt::Debug for RawDocument {
} }
fn raw_documents_from_matches(matches: SetBuf<(DocumentId, TmpMatch, Highlight)>) -> Vec<RawDocument> { fn raw_documents_from_matches(matches: SetBuf<(DocumentId, TmpMatch, Highlight)>) -> Vec<RawDocument> {
let mut docs_ranges = Vec::<(DocumentId, Range, Vec<Highlight>)>::new(); let mut docs_ranges: Vec<(_, Range, _)> = Vec::new();
let mut matches2 = Matches::with_capacity(matches.len()); let mut matches2 = Matches::with_capacity(matches.len());
for group in matches.linear_group_by(|(a, _, _), (b, _, _)| a == b) { for group in matches.linear_group_by(|(a, _, _), (b, _, _)| a == b) {

View File

@ -229,7 +229,7 @@ impl<'c, S, FI> QueryBuilder<'c, S, FI>
} }
pub fn add_searchable_attribute(&mut self, attribute: u16) { pub fn add_searchable_attribute(&mut self, attribute: u16) {
let reorders = self.searchable_attrs.get_or_insert_with(Default::default); let reorders = self.searchable_attrs.get_or_insert_with(ReorderedAttrs::new);
reorders.insert_attribute(attribute); reorders.insert_attribute(attribute);
} }
} }

View File

@ -5,6 +5,10 @@ pub struct ReorderedAttrs {
} }
impl ReorderedAttrs { impl ReorderedAttrs {
pub fn new() -> ReorderedAttrs {
ReorderedAttrs { count: 0, reorders: Vec::new() }
}
pub fn insert_attribute(&mut self, attribute: u16) { pub fn insert_attribute(&mut self, attribute: u16) {
self.reorders.resize(attribute as usize + 1, None); self.reorders.resize(attribute as usize + 1, None);
self.reorders[attribute as usize] = Some(self.count as u16); self.reorders[attribute as usize] = Some(self.count as u16);