terminusdb / terminusdb-store

a tokio-enabled data store for triple data

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Question about repetitive MemoryBackedStore construction pattern

spl opened this issue · comments

What is the reason for this kind of pattern?

let files: Vec<_> = (0..40).map(|_| MemoryBackedStore::new()).collect();
let clf = ChildLayerFiles {
    node_dictionary_files: DictionaryFiles {
        blocks_file: files[0].clone(),
        offsets_file: files[1].clone(),
    },
//...

The above comes from from here, but there are a number of them:

src/layer/base.rs:1040:    let files: Vec<_> = (0..21).map(|_| MemoryBackedStore::new()).collect();
src/layer/builder.rs:299:  let files: Vec<_> = (0..21).map(|_| MemoryBackedStore::new()).collect();
src/layer/builder.rs:346:  let files: Vec<_> = (0..40).map(|_| MemoryBackedStore::new()).collect();
src/layer/child.rs:1597:   let files: Vec<_> = (0..40).map(|_| MemoryBackedStore::new()).collect();
src/storage/memory.rs:251: let files: Vec<_> = (0..21).map(|_| MemoryBackedStore::new()).collect();
src/storage/memory.rs:321: let files: Vec<_> = (0..40).map(|_| MemoryBackedStore::new()).collect();

I don't currently see why each of files[0].clone() to files[39].clone() shouldn't be replaced with MemoryBackedStore::new(), but I could be missing something.

.. Yeah that would actually be much better. The reason for this pattern is probably sleep deprivation.