Skip to content

Commit

Permalink
[Generalization][VStore] DeltaStore is now parametrized by a sub-stor…
Browse files Browse the repository at this point in the history
…e instead of a memory. Related to #20.
  • Loading branch information
ptal committed Apr 11, 2016
1 parent 0b867ad commit b1fca35
Show file tree
Hide file tree
Showing 9 changed files with 155 additions and 105 deletions.
7 changes: 3 additions & 4 deletions src/libpcp/propagation/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,14 +210,13 @@ mod test {
use propagators::cmp::*;
use propagators::distinct::*;
use term::*;
use variable::delta_store::DeltaStore;
use variable::memory::*;
use variable::test::*;
use interval::interval::*;
use interval::ops::*;
use gcollections::ops::*;

type Domain = Interval<i32>;
type VStore = DeltaStore<CopyStore<Domain>, Domain, FDEvent>;
type Domain = DomainI32;
type VStore = DeltaStoreI32;
type CStore = Store<VStore, FDEvent, IndexedDeps, RelaxedFifo>;

#[test]
Expand Down
7 changes: 3 additions & 4 deletions src/libpcp/search/branching/binary_split.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,13 @@ mod test {
use propagation::events::*;
use propagation::reactors::*;
use propagation::schedulers::*;
use variable::delta_store::DeltaStore;
use variable::memory::*;
use variable::test::*;
use gcollections::ops::*;
use interval::interval::*;
use interval::ops::*;

type Domain = Interval<i32>;
type VStore = DeltaStore<CopyStore<Domain>, Domain, FDEvent>;
type Domain = DomainI32;
type VStore = DeltaStoreI32;
type CStore = Store<VStore, FDEvent, IndexedDeps, RelaxedFifo>;
type FDSpace = Space<VStore, CStore>;

Expand Down
7 changes: 3 additions & 4 deletions src/libpcp/search/branching/first_smallest_var.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,15 @@ mod test {
use propagation::events::*;
use propagation::reactors::*;
use propagation::schedulers::*;
use variable::delta_store::DeltaStore;
use variable::memory::*;
use variable::test::*;
use search::space::*;
use search::branching::VarSelection;
use gcollections::ops::*;
use interval::interval::*;
use interval::ops::*;

type Domain = Interval<i32>;
type VStore = DeltaStore<CopyStore<Domain>, Domain, FDEvent>;
type Domain = DomainI32;
type VStore = DeltaStoreI32;
type CStore = Store<VStore, FDEvent, IndexedDeps, RelaxedFifo>;
type FDSpace = Space<VStore, CStore>;

Expand Down
7 changes: 3 additions & 4 deletions src/libpcp/search/engine/one_solution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ mod test {
use propagators::cmp::*;
use propagators::distinct::*;
use variable::ops::*;
use variable::delta_store::DeltaStore;
use variable::memory::*;
use variable::test::*;
use term::*;
use search::search_tree_visitor::*;
use search::search_tree_visitor::Status::*;
Expand All @@ -125,8 +124,8 @@ mod test {
use gcollections::ops::*;
use test::Bencher;

type Domain = Interval<i32>;
type VStore = DeltaStore<CopyStore<Domain>, Domain, FDEvent>;
type Domain = DomainI32;
type VStore = DeltaStoreI32;
type CStore = Store<VStore, FDEvent, IndexedDeps, RelaxedFifo>;
type FDSpace = Space<VStore, CStore>;

Expand Down
80 changes: 80 additions & 0 deletions src/libpcp/variable/concept.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
// Copyright 2016 Pierre Talbot (IRCAM)

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at

// http://www.apache.org/licenses/LICENSE-2.0

// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use kernel::*;
use variable::ops::*;
use gcollections::ops::*;
use gcollections::ops::sequence::ordering::*;
use std::ops::Index;
use std::fmt::Display;

pub trait DomainConcept :
Clone + Display + Bounded + Cardinality + Subset
{}

impl<R> DomainConcept for R where
R: Clone + Display + Bounded + Cardinality + Subset
{}

pub trait ReadOnlyMemoryConcept<Domain> :
Cardinality<Size=usize>
+ Iterable<Item=Domain>
+ Empty
+ Index<usize, Output=Domain>
+ Display
+ Clone // TO DELETE
{}

impl<Domain, R> ReadOnlyMemoryConcept<Domain> for R where
R: Cardinality<Size=usize>
+ Iterable<Item=Domain>
+ Empty
+ Index<usize, Output=Domain>
+ Display
+ Clone // TO DELETE
{}

pub trait MemoryConcept<Domain> :
ReadOnlyMemoryConcept<Domain>
+ Push<Back, Domain>
+ Update<usize, Domain>
+ Freeze
where
Domain: DomainConcept
{}

impl<Domain, R> MemoryConcept<Domain> for R where
R: ReadOnlyMemoryConcept<Domain>
+ Push<Back, Domain>
+ Update<usize, Domain>
+ Freeze,
Domain: DomainConcept
{}

pub trait StoreConcept<Domain> :
ReadOnlyMemoryConcept<Domain>
+ Alloc<Domain>
+ Update<usize, Domain>
+ State
where
Domain: DomainConcept
{}

impl<Domain, R> StoreConcept<Domain> for R where
R: ReadOnlyMemoryConcept<Domain>
+ Alloc<Domain>
+ Update<usize, Domain>
+ State,
Domain: DomainConcept
{}
95 changes: 48 additions & 47 deletions src/libpcp/variable/delta_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,46 +14,47 @@

use kernel::*;
use variable::ops::*;
use variable::store::*;
use variable::memory::*;
use term::identity::*;
use variable::concept::*;
use gcollections::ops::*;
use std::slice;
use vec_map::{Drain, VecMap};
use std::fmt::{Formatter, Display, Error};
use std::ops::Index;
use std::marker::PhantomData;

pub struct DeltaStore<Memory, Domain, Event> where
Memory: MemoryConcept<Domain>,
pub struct DeltaStore<Store, Domain, Event> where
Store: StoreConcept<Domain>,
Domain: DomainConcept
{
store: Store<Memory, Domain>,
delta: VecMap<Event>
store: Store,
delta: VecMap<Event>,
phantom: PhantomData<Domain>
}

impl<Memory, Domain, Event> DeltaStore<Memory, Domain, Event> where
Memory: MemoryConcept<Domain>,
impl<Store, Domain, Event> DeltaStore<Store, Domain, Event> where
Store: StoreConcept<Domain>,
Domain: DomainConcept
{
fn from_store(store: Store<Memory, Domain>) -> DeltaStore<Memory, Domain, Event> {
fn from_store(store: Store) -> DeltaStore<Store, Domain, Event> {
DeltaStore {
store: store,
delta: VecMap::new()
delta: VecMap::new(),
phantom: PhantomData
}
}
}

impl<Memory, Domain, Event> Empty for DeltaStore<Memory, Domain, Event> where
Memory: MemoryConcept<Domain>,
impl<Store, Domain, Event> Empty for DeltaStore<Store, Domain, Event> where
Store: StoreConcept<Domain>,
Domain: DomainConcept
{
fn empty() -> DeltaStore<Memory, Domain, Event> {
fn empty() -> DeltaStore<Store, Domain, Event> {
DeltaStore::from_store(Store::empty())
}
}

impl<Memory, Domain, Event> DeltaStore<Memory, Domain, Event> where
Memory: MemoryConcept<Domain>,
impl<Store, Domain, Event> DeltaStore<Store, Domain, Event> where
Store: StoreConcept<Domain>,
Domain: DomainConcept,
Event: MonotonicEvent<Domain> + Merge + Clone
{
Expand All @@ -73,8 +74,8 @@ impl<Memory, Domain, Event> DeltaStore<Memory, Domain, Event> where
}
}

impl<Memory, Domain, Event> DrainDelta<Event> for DeltaStore<Memory, Domain, Event> where
Memory: MemoryConcept<Domain>,
impl<Store, Domain, Event> DrainDelta<Event> for DeltaStore<Store, Domain, Event> where
Store: StoreConcept<Domain>,
Domain: DomainConcept
{
fn drain_delta<'a>(&'a mut self) -> Drain<'a, Event> {
Expand All @@ -86,35 +87,32 @@ impl<Memory, Domain, Event> DrainDelta<Event> for DeltaStore<Memory, Domain, Eve
}
}

impl<Memory, Domain, Event> Clone for DeltaStore<Memory, Domain, Event> where
Memory: MemoryConcept<Domain>,
impl<Store, Domain, Event> Clone for DeltaStore<Store, Domain, Event> where
Store: StoreConcept<Domain>,
Domain: DomainConcept
{
fn clone(&self) -> Self {
DeltaStore {
store: self.store.clone(),
delta: VecMap::new()
}
DeltaStore::from_store(self.store.clone())
}
}

impl<Memory, Domain, Event> State for DeltaStore<Memory, Domain, Event> where
Memory: MemoryConcept<Domain>,
impl<Store, Domain, Event> State for DeltaStore<Store, Domain, Event> where
Store: StoreConcept<Domain>,
Domain: DomainConcept
{
type Label = Store<Memory, Domain>;
type Label = <Store as State>::Label;

fn mark(&self) -> Store<Memory, Domain> {
fn mark(&self) -> Self::Label {
self.store.mark()
}

fn restore(self, label: Store<Memory, Domain>) -> Self {
DeltaStore::from_store(label)
fn restore(self, label: Self::Label) -> Self {
DeltaStore::from_store(self.store.restore(label))
}
}

impl<Memory, Domain, Event> Iterable for DeltaStore<Memory, Domain, Event> where
Memory: MemoryConcept<Domain>,
impl<Store, Domain, Event> Iterable for DeltaStore<Store, Domain, Event> where
Store: StoreConcept<Domain>,
Domain: DomainConcept
{
type Item = Domain;
Expand All @@ -124,8 +122,8 @@ impl<Memory, Domain, Event> Iterable for DeltaStore<Memory, Domain, Event> where
}
}

impl<Memory, Domain, Event> Cardinality for DeltaStore<Memory, Domain, Event> where
Memory: MemoryConcept<Domain>,
impl<Store, Domain, Event> Cardinality for DeltaStore<Store, Domain, Event> where
Store: StoreConcept<Domain>,
Domain: DomainConcept
{
type Size = usize;
Expand All @@ -135,21 +133,23 @@ impl<Memory, Domain, Event> Cardinality for DeltaStore<Memory, Domain, Event> wh
}
}

impl<Memory, Domain, Event> Alloc<Domain> for DeltaStore<Memory, Domain, Event> where
Memory: MemoryConcept<Domain>,
impl<Store, Location, Domain, Event> Alloc<Domain> for DeltaStore<Store, Domain, Event> where
Store: StoreConcept<Domain>,
Store: Alloc<Domain, Location=Location>,
Location: VarIndex,
Domain: DomainConcept
{
type Location = Identity<Domain>;
type Location = <Store as Alloc<Domain>>::Location;

fn alloc(&mut self, dom: Domain) -> Identity<Domain> {
fn alloc(&mut self, dom: Domain) -> Self::Location {
let var = self.store.alloc(dom);
self.delta.reserve_len(var.index());
var
}
}

impl<Memory, Domain, Event> Update<usize, Domain> for DeltaStore<Memory, Domain, Event> where
Memory: MemoryConcept<Domain>,
impl<Store, Domain, Event> Update<usize, Domain> for DeltaStore<Store, Domain, Event> where
Store: StoreConcept<Domain>,
Domain: DomainConcept,
Event: MonotonicEvent<Domain> + Merge + Clone
{
Expand All @@ -159,8 +159,8 @@ impl<Memory, Domain, Event> Update<usize, Domain> for DeltaStore<Memory, Domain,
}
}

impl<Memory, Domain, Event> Index<usize> for DeltaStore<Memory, Domain, Event> where
Memory: MemoryConcept<Domain>,
impl<Store, Domain, Event> Index<usize> for DeltaStore<Store, Domain, Event> where
Store: StoreConcept<Domain>,
Domain: DomainConcept
{
type Output = Domain;
Expand All @@ -169,8 +169,8 @@ impl<Memory, Domain, Event> Index<usize> for DeltaStore<Memory, Domain, Event> w
}
}

impl<Memory, Domain, Event> Display for DeltaStore<Memory, Domain, Event> where
Memory: MemoryConcept<Domain>,
impl<Store, Domain, Event> Display for DeltaStore<Store, Domain, Event> where
Store: StoreConcept<Domain>,
Domain: DomainConcept
{
fn fmt(&self, formatter: &mut Formatter) -> Result<(), Error> {
Expand All @@ -183,15 +183,16 @@ pub mod test {
use super::*;
use kernel::Alloc;
use variable::ops::*;
use variable::memory::*;
use variable::test::DomainI32;
use variable::test::DeltaStoreI32;
use term::identity::*;
use propagation::events::*;
use propagation::events::FDEvent::*;
use interval::interval::*;
use gcollections::ops::*;

pub type Domain = Interval<i32>;
pub type FDStore = DeltaStore<CopyStore<Domain>, Domain, FDEvent>;
pub type Domain = DomainI32;
pub type FDStore = DeltaStoreI32;

fn test_op<Op>(source: Domain, target: Domain, delta_expected: Vec<FDEvent>, update_success: bool, op: Op) where
Op: FnOnce(&FDStore, Identity<Domain>) -> Domain
Expand Down
Loading

0 comments on commit b1fca35

Please sign in to comment.