diff --git a/src/bin/raptor-cli.rs b/src/bin/raptor-cli.rs index 59636a5b4..0932ccc87 100644 --- a/src/bin/raptor-cli.rs +++ b/src/bin/raptor-cli.rs @@ -12,7 +12,7 @@ use std::io::{BufReader, BufRead}; use serde_json::from_str; -use raptor::{FstMapBuilder, FstMap}; +use raptor::{MapBuilder, Map}; #[derive(Debug, Deserialize)] struct Product { @@ -41,7 +41,7 @@ fn main() { set }; - let mut builder = FstMapBuilder::new(); + let mut builder = MapBuilder::new(); for line in data.lines() { let line = line.unwrap(); @@ -65,5 +65,5 @@ fn main() { let (map, values) = builder.build(map, values).unwrap(); eprintln!("Checking the dump consistency..."); - unsafe { FstMap::::from_paths("map.fst", "values.vecs").unwrap() }; + unsafe { Map::::from_paths("map.fst", "values.vecs").unwrap() }; } diff --git a/src/bin/raptor.rs b/src/bin/raptor.rs index 2ed9dc56d..bef8ef7db 100644 --- a/src/bin/raptor.rs +++ b/src/bin/raptor.rs @@ -8,10 +8,7 @@ extern crate tokio_proto; extern crate tokio_service; extern crate url; -use std::io; -use std::path::Path; -use std::fs::{self, File}; -use std::io::{Read, BufReader}; +use std::{io, fs}; use fst::Streamer; use futures::future; @@ -20,15 +17,15 @@ use tokio_minihttp::{Request, Response, Http}; use tokio_proto::TcpServer; use tokio_service::Service; -use raptor::{FstMap, OpWithStateBuilder}; +use raptor::{Map, OpWithStateBuilder}; -static mut MAP: Option> = None; +static mut MAP: Option> = None; static mut LEV_BUILDER_0: Option = None; static mut LEV_BUILDER_1: Option = None; static mut LEV_BUILDER_2: Option = None; struct MainService<'a> { - map: &'a FstMap, + map: &'a Map, lev_builder_0: &'a LevBuilder, lev_builder_1: &'a LevBuilder, lev_builder_2: &'a LevBuilder, @@ -109,7 +106,7 @@ fn main() { let map = fs::read("map.fst").unwrap(); let values = fs::read("values.vecs").unwrap(); - Some(FstMap::from_bytes(map, &values).unwrap()) + Some(Map::from_bytes(map, &values).unwrap()) }; LEV_BUILDER_0 = Some(LevBuilder::new(0, false)); LEV_BUILDER_1 = Some(LevBuilder::new(1, false)); diff --git a/src/lib.rs b/src/lib.rs index 0a082d839..890614e55 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,16 +3,15 @@ extern crate bincode; extern crate fst; extern crate serde; -mod fst_map; +mod map; use fst::Automaton; -pub use self::fst_map::{FstMap, FstMapBuilder}; -pub use self::fst_map::{ +pub use self::map::{Map, MapBuilder, Values}; +pub use self::map::{ OpBuilder, IndexedValues, OpWithStateBuilder, IndexedValuesWithState, }; -use self::fst_map::Values; pub struct StreamBuilder<'m, 'v, T: 'v, A> { inner: fst::map::StreamBuilder<'m, A>, diff --git a/src/fst_map.rs b/src/map.rs similarity index 96% rename from src/fst_map.rs rename to src/map.rs index d97fc9810..2b81c8212 100644 --- a/src/fst_map.rs +++ b/src/map.rs @@ -9,12 +9,12 @@ use std::path::Path; use {StreamBuilder, Stream}; #[derive(Debug)] -pub struct FstMap { +pub struct Map { inner: fst::Map, values: Values, } -impl FstMap { +impl Map { pub unsafe fn from_paths(map: P, values: Q) -> fst::Result where T: DeserializeOwned, @@ -63,11 +63,6 @@ impl FstMap { } } - pub fn op(&self) -> OpBuilder { - // OpBuilder::new(&self.values).add(self.as_inner()) - unimplemented!() - } - pub fn as_map(&self) -> &fst::Map { &self.inner } @@ -114,14 +109,14 @@ impl Values { } #[derive(Debug)] -pub struct FstMapBuilder { +pub struct MapBuilder { map: Vec<(String, u64)>, // This makes many memory indirections but it is only used // at index time, not kept for query time. values: Vec>, } -impl FstMapBuilder { +impl MapBuilder { pub fn new() -> Self { Self { map: Vec::new(), @@ -148,8 +143,8 @@ impl FstMapBuilder { } } - pub fn build_memory(self) -> fst::Result> { - Ok(FstMap { + pub fn build_in_memory(self) -> fst::Result> { + Ok(Map { inner: fst::Map::from_iter(self.map)?, values: Values::new(self.values), })