Skip to content

Commit

Permalink
add comment to [ScalarCompressor]
Browse files Browse the repository at this point in the history
  • Loading branch information
vlopes11 committed Apr 9, 2023
1 parent ebe3a22 commit 0862d97
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/composer/compiler/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,27 @@ use hashbrown::HashMap;
///
/// It will compress [i8] equivalent values into a single byte, and perform a
/// full serialization for values that won't fit [i8].
///
/// The compressor contains an internal mapping for indexed [i8] values. Here
/// follows a couple of example values to better illustrate the concept:
///
/// - `-128_i8` is not mapped as it is [i8::MIN]
/// - `-127_i8` is mapped to `2`
/// - `-126_i8` is mapped to `3`
/// - `-125_i8` is mapped to `4`
/// - (...)
/// - `-1_i8` is mapped to `128`
/// - `0_i8` is mapped to `129`
/// - `1_i8` is mapped to `130`
/// - (...)
/// - `124_i8` is mapped to `253`
/// - `125_i8` is mapped to `254`
/// - `126_i8` is mapped to `255`
///
/// A `BlsScalar::zero() - BlsScalar::from(126)` will be serialized as `3_u8`.
///
/// A [BlsScalar] that is not in the map will be serialized as `0_u8`, followed
/// by the result of [BlsScalar::to_bytes].
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ScalarCompressor {
map: HashMap<BlsScalar, u8>,
Expand Down

0 comments on commit 0862d97

Please sign in to comment.