-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bdd3ba1
commit 60ed7c3
Showing
16 changed files
with
250 additions
and
232 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
use webgraph::prelude::Encode; | ||
use std::convert::Infallible; | ||
use crate::bvgraph::BVGraphComponent; | ||
|
||
/// An estimator that simply returns the cost of each symbol calculated as the log2 of the value plus 2. | ||
#[derive(Clone, Default)] | ||
pub struct Log2Estimator {} | ||
|
||
impl Log2Estimator { | ||
fn get_symbol_cost(&self, value: u64, _component: BVGraphComponent) -> usize { | ||
u64::ilog2(value + 2) as usize | ||
} | ||
} | ||
|
||
impl Encode for Log2Estimator { | ||
type Error = Infallible; | ||
|
||
fn start_node(&mut self, _node: usize) -> Result<usize, Self::Error> { | ||
Ok(0) | ||
} | ||
|
||
fn write_outdegree(&mut self, value: u64) -> Result<usize, Self::Error> { | ||
Ok(self.get_symbol_cost(value, BVGraphComponent::Outdegree)) | ||
} | ||
|
||
fn write_reference_offset(&mut self, value: u64) -> Result<usize, Self::Error> { | ||
Ok(self.get_symbol_cost(value, BVGraphComponent::ReferenceOffset)) | ||
} | ||
|
||
fn write_block_count(&mut self, value: u64) -> Result<usize, Self::Error> { | ||
Ok(self.get_symbol_cost(value, BVGraphComponent::BlockCount)) | ||
} | ||
|
||
fn write_block(&mut self, value: u64) -> Result<usize, Self::Error> { | ||
Ok(self.get_symbol_cost(value, BVGraphComponent::Blocks)) | ||
} | ||
|
||
fn write_interval_count(&mut self, value: u64) -> Result<usize, Self::Error> { | ||
Ok(self.get_symbol_cost(value, BVGraphComponent::IntervalCount)) | ||
} | ||
|
||
fn write_interval_start(&mut self, value: u64) -> Result<usize, Self::Error> { | ||
Ok(self.get_symbol_cost(value, BVGraphComponent::IntervalStart)) | ||
} | ||
|
||
fn write_interval_len(&mut self, value: u64) -> Result<usize, Self::Error> { | ||
Ok(self.get_symbol_cost(value, BVGraphComponent::IntervalLen)) | ||
} | ||
|
||
fn write_first_residual(&mut self, value: u64) -> Result<usize, Self::Error> { | ||
Ok(self.get_symbol_cost(value, BVGraphComponent::FirstResidual)) | ||
} | ||
|
||
fn write_residual(&mut self, value: u64) -> Result<usize, Self::Error> { | ||
Ok(self.get_symbol_cost(value, BVGraphComponent::Residual)) | ||
} | ||
|
||
fn flush(&mut self) -> Result<usize, Self::Error> { | ||
Ok(0) | ||
} | ||
|
||
fn end_node(&mut self, _node: usize) -> Result<usize, Self::Error> { | ||
Ok(0) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pub mod log2_estimator; | ||
pub mod entropy_estimator; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use webgraph::prelude::SequentialDecoderFactory; | ||
use crate::ans::decoder::ANSDecoder; | ||
use crate::ans::model4decoder::ANSModel4Decoder; | ||
use crate::ans::Prelude; | ||
|
||
pub struct ANSBVGraphSeqDecoderFactory { | ||
/// The prelude resulting from the encoding process of the graph. | ||
prelude: Prelude, | ||
|
||
/// The ANSModel4Decoder used by the decoder to decode the graph. | ||
model: ANSModel4Decoder, | ||
} | ||
|
||
impl ANSBVGraphSeqDecoderFactory { | ||
pub fn new(prelude: Prelude) -> Self { | ||
Self { | ||
model: ANSModel4Decoder::new(&prelude.tables), | ||
prelude, | ||
} | ||
} | ||
} | ||
|
||
impl SequentialDecoderFactory for ANSBVGraphSeqDecoderFactory { | ||
type Decoder<'b> = ANSDecoder<'b> where Self: 'b; | ||
|
||
fn new_decoder(&self) -> anyhow::Result<Self::Decoder<'_>> { | ||
Ok(ANSDecoder::new( | ||
&self.model, | ||
&self.prelude.stream, | ||
self.prelude.state, | ||
)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pub mod bvgraphseq_decoder_factory; | ||
pub mod bvgraph_decoder_factory; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.