Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ wasm = ["bellman/wasm"]
[dependencies]
rand = "0.4"
digest = "0.8"
fnv = "1.0.3"
byteorder = "1"
tiny-keccak = {version = "2.0", features = ["keccak"] }
serde = "1.0"
Expand Down
32 changes: 16 additions & 16 deletions src/circuit/num.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use fnv::FnvHashMap;
use std::default::Default;

use bellman::pairing::{
Engine,
};
Expand Down Expand Up @@ -779,27 +782,24 @@ impl<E: Engine> Num<E> {
self.value = newval;
let mut lc = LinearCombination::zero();
// std::mem::swap(&mut self.lc, &mut lc);
use std::collections::HashMap;
let mut final_coeffs: HashMap<bellman::Variable, E::Fr> = HashMap::new();
let mut final_coeffs = FnvHashMap::<Variable, E::Fr>::with_capacity_and_hasher(
self.lc.as_ref().len() + other.lc.as_ref().len(),
Default::default(),
);
for (var, coeff) in self.lc.as_ref() {
if final_coeffs.get(var).is_some() {
if let Some(existing_coeff) = final_coeffs.get_mut(var) {
existing_coeff.add_assign(&coeff);
}
} else {
final_coeffs.insert(*var, *coeff);
}
final_coeffs
.entry(*var)
.and_modify(|c| c.add_assign(coeff))
.or_insert_with(|| *coeff);
}

for (var, coeff) in other.lc.as_ref() {
if final_coeffs.get(var).is_some() {
if let Some(existing_coeff) = final_coeffs.get_mut(var) {
existing_coeff.add_assign(&coeff);
}
} else {
final_coeffs.insert(*var, *coeff);
}
final_coeffs
.entry(*var)
.and_modify(|c| c.add_assign(coeff))
.or_insert_with(|| *coeff);
}

for (var, coeff) in final_coeffs.into_iter() {
lc = lc + (coeff, var);
}
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
pub extern crate bellman;
extern crate blake2_rfc_bellman_edition as blake2_rfc;
extern crate digest;
extern crate fnv;
extern crate rand;
extern crate byteorder;
extern crate tiny_keccak;
Expand Down