Skip to content

Commit

Permalink
#3: prepared index_item vector
Browse files Browse the repository at this point in the history
  • Loading branch information
mkviatkovskii committed Jul 5, 2024
1 parent df0ad98 commit 2017cbf
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/ringo.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pub mod math;
pub mod molecule;
mod bingo;
mod ringo;
1 change: 1 addition & 0 deletions src/ringo/bingo.rs → src/ringo/ringo.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
mod index;
mod search;
mod index_item;
12 changes: 8 additions & 4 deletions src/ringo/bingo/index.rs → src/ringo/ringo/index.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
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<IndexItem> {
// 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() {
let line = line.unwrap();
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);
}
15 changes: 15 additions & 0 deletions src/ringo/ringo/index_item.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use bit_vec::BitVec;

pub struct IndexItem {
pub position: usize,
pub fingerprint: Vec<u8>
}

impl IndexItem {
pub fn new(position: usize, fingerprint: BitVec) -> IndexItem {
IndexItem {
position,
fingerprint: fingerprint.to_bytes()
}
}
}
File renamed without changes.

0 comments on commit 2017cbf

Please sign in to comment.