map: Increase the SmallVec size

This commit is contained in:
Kerollmops 2018-04-22 18:28:08 +02:00
parent c371fb56b7
commit f851227ed4
No known key found for this signature in database
GPG Key ID: 016ACC0DC3ADC318
3 changed files with 15 additions and 17 deletions

View File

@ -53,7 +53,8 @@ fn main() {
let description = product.ft.split_whitespace().filter(|&s| s != "Description"); let description = product.ft.split_whitespace().filter(|&s| s != "Description");
let words = title.chain(description) let words = title.chain(description)
.filter(|&s| s.chars().any(|c| c.is_alphabetic())) // remove that ? .filter(|&s| s.chars().any(|c| c.is_alphabetic())) // remove that ?
.filter(|&s| !common_words.contains(s)); .filter(|&s| !common_words.contains(s))
.map(|s| s.to_lowercase());
for word in words { for word in words {
builder.insert(word, product.product_id); builder.insert(word, product.product_id);
@ -64,6 +65,7 @@ fn main() {
let values = File::create("values.vecs").unwrap(); let values = File::create("values.vecs").unwrap();
let (map, values) = builder.build(map, values).unwrap(); let (map, values) = builder.build(map, values).unwrap();
// just to check if the dump is valid
let map = unsafe { MultiMap::from_paths("map.fst", "values.vecs").unwrap() }; let map = unsafe { MultiMap::from_paths("map.fst", "values.vecs").unwrap() };
// let mut stream = map.stream(); // let mut stream = map.stream();

View File

@ -13,7 +13,7 @@ use tokio_minihttp::{Request, Response, Http};
use tokio_proto::TcpServer; use tokio_proto::TcpServer;
use tokio_service::Service; use tokio_service::Service;
use raptor::{MultiMapBuilder, MultiMap}; use raptor::MultiMap;
struct MainService { struct MainService {
map: MultiMap, map: MultiMap,
@ -30,13 +30,14 @@ impl Service for MainService {
let url = format!("http://raptor.net{}", request.path()); let url = format!("http://raptor.net{}", request.path());
let url = url::Url::parse(&url).unwrap(); let url = url::Url::parse(&url).unwrap();
let mut resp = Response::new();
if let Some((_, key)) = url.query_pairs().find(|&(ref k, _)| k == "query") { if let Some((_, key)) = url.query_pairs().find(|&(ref k, _)| k == "query") {
let values = self.map.get(&*key); let key = key.to_lowercase();
println!("{:?}", values); let values = self.map.get(&key).map(|a| &a[..10]);
resp.body(&format!("{:?}", values));
} }
let mut resp = Response::new();
resp.body("Hello, world!");
future::ok(resp) future::ok(resp)
} }
} }
@ -51,12 +52,7 @@ fn main() {
// closure, make it global. // closure, make it global.
// It will permit the server to be multithreaded. // It will permit the server to be multithreaded.
let mut builder = MultiMapBuilder::new(); let map = unsafe { MultiMap::from_paths("map.fst", "values.vecs").unwrap() };
builder.insert("foo", 12);
builder.insert("foo", 13);
builder.insert("bar", 10);
let map = builder.build_memory().unwrap();
println!("Called Fn here !"); println!("Called Fn here !");

View File

@ -13,12 +13,12 @@ use std::str::from_utf8_unchecked;
pub use fst::MapBuilder; pub use fst::MapBuilder;
use smallvec::SmallVec; use smallvec::SmallVec;
type SmallVec16<T> = SmallVec<[T; 16]>; type SmallVec32<T> = SmallVec<[T; 16]>;
#[derive(Debug)] #[derive(Debug)]
pub struct MultiMap { pub struct MultiMap {
map: fst::Map, map: fst::Map,
values: Box<[SmallVec16<u64>]>, values: Box<[SmallVec32<u64>]>,
} }
impl MultiMap { impl MultiMap {
@ -54,7 +54,7 @@ impl MultiMap {
pub struct Stream<'a, A: fst::Automaton = fst::automaton::AlwaysMatch> { pub struct Stream<'a, A: fst::Automaton = fst::automaton::AlwaysMatch> {
inner: fst::map::Stream<'a, A>, inner: fst::map::Stream<'a, A>,
values: &'a [SmallVec16<u64>], values: &'a [SmallVec32<u64>],
} }
impl<'a, 'm, A: fst::Automaton> fst::Streamer<'a> for Stream<'m, A> { impl<'a, 'm, A: fst::Automaton> fst::Streamer<'a> for Stream<'m, A> {
@ -75,7 +75,7 @@ impl<'a, 'm, A: fst::Automaton> fst::Streamer<'a> for Stream<'m, A> {
#[derive(Debug)] #[derive(Debug)]
pub struct MultiMapBuilder { pub struct MultiMapBuilder {
map: Vec<(String, u64)>, map: Vec<(String, u64)>,
values: Vec<SmallVec16<u64>>, values: Vec<SmallVec32<u64>>,
} }
impl<'a> MultiMapBuilder { impl<'a> MultiMapBuilder {
@ -98,7 +98,7 @@ impl<'a> MultiMapBuilder {
}, },
Err(index) => { Err(index) => {
let values = { let values = {
let mut vec = SmallVec16::new(); let mut vec = SmallVec32::new();
vec.push(value); vec.push(value);
vec vec
}; };