add BoomIndex

This commit is contained in:
Alexander Weiss 2022-02-07 20:52:18 +01:00
parent 7874205e8e
commit d908e83dab
5 changed files with 47 additions and 6 deletions

View File

@ -16,20 +16,20 @@ pub enum BlobType {
Tree,
}
#[derive(Debug, PartialEq, Constructor)]
#[derive(Debug, PartialEq, Clone, Constructor)]
pub struct Blob {
tpe: BlobType,
id: Id,
}
#[derive(Debug, Constructor)]
#[derive(Debug, Clone, Constructor)]
pub struct BlobInformation {
blob: Blob,
offset: u32,
length: u32,
}
#[derive(Debug, Constructor)]
#[derive(Debug, Clone, Constructor)]
pub struct IndexEntry {
pack: Id,
bi: BlobInformation,

View File

@ -4,7 +4,7 @@ use clap::Parser;
use crate::backend::{FileType, MapResult, ReadBackend};
use crate::blob::TreeIterator;
use crate::id::Id;
use crate::index::indexfiles::AllIndexFiles;
use crate::index::{AllIndexFiles, BoomIndex};
use crate::repo::SnapshotFile;
#[derive(Parser)]
@ -24,7 +24,7 @@ pub(super) fn execute(be: &impl ReadBackend, opts: Opts) -> Result<()> {
}
})?;
let index = AllIndexFiles::new(be.clone());
let index= BoomIndex::from_iter(AllIndexFiles::new(be.clone()).into_iter());
let snap = SnapshotFile::from_backend(be, id)?;
for path_node in TreeIterator::from_id(be.clone(), index, snap.tree) {

View File

@ -2,7 +2,7 @@ use derive_more::Display;
use serde::{Deserialize, Serialize};
use thiserror::Error;
#[derive(Clone, Copy, Debug, Default, PartialEq, Serialize, Deserialize, Display)]
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, Serialize, Deserialize, Display)]
#[display(fmt = "{}", "&self.to_hex()[0..8]")]
pub struct Id(
#[serde(serialize_with = "hex::serde::serialize")]

37
src/index/boom.rs Normal file
View File

@ -0,0 +1,37 @@
use boomphf::hashmap::BoomHashMap;
use super::{AllIndexFiles, ReadIndex};
use crate::backend::ReadBackend;
use crate::blob::IndexEntry;
use crate::id::Id;
pub struct BoomIndex(BoomHashMap<Id, IndexEntry>);
impl BoomIndex {
pub fn from_all_indexfiles<BE: ReadBackend>(aif: AllIndexFiles<BE>) -> Self {
Self::from_iter(aif.into_iter())
}
}
impl FromIterator<IndexEntry> for BoomIndex {
fn from_iter<T>(iter: T) -> Self
where
T: IntoIterator<Item = IndexEntry>,
{
let mut ids = Vec::new();
let mut ies = Vec::new();
for ie in iter {
ids.push(*ie.id());
ies.push(ie);
}
BoomIndex(BoomHashMap::new(ids, ies))
}
}
impl ReadIndex for BoomIndex {
fn get_id(&self, id: &Id) -> Option<IndexEntry> {
self.0.get(id).map(IndexEntry::clone)
}
}

View File

@ -1,5 +1,9 @@
pub mod boom;
pub mod indexfiles;
pub use boom::*;
pub use indexfiles::*;
use crate::blob::IndexEntry;
use crate::id::Id;