Pre: allow initialization of a CC with an arbitrary counter value. Useful for testing.

This commit is contained in:
Richard Newman 2017-04-11 14:44:11 -07:00
parent 33fa1261b8
commit 98ac559894
3 changed files with 29 additions and 3 deletions

View file

@ -22,6 +22,10 @@ pub struct RcCounter {
/// A simple shared counter.
impl RcCounter {
pub fn with_initial(value: usize) -> Self {
RcCounter { c: Rc::new(AtomicUsize::new(value)) }
}
pub fn new() -> Self {
RcCounter { c: Rc::new(AtomicUsize::new(0)) }
}

View file

@ -206,6 +206,18 @@ impl Default for ConjoiningClauses {
}
}
impl ConjoiningClauses {
/// Construct a new `ConjoiningClauses` with the provided alias counter. This allows a caller
/// to share a counter with an enclosing scope, and to start counting at a particular offset
/// for testing.
pub fn with_alias_counter(counter: RcCounter) -> ConjoiningClauses {
ConjoiningClauses {
alias_counter: counter,
..Default::default()
}
}
}
/// Cloning.
impl ConjoiningClauses {
fn make_receptacle(&self) -> ConjoiningClauses {

View file

@ -19,11 +19,12 @@ mod types;
mod validate;
mod clauses;
use mentat_core::{
Schema,
};
use mentat_core::counter::RcCounter;
use mentat_query::{
FindQuery,
FindSpec,
@ -69,11 +70,20 @@ impl AlgebraicQuery {
}
}
#[allow(dead_code)]
pub fn algebrize_with_counter(schema: &Schema, parsed: FindQuery, counter: usize) -> Result<AlgebraicQuery> {
let alias_counter = RcCounter::with_initial(counter);
let cc = clauses::ConjoiningClauses::with_alias_counter(alias_counter);
algebrize_with_cc(schema, parsed, cc)
}
pub fn algebrize(schema: &Schema, parsed: FindQuery) -> Result<AlgebraicQuery> {
algebrize_with_cc(schema, parsed, clauses::ConjoiningClauses::default())
}
#[allow(dead_code)]
pub fn algebrize_with_cc(schema: &Schema, parsed: FindQuery, mut cc: ConjoiningClauses) -> Result<AlgebraicQuery> {
// TODO: integrate default source into pattern processing.
// TODO: flesh out the rest of find-into-context.
let mut cc = clauses::ConjoiningClauses::default();
let where_clauses = parsed.where_clauses;
for where_clause in where_clauses {
cc.apply_clause(schema, where_clause)?;