From 2017cbfda782ad9a2a9039c20cea3c13da11f037 Mon Sep 17 00:00:00 2001 From: Mikhail Kviatkovskii Date: Fri, 5 Jul 2024 11:48:09 +0400 Subject: [PATCH] #3: prepared index_item vector --- src/ringo.rs | 2 +- src/ringo/{bingo.rs => ringo.rs} | 1 + src/ringo/{bingo => ringo}/index.rs | 12 ++++++++---- src/ringo/ringo/index_item.rs | 15 +++++++++++++++ src/ringo/{bingo => ringo}/search.rs | 0 5 files changed, 25 insertions(+), 5 deletions(-) rename src/ringo/{bingo.rs => ringo.rs} (58%) rename src/ringo/{bingo => ringo}/index.rs (69%) create mode 100644 src/ringo/ringo/index_item.rs rename src/ringo/{bingo => ringo}/search.rs (100%) diff --git a/src/ringo.rs b/src/ringo.rs index 00302d3..76b46a1 100644 --- a/src/ringo.rs +++ b/src/ringo.rs @@ -1,3 +1,3 @@ pub mod math; pub mod molecule; -mod bingo; +mod ringo; diff --git a/src/ringo/bingo.rs b/src/ringo/ringo.rs similarity index 58% rename from src/ringo/bingo.rs rename to src/ringo/ringo.rs index 34de02b..0e77780 100644 --- a/src/ringo/bingo.rs +++ b/src/ringo/ringo.rs @@ -1,2 +1,3 @@ mod index; mod search; +mod index_item; diff --git a/src/ringo/bingo/index.rs b/src/ringo/ringo/index.rs similarity index 69% rename from src/ringo/bingo/index.rs rename to src/ringo/ringo/index.rs index 06f57bb..0d09dc5 100644 --- a/src/ringo/bingo/index.rs +++ b/src/ringo/ringo/index.rs @@ -1,14 +1,14 @@ use std::fs::File; use std::io::{BufRead}; - use crate::ringo::molecule::smiles::reader::molecule::parse_molecule; +use crate::ringo::ringo::index_item::IndexItem; -fn index(smiles_file: &str) { +fn index(smiles_file: &str) -> Vec { // open file for reading let fi = File::open(smiles_file).expect("Could not open file"); + let mut result = Vec::new(); // open binary file for index - let mut offset = 0; // let mut fo = File::create(smiles_file.to_owned() + ".fp"); for line in std::io::BufReader::new(fi).lines() { @@ -16,11 +16,15 @@ fn index(smiles_file: &str) { let molecule = parse_molecule(&line).unwrap().1; // let ecfp = molecule.ecfp(2, 512); // write ecfp and offset to binary file + result.push(IndexItem::new(offset, molecule.ecfp(2, 512))); + offset += line.len() + 1; } + return result; } #[test] fn test_index() { - index("molecules.smi"); + let result = index("molecules.smi"); + assert_eq!(result.len(), 1); } diff --git a/src/ringo/ringo/index_item.rs b/src/ringo/ringo/index_item.rs new file mode 100644 index 0000000..06d8c90 --- /dev/null +++ b/src/ringo/ringo/index_item.rs @@ -0,0 +1,15 @@ +use bit_vec::BitVec; + +pub struct IndexItem { + pub position: usize, + pub fingerprint: Vec +} + +impl IndexItem { + pub fn new(position: usize, fingerprint: BitVec) -> IndexItem { + IndexItem { + position, + fingerprint: fingerprint.to_bytes() + } + } +} diff --git a/src/ringo/bingo/search.rs b/src/ringo/ringo/search.rs similarity index 100% rename from src/ringo/bingo/search.rs rename to src/ringo/ringo/search.rs