This commit is contained in:
+8
-6
@@ -17,7 +17,8 @@ pub enum SaveError {
|
||||
|
||||
/// Uses a hashmap to map descriptors to buckets of files.
|
||||
/// Also keeps a BK-tree for quick distance ranking
|
||||
pub struct DescriptorStore {
|
||||
pub struct DescriptorStore<T: Descriptor> {
|
||||
descriptor: T,
|
||||
/// Main hashmap that maps descriptors to buckets of filenames
|
||||
map: HashMap<u64, Vec<String>>,
|
||||
|
||||
@@ -31,14 +32,15 @@ pub struct DescriptorStore {
|
||||
seen: Option<HashSet<String>>,
|
||||
}
|
||||
|
||||
impl DescriptorStore {
|
||||
impl<T: Descriptor> DescriptorStore<T> {
|
||||
/// Makes a new empty DescriptorStore with default settings
|
||||
pub fn new() -> Self {
|
||||
pub fn new(descriptor: T) -> Self {
|
||||
let map: HashMap<u64, Vec<String>> = HashMap::new();
|
||||
//let seen: HashSet<String> = HashSet::new();
|
||||
//let seen = None;
|
||||
DescriptorStore {
|
||||
map,
|
||||
descriptor,
|
||||
save_location: std::path::PathBuf::from("store.messagepack"),
|
||||
bktree: BkTree::new(hamming_distance),
|
||||
seen: None,
|
||||
@@ -119,7 +121,7 @@ impl DescriptorStore {
|
||||
}
|
||||
|
||||
/// Calculates all descriptions with a given descriptor
|
||||
pub fn insert_directory<T: Descriptor, U: AsRef<Path>>(&mut self, dir: U, desc: T) {
|
||||
pub fn insert_directory<U: AsRef<Path>>(&mut self, dir: U) {
|
||||
for node in fs::read_dir(dir).unwrap() {
|
||||
let file = node.expect("Error walking directory");
|
||||
let name = match file.file_name().into_string() {
|
||||
@@ -138,7 +140,7 @@ impl DescriptorStore {
|
||||
continue
|
||||
}
|
||||
};
|
||||
let phash = desc.describe(&img);
|
||||
let phash = self.descriptor.describe(&img);
|
||||
if self.contains(phash) {
|
||||
println!("{} duplicate of {:?}", name, self.map.get(&phash));
|
||||
}
|
||||
@@ -222,7 +224,7 @@ impl DescriptorStore {
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for DescriptorStore {
|
||||
impl<T: Descriptor> fmt::Display for DescriptorStore<T> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
let mut output = String::new();
|
||||
for (key, bucket) in self.map.iter() {
|
||||
|
||||
Reference in New Issue
Block a user