Merge pull request #1 from carols10cents/updates

Make a few modernizations to spruce the project up a bit :)
master
Jim Blandy 4 years ago committed by GitHub
commit 1bd7691d47
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -2,6 +2,7 @@
name = "fingertips" name = "fingertips"
version = "0.1.0" version = "0.1.0"
authors = ["Jason Orendorff <jason.orendorff@gmail.com>"] authors = ["Jason Orendorff <jason.orendorff@gmail.com>"]
edition = "2018"
[dependencies] [dependencies]
argparse = "0.2.1" argparse = "0.2.1"

@ -13,16 +13,12 @@
/// The `main` function at the end handles command-line arguments. It calls one /// The `main` function at the end handles command-line arguments. It calls one
/// of the two functions above to do the work. /// of the two functions above to do the work.
extern crate argparse;
extern crate byteorder;
mod index; mod index;
mod read; mod read;
mod write; mod write;
mod merge; mod merge;
mod tmp; mod tmp;
use std::error::Error;
use std::fs::File; use std::fs::File;
use std::io; use std::io;
use std::io::prelude::*; use std::io::prelude::*;
@ -31,10 +27,10 @@ use std::sync::mpsc::{channel, Receiver};
use std::thread::{spawn, JoinHandle}; use std::thread::{spawn, JoinHandle};
use argparse::{ArgumentParser, StoreTrue, Collect}; use argparse::{ArgumentParser, StoreTrue, Collect};
use index::InMemoryIndex; use crate::index::InMemoryIndex;
use write::write_index_to_tmp_file; use crate::write::write_index_to_tmp_file;
use merge::FileMerge; use crate::merge::FileMerge;
use tmp::TmpDir; use crate::tmp::TmpDir;
/// Create an inverted index for the given list of `documents`, /// Create an inverted index for the given list of `documents`,
/// storing it in the specified `output_dir`. /// storing it in the specified `output_dir`.
@ -298,6 +294,6 @@ fn main() {
match run(filenames, single_threaded) { match run(filenames, single_threaded) {
Ok(()) => {} Ok(()) => {}
Err(err) => println!("error: {:?}", err.description()) Err(err) => println!("error: {}", err)
} }
} }

@ -3,9 +3,9 @@ use std::io::{self, BufWriter};
use std::mem; use std::mem;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use tmp::TmpDir; use crate::tmp::TmpDir;
use read::IndexFileReader; use crate::read::IndexFileReader;
use write::IndexFileWriter; use crate::write::IndexFileWriter;
pub struct FileMerge { pub struct FileMerge {
output_dir: PathBuf, output_dir: PathBuf,

@ -6,7 +6,7 @@ use std::io::prelude::*;
use std::io::{self, BufReader, SeekFrom}; use std::io::{self, BufReader, SeekFrom};
use std::path::Path; use std::path::Path;
use byteorder::{LittleEndian, ReadBytesExt}; use byteorder::{LittleEndian, ReadBytesExt};
use write::IndexFileWriter; use crate::write::IndexFileWriter;
/// A `IndexFileReader` does a single linear pass over an index file from /// A `IndexFileReader` does a single linear pass over an index file from
/// beginning to end. Needless to say, this is not how an index is normally /// beginning to end. Needless to say, this is not how an index is normally

@ -17,7 +17,7 @@ impl TmpDir {
} }
pub fn create(&mut self) -> io::Result<(PathBuf, BufWriter<File>)> { pub fn create(&mut self) -> io::Result<(PathBuf, BufWriter<File>)> {
let mut try = 1; let mut r#try = 1;
loop { loop {
let filename = self.dir.join(PathBuf::from(format!("tmp{:08x}.dat", self.n))); let filename = self.dir.join(PathBuf::from(format!("tmp{:08x}.dat", self.n)));
self.n += 1; self.n += 1;
@ -29,13 +29,13 @@ impl TmpDir {
Ok(f) => Ok(f) =>
return Ok((filename, BufWriter::new(f))), return Ok((filename, BufWriter::new(f))),
Err(exc) => Err(exc) =>
if try < 999 && exc.kind() == io::ErrorKind::AlreadyExists { if r#try < 999 && exc.kind() == io::ErrorKind::AlreadyExists {
// keep going // keep going
} else { } else {
return Err(exc); return Err(exc);
} }
} }
try += 1; r#try += 1;
} }
} }
} }

@ -2,8 +2,8 @@ use std::fs::File;
use std::io::{self, BufWriter, SeekFrom}; use std::io::{self, BufWriter, SeekFrom};
use std::io::prelude::*; use std::io::prelude::*;
use std::path::PathBuf; use std::path::PathBuf;
use index::InMemoryIndex; use crate::index::InMemoryIndex;
use tmp::TmpDir; use crate::tmp::TmpDir;
use byteorder::{LittleEndian, WriteBytesExt}; use byteorder::{LittleEndian, WriteBytesExt};
/// Writer for saving an index to a binary file. /// Writer for saving an index to a binary file.

Loading…
Cancel
Save