mirror of
https://github.com/circify/circ.git
synced 2026-01-10 06:08:02 -05:00
Update all hash sets
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
use crate::ir::term::*;
|
||||
use std::collections::HashSet;
|
||||
use std::rc::Rc;
|
||||
|
||||
enum Entry {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::ir::term::extras::*;
|
||||
use crate::ir::term::*;
|
||||
use std::collections::HashSet;
|
||||
use ahash::AHashSet;
|
||||
use super::cfold;
|
||||
|
||||
/// This is a tool for sweeping a list of equations, some of which define new variables as
|
||||
@@ -23,11 +23,11 @@ pub struct Inliner<'a> {
|
||||
stale_vars: TermSet,
|
||||
|
||||
/// Variables that are "protected": they should not be eliminated.
|
||||
protected: &'a HashSet<String>,
|
||||
protected: &'a AHashSet<String>,
|
||||
}
|
||||
|
||||
impl<'a> Inliner<'a> {
|
||||
fn new(protected: &'a HashSet<String>) -> Self {
|
||||
fn new(protected: &'a AHashSet<String>) -> Self {
|
||||
Self {
|
||||
substs: TermMap::new(),
|
||||
subst_cache: TermMap::new(),
|
||||
@@ -40,7 +40,7 @@ impl<'a> Inliner<'a> {
|
||||
/// Also checks that no key variable is in any `subst_cache` value.
|
||||
#[allow(dead_code)]
|
||||
fn check_substs(&self) {
|
||||
let keys: HashSet<&Term> = self.substs.keys().collect();
|
||||
let keys: AHashSet<&Term> = self.substs.keys().collect();
|
||||
for (key, value) in &self.substs {
|
||||
for child in PostOrderIter::new(value.clone()) {
|
||||
assert!(
|
||||
@@ -173,7 +173,7 @@ impl<'a> Inliner<'a> {
|
||||
///
|
||||
/// First, maintains a set of variables being substituted.
|
||||
/// Second, maintain a
|
||||
pub fn inline(assertions: &mut Vec<Term>, public_inputs: &HashSet<String>) {
|
||||
pub fn inline(assertions: &mut Vec<Term>, public_inputs: &AHashSet<String>) {
|
||||
let mut new_assertions = Vec::new();
|
||||
let mut inliner = Inliner::new(public_inputs);
|
||||
for assertion in assertions.drain(..) {
|
||||
@@ -203,7 +203,7 @@ mod test {
|
||||
|
||||
fn sub_test(xs: Vec<Term>, n: usize) {
|
||||
let mut ys = xs.clone();
|
||||
let p = HashSet::new();
|
||||
let p = AHashSet::new();
|
||||
inline(&mut ys, &p);
|
||||
assert_eq!(n, ys.len());
|
||||
let x = term(Op::BoolNaryOp(BoolNaryOp::And), xs.clone());
|
||||
|
||||
@@ -3,7 +3,7 @@ use hashconsing::{HConsed, WHConsed};
|
||||
use lazy_static::lazy_static;
|
||||
use log::debug;
|
||||
use rug::Integer;
|
||||
use std::collections::{BTreeMap, HashMap, HashSet};
|
||||
use std::collections::{BTreeMap};
|
||||
use std::fmt::{self, Debug, Display, Formatter};
|
||||
use std::sync::{Arc, RwLock};
|
||||
use crate::util::once::OnceQueue;
|
||||
@@ -722,7 +722,7 @@ impl Value {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn eval(t: &Term, h: &HashMap<String, Value>) -> Value {
|
||||
pub fn eval(t: &Term, h: &AHashMap<String, Value>) -> Value {
|
||||
let mut vs = TermMap::<Value>::new();
|
||||
for c in PostOrderIter::new(t.clone()) {
|
||||
let v = match &c.op {
|
||||
@@ -928,8 +928,8 @@ impl std::iter::Iterator for PostOrderIter {
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Constraints {
|
||||
pub(super) assertions: Vec<Term>,
|
||||
pub(super) public_inputs: HashSet<String>,
|
||||
pub(super) values: Option<HashMap<String, Value>>,
|
||||
pub(super) public_inputs: AHashSet<String>,
|
||||
pub(super) values: Option<AHashMap<String, Value>>,
|
||||
}
|
||||
|
||||
impl Constraints {
|
||||
@@ -981,8 +981,8 @@ impl Constraints {
|
||||
pub fn new(values: bool) -> Self {
|
||||
Self {
|
||||
assertions: Vec::new(),
|
||||
public_inputs: HashSet::new(),
|
||||
values: if values { Some(HashMap::new()) } else { None },
|
||||
public_inputs: AHashSet::new(),
|
||||
values: if values { Some(AHashMap::new()) } else { None },
|
||||
}
|
||||
}
|
||||
pub fn publicize(&mut self, s: String) {
|
||||
@@ -991,13 +991,13 @@ impl Constraints {
|
||||
pub fn assertions(&self) -> &Vec<Term> {
|
||||
&self.assertions
|
||||
}
|
||||
pub fn consume(self) -> (Vec<Term>, HashSet<String>, Option<HashMap<String, Value>>) {
|
||||
pub fn consume(self) -> (Vec<Term>, AHashSet<String>, Option<AHashMap<String, Value>>) {
|
||||
(self.assertions, self.public_inputs, self.values)
|
||||
}
|
||||
pub fn from_parts(
|
||||
assertions: Vec<Term>,
|
||||
public_inputs: HashSet<String>,
|
||||
values: Option<HashMap<String, Value>>,
|
||||
public_inputs: AHashSet<String>,
|
||||
values: Option<AHashMap<String, Value>>,
|
||||
) -> Self {
|
||||
Self {
|
||||
assertions,
|
||||
@@ -1009,7 +1009,7 @@ impl Constraints {
|
||||
term(Op::BoolNaryOp(BoolNaryOp::And), self.assertions.clone())
|
||||
}
|
||||
pub fn terms(&self) -> usize {
|
||||
let mut terms = HashSet::<Term>::new();
|
||||
let mut terms = AHashSet::<Term>::new();
|
||||
for a in &self.assertions {
|
||||
for s in PostOrderIter::new(a.clone()) {
|
||||
terms.insert(s);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use super::*;
|
||||
|
||||
lazy_static! {
|
||||
pub static ref TERM_TYPES: RwLock<HashMap<TTerm, Sort>> = RwLock::new(HashMap::new());
|
||||
pub static ref TERM_TYPES: RwLock<AHashMap<TTerm, Sort>> = RwLock::new(AHashMap::new());
|
||||
}
|
||||
|
||||
#[track_caller]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use super::*;
|
||||
use log::debug;
|
||||
use std::collections::{HashMap, HashSet, VecDeque};
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use crate::util::once::OnceQueue;
|
||||
|
||||
struct LinReducer<S: Eq + Hash> {
|
||||
|
||||
@@ -5,9 +5,8 @@ use crate::target::r1cs::*;
|
||||
use log::debug;
|
||||
use rug::ops::Pow;
|
||||
use rug::Integer;
|
||||
use ahash::{AHashMap, AHashSet};
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::collections::HashSet;
|
||||
use std::fmt::Display;
|
||||
use std::iter::ExactSizeIterator;
|
||||
|
||||
@@ -22,16 +21,16 @@ struct ToR1cs {
|
||||
bools: TermMap<Lc>,
|
||||
bvs: TermMap<BvEntry>,
|
||||
fields: TermMap<Lc>,
|
||||
values: Option<HashMap<String, Value>>,
|
||||
public_inputs: HashSet<String>,
|
||||
values: Option<AHashMap<String, Value>>,
|
||||
public_inputs: AHashSet<String>,
|
||||
next_idx: usize,
|
||||
}
|
||||
|
||||
impl ToR1cs {
|
||||
fn new(
|
||||
modulus: Integer,
|
||||
values: Option<HashMap<String, Value>>,
|
||||
public_inputs: HashSet<String>,
|
||||
values: Option<AHashMap<String, Value>>,
|
||||
public_inputs: AHashSet<String>,
|
||||
) -> Self {
|
||||
Self {
|
||||
r1cs: R1cs::new(modulus, values.is_some()),
|
||||
@@ -839,13 +838,13 @@ mod test {
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
struct PureBool(Term, HashMap<String, Value>);
|
||||
struct PureBool(Term, AHashMap<String, Value>);
|
||||
|
||||
impl Arbitrary for PureBool {
|
||||
fn arbitrary(g: &mut Gen) -> Self {
|
||||
let mut rng = rand::rngs::StdRng::seed_from_u64(u64::arbitrary(g));
|
||||
let t = PureBoolDist(g.size()).sample(&mut rng);
|
||||
let values: HashMap<String, Value> = PostOrderIter::new(t.clone())
|
||||
let values: AHashMap<String, Value> = PostOrderIter::new(t.clone())
|
||||
.filter_map(|c| {
|
||||
if let Op::Var(n, _) = &c.op {
|
||||
Some((n.clone(), Value::Bool(bool::arbitrary(g))))
|
||||
@@ -877,7 +876,7 @@ mod test {
|
||||
} else {
|
||||
term![Op::Not; t]
|
||||
};
|
||||
let cs = Constraints::from_parts(vec![t], HashSet::new(), Some(values));
|
||||
let cs = Constraints::from_parts(vec![t], AHashSet::new(), Some(values));
|
||||
let r1cs = to_r1cs(cs, Integer::from(crate::ir::term::field::TEST_FIELD));
|
||||
r1cs.check_all();
|
||||
}
|
||||
@@ -886,7 +885,7 @@ mod test {
|
||||
fn random_bool(ArbitraryTermEnv(t, values): ArbitraryTermEnv) {
|
||||
let v = eval(&t, &values);
|
||||
let t = term![Op::Eq; t, leaf_term(Op::Const(v))];
|
||||
let cs = Constraints::from_parts(vec![t], HashSet::new(), Some(values));
|
||||
let cs = Constraints::from_parts(vec![t], AHashSet::new(), Some(values));
|
||||
let r1cs = to_r1cs(cs, Integer::from(crate::ir::term::field::TEST_FIELD));
|
||||
r1cs.check_all();
|
||||
}
|
||||
@@ -895,7 +894,7 @@ mod test {
|
||||
fn random_pure_bool_opt(ArbitraryBoolEnv(t, values): ArbitraryBoolEnv) {
|
||||
let v = eval(&t, &values);
|
||||
let t = term![Op::Eq; t, leaf_term(Op::Const(v))];
|
||||
let cs = Constraints::from_parts(vec![t], HashSet::new(), Some(values));
|
||||
let cs = Constraints::from_parts(vec![t], AHashSet::new(), Some(values));
|
||||
let r1cs = to_r1cs(cs, Integer::from(crate::ir::term::field::TEST_FIELD));
|
||||
r1cs.check_all();
|
||||
let r1cs2 = reduce_linearities(r1cs);
|
||||
@@ -906,7 +905,7 @@ mod test {
|
||||
fn random_bool_opt(ArbitraryTermEnv(t, values): ArbitraryTermEnv) {
|
||||
let v = eval(&t, &values);
|
||||
let t = term![Op::Eq; t, leaf_term(Op::Const(v))];
|
||||
let cs = Constraints::from_parts(vec![t], HashSet::new(), Some(values));
|
||||
let cs = Constraints::from_parts(vec![t], AHashSet::new(), Some(values));
|
||||
let r1cs = to_r1cs(cs, Integer::from(crate::ir::term::field::TEST_FIELD));
|
||||
r1cs.check_all();
|
||||
let r1cs2 = reduce_linearities(r1cs);
|
||||
@@ -936,12 +935,12 @@ mod test {
|
||||
fn not_opt_test() {
|
||||
init();
|
||||
let t = term![Op::Not; leaf_term(Op::Var("b".to_owned(), Sort::Bool))];
|
||||
let values: HashMap<String, Value> = vec![("b".to_owned(), Value::Bool(true))]
|
||||
let values: AHashMap<String, Value> = vec![("b".to_owned(), Value::Bool(true))]
|
||||
.into_iter()
|
||||
.collect();
|
||||
let v = eval(&t, &values);
|
||||
let t = term![Op::Eq; t, leaf_term(Op::Const(v))];
|
||||
let cs = Constraints::from_parts(vec![t], HashSet::new(), Some(values));
|
||||
let cs = Constraints::from_parts(vec![t], AHashSet::new(), Some(values));
|
||||
let r1cs = to_r1cs(cs, Integer::from(crate::ir::term::field::TEST_FIELD));
|
||||
r1cs.check_all();
|
||||
let r1cs2 = reduce_linearities(r1cs);
|
||||
|
||||
Reference in New Issue
Block a user