Merge pull request #1 from carols10cents/updates

Make a few modernizations to spruce the project up a bit :)
master
Jim Blandy 3 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"
version = "0.1.0"
authors = ["Jason Orendorff <jason.orendorff@gmail.com>"]
edition = "2018"
[dependencies]
argparse = "0.2.1"

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

@ -6,7 +6,7 @@ use std::io::prelude::*;
use std::io::{self, BufReader, SeekFrom};
use std::path::Path;
use byteorder::{LittleEndian, ReadBytesExt};
use write::IndexFileWriter;
use crate::write::IndexFileWriter;
/// 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

@ -17,7 +17,7 @@ impl TmpDir {
}
pub fn create(&mut self) -> io::Result<(PathBuf, BufWriter<File>)> {
let mut try = 1;
let mut r#try = 1;
loop {
let filename = self.dir.join(PathBuf::from(format!("tmp{:08x}.dat", self.n)));
self.n += 1;
@ -29,13 +29,13 @@ impl TmpDir {
Ok(f) =>
return Ok((filename, BufWriter::new(f))),
Err(exc) =>
if try < 999 && exc.kind() == io::ErrorKind::AlreadyExists {
if r#try < 999 && exc.kind() == io::ErrorKind::AlreadyExists {
// keep going
} else {
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::prelude::*;
use std::path::PathBuf;
use index::InMemoryIndex;
use tmp::TmpDir;
use crate::index::InMemoryIndex;
use crate::tmp::TmpDir;
use byteorder::{LittleEndian, WriteBytesExt};
/// Writer for saving an index to a binary file.

Loading…
Cancel
Save