1#![doc = include_str!("../README.md")]
2#![doc = "\n## Example\n\n```rust"]
3#![doc = include_str!("../examples/main.rs")]
4#![doc = "```"]
5
6use std::path::Path;
7
8use brk_core::Version;
9use brk_exit::Exit;
10use brk_fetcher::Fetcher;
11use brk_indexer::Indexer;
12use brk_vec::{Computation, Format};
13use log::info;
14
15mod states;
16mod stores;
17mod utils;
18mod vecs;
19
20use states::*;
21use stores::Stores;
22use vecs::Vecs;
23
24#[derive(Clone)]
25pub struct Computer {
26 fetcher: Option<Fetcher>,
27 pub vecs: Vecs,
28 pub stores: Stores,
29}
30
31const VERSION: Version = Version::ONE;
32
33impl Computer {
34 pub fn forced_import(
36 outputs_dir: &Path,
37 indexer: &Indexer,
38 computation: Computation,
39 fetcher: Option<Fetcher>,
40 format: Format,
41 ) -> color_eyre::Result<Self> {
42 Ok(Self {
43 vecs: Vecs::import(
44 &outputs_dir.join("vecs/computed"),
46 VERSION + Version::ZERO,
47 indexer,
48 fetcher.is_some(),
49 computation,
50 format,
51 )?,
52 stores: Stores::import(
53 &outputs_dir.join("stores"),
55 VERSION + Version::ZERO,
56 &indexer.stores.keyspace,
57 )?,
58 fetcher,
59 })
60 }
61}
62
63impl Computer {
64 pub fn compute(
65 &mut self,
66 indexer: &mut Indexer,
67 starting_indexes: brk_indexer::Indexes,
68 exit: &Exit,
69 ) -> color_eyre::Result<()> {
70 info!("Computing...");
71 self.vecs.compute(
72 indexer,
73 starting_indexes,
74 self.fetcher.as_mut(),
75 exit,
76 &mut self.stores,
77 )
78 }
79}