Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewhammer committed Dec 22, 2019
2 parents 2f2e671 + 4782644 commit a205874
Show file tree
Hide file tree
Showing 10 changed files with 161 additions and 161 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[package]
name = "adapton"
version = "0.3.30"
edition = "2018"
authors = ["Matthew A. Hammer <[email protected]>"]

# A short blurb about the package. This is not rendered in any format when
Expand All @@ -12,6 +13,7 @@ documentation = "https://docs.rs/adapton"
homepage = "http://adapton.org"
repository = "https://github.com/Adapton/adapton.rust/"


# This points to a file in the repository (relative to this Cargo.toml). The
# contents of this file are stored and indexed in the registry.
readme = "README.md"
Expand Down
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ A general-purpose **Incremental Computation** (IC) library for Rust.
Versions:
---------

- The [Adapton repo](https://github.com/Adapton/adapton.rust) has the latest, in `dev` and `master` branches.
- branch [dev](https://github.com/Adapton/adapton.rust/tree/dev) contains the **latest development**.
- branch `master` is "stable", e.g., for external libraries.
- Also see the [Adapton crate](https://crates.io/crates/adapton) for periodic "stable" releases.
- The [Adapton repo](https://github.com/Adapton/adapton.rust) has the latest code version in the `master` branch.
- The [Adapton crate](https://crates.io/crates/adapton) for periodic "stable" releases.
- See also: A prior [OCaml implementation](https://github.com/plum-umd/adapton.ocaml).

Research and Development Community:
Expand Down
12 changes: 6 additions & 6 deletions src/catalog/bitstring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ pub struct BS {
}

pub trait BitString {
fn pow(i64, i64) -> i64;
fn flip(i64, i64) -> i64;
fn is_set(i64, i64) -> bool;
fn prepend(i64, BS) -> BS;
fn length(BS) -> i64;
fn shift_left(BS, i64) -> BS;
fn pow(_: i64, _: i64) -> i64;
fn flip(_: i64, _: i64) -> i64;
fn is_set(_: i64, _: i64) -> bool;
fn prepend(_: i64, _: BS) -> BS;
fn length(_: BS) -> i64;
fn shift_left(_: BS, _: i64) -> BS;

const MAX_LEN: i64;
}
Expand Down
80 changes: 40 additions & 40 deletions src/catalog/collections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ use std::hash::{Hash,Hasher};
use std::collections::hash_map::DefaultHasher;
use std::rc::Rc;

use macros::* ;
use adapton::engine::* ;
use crate::macros::* ;
use crate::adapton::engine::* ;

pub mod trie {
pub use catalog::trie::*;
pub use crate::catalog::trie::*;
}

#[derive(Clone,Copy,Hash,Eq,PartialEq,Debug)]
Expand Down Expand Up @@ -36,11 +36,11 @@ pub trait ListIntro<X:'static> : Debug+Clone+Hash+PartialEq+Eq+'static {
/// Introduce an empty list
fn nil () -> Self ;
/// Introduce a Cons cell
fn cons (X, Self) -> Self ;
fn cons (_: X, _: Self) -> Self ;
/// Introduce a Name "cons" cell
fn name (Name, Self) -> Self ;
fn name (_: Name, _: Self) -> Self ;
/// Introduce a list with an articulation that holds a list
fn art (Art<Self>) -> Self ;
fn art (_: Art<Self>) -> Self ;

/// Creates a singleton list. Derived from `cons` and `nil` introduction forms.
fn singleton (hd:X) -> Self {
Expand Down Expand Up @@ -84,7 +84,7 @@ pub trait ListElim<X> : Debug+Clone+Hash+PartialEq+Eq {
/// Eliminates the `art` case internally, by forcing the art and
/// eliminating the resulting list with the given handler functions;
/// forces multiple `art` cases, if need be.
fn elim<Res,NilF,ConsF,NameF> (&Self, NilF, ConsF, NameF) -> Res
fn elim<Res,NilF,ConsF,NameF> (_: &Self, _: NilF, _: ConsF, _: NameF) -> Res
where NilF:FnOnce( &Self) -> Res
, ConsF:FnOnce(&X, &Self) -> Res
, NameF:FnOnce(&Name, &Self) -> Res ;
Expand All @@ -93,7 +93,7 @@ pub trait ListElim<X> : Debug+Clone+Hash+PartialEq+Eq {
/// argument. This variant is needed due to the move semantics of
/// Rust. The argument is moved into the body of the activated
/// handler function when it is applied.
fn elim_arg<Arg,Res,NilF,ConsF,NameF> (Self, Arg, NilF, ConsF, NameF) -> Res
fn elim_arg<Arg,Res,NilF,ConsF,NameF> (_: Self, _: Arg, _: NilF, _: ConsF, _: NameF) -> Res
where NilF:FnOnce( Self, Arg) -> Res
, ConsF:FnOnce(X, Self, Arg) -> Res
, NameF:FnOnce(Name, Self, Arg) -> Res ;
Expand Down Expand Up @@ -314,13 +314,13 @@ pub fn list_append<X:'static, L:ListIntro<X>+ListElim<X>>(l1:L, l2:L) -> L {
pub trait RoseIntro<Leaf,Branch> : Debug+Clone+Hash+PartialEq+Eq {
type List: ListElim<Self>;
/// Introduce a leaf with exactly zero children
fn leaf (Leaf) -> Self;
fn leaf (_: Leaf) -> Self;
/// Introduce a branch with zero or more subtrees
fn branch (Branch, Self::List) -> Self;
fn branch (_: Branch, _: Self::List) -> Self;
/// Introduce a Named subtree
fn name (Name, Self) -> Self ;
fn name (_: Name, _: Self) -> Self ;
/// Introduce a list with an articulation that holds a list
fn art (Art<Self>) -> Self ;
fn art (_: Art<Self>) -> Self ;
}

/// Rose Trees: A tree with arbitrary branching at each node.
Expand All @@ -330,7 +330,7 @@ pub trait RoseIntro<Leaf,Branch> : Debug+Clone+Hash+PartialEq+Eq {
pub trait RoseElim<Leaf,Branch> : Debug+Clone+Hash+PartialEq+Eq {
type Children: ListElim<Self>;
fn elim<Arg, Res, LeafFn, BranchFn, NameFn>
(Self, Arg, LeafFn, BranchFn, NameFn) -> Res
(_: Self, _: Arg, _: LeafFn, _: BranchFn, _: NameFn) -> Res
where LeafFn: FnOnce(Leaf, Arg) -> Res
, BranchFn:FnOnce(Branch, Self::Children, Arg) -> Res
, NameFn: FnOnce(Name, Self, Arg) -> Res
Expand All @@ -341,12 +341,12 @@ pub trait RoseElim<Leaf,Branch> : Debug+Clone+Hash+PartialEq+Eq {
/// Pugh and Teiltelbaum's POPL 1989 paper, and its "Chunky List"
/// representation (*Incremental Computation via Function Caching*).
pub trait Level : Debug+Hash+PartialEq+Eq+Clone+'static {
fn new<X:Hash>(&X) -> Self ;
fn new<X:Hash>(_: &X) -> Self ;
fn bits () -> Self ;
fn zero () -> Self ;
fn inc (&Self) -> Self ;
fn add (&Self, &Self) -> Self ;
fn lte (&Self, &Self) -> bool ;
fn inc (_: &Self) -> Self ;
fn add (_: &Self, _: &Self) -> Self ;
fn lte (_: &Self, _: &Self) -> bool ;
fn max_val () -> Self ;
fn max (a:&Self, b:&Self) -> Self {
if Self::lte(a, b) { b.clone() } else { a.clone() }
Expand All @@ -359,43 +359,43 @@ pub trait Level : Debug+Hash+PartialEq+Eq+Clone+'static {
/// further, the binary cases `name` and `bin` carry levels of type `Lev`, which helps establish and maintain balance.
pub trait TreeIntro<Lev:Level,Leaf> : Debug+Hash+PartialEq+Eq+Clone+'static {
fn nil () -> Self ;
fn leaf (Leaf) -> Self ;
fn bin (Lev, Self, Self) -> Self ;
fn leaf (_: Leaf) -> Self ;
fn bin (_: Lev, _: Self, _: Self) -> Self ;

// requisite "adaptonic" constructors: `name` and `art`:
fn name (Name, Lev, Self, Self) -> Self ;
fn art (Art<Self>) -> Self ;
fn name (_: Name, _: Lev, _: Self, _: Self) -> Self ;
fn art (_: Art<Self>) -> Self ;
}

pub trait TreeElim<Lev:Level,Leaf> : Debug+Hash+PartialEq+Eq+Clone+'static {
fn lev_of_tree(&Self) -> Lev ;
fn lev_of_tree(_: &Self) -> Lev ;

fn elim<Res,NilC,LeafC,BinC,NameC>
(Self, NilC, LeafC, BinC, NameC) -> Res
(_: Self, _: NilC, _: LeafC, _: BinC, _: NameC) -> Res
where NilC : FnOnce() -> Res
, LeafC : FnOnce(Leaf) -> Res
, BinC : FnOnce(Lev, Self, Self) -> Res
, NameC : FnOnce(Name, Lev, Self, Self) -> Res
;

fn elim_ref<Res,NilC,LeafC,BinC,NameC>
(&Self, NilC, LeafC, BinC, NameC) -> Res
(_: &Self, _: NilC, _: LeafC, _: BinC, _: NameC) -> Res
where NilC : FnOnce() -> Res
, LeafC : FnOnce(&Leaf) -> Res
, BinC : FnOnce(&Lev, &Self, &Self) -> Res
, NameC : FnOnce(&Name, &Lev, &Self, &Self) -> Res
;

fn elim_arg<Arg,Res,NilC,LeafC,BinC,NameC>
(Self, Arg, NilC, LeafC, BinC, NameC) -> Res
(_: Self, _: Arg, _: NilC, _: LeafC, _: BinC, _: NameC) -> Res
where NilC : FnOnce(Arg) -> Res
, LeafC : FnOnce(Leaf, Arg) -> Res
, BinC : FnOnce(Lev, Self, Self, Arg) -> Res
, NameC : FnOnce(Name, Lev, Self, Self, Arg) -> Res
;

fn full_move<Arg,Res,NilC,LeafC,BinC,NameC,ArtC>
(Self, Arg, NilC, LeafC, BinC, NameC, ArtC) -> Res
(_: Self, _: Arg, _: NilC, _: LeafC, _: BinC, _: NameC, _: ArtC) -> Res
where NilC : FnOnce(Arg) -> Res
, LeafC : FnOnce(Leaf, Arg) -> Res
, BinC : FnOnce(Lev, Self, Self, Arg) -> Res
Expand Down Expand Up @@ -436,11 +436,11 @@ pub trait MapElim<Dom,Cod>
: Debug+Hash+PartialEq+Eq+Clone+'static

{
fn find(&Self, d:&Dom) -> Option<Cod>;
fn remove (Self, d:&Dom) -> (Self, Option<Cod>);
fn fold<Res,F>(Self, Res, Rc<F>) -> Res where
fn find(_: &Self, d:&Dom) -> Option<Cod>;
fn remove (_: Self, d:&Dom) -> (Self, Option<Cod>);
fn fold<Res,F>(_: Self, _: Res, _: Rc<F>) -> Res where
F:Fn(Dom, Cod, Res) -> Res;
fn append(Self, other:Self) -> Self;
fn append(_: Self, other:Self) -> Self;
}

pub fn map_empty<Dom,Cod,M:MapIntro<Dom,Cod>>() -> M { M::empty() }
Expand All @@ -452,11 +452,11 @@ pub trait SetIntro<Elm>
: Debug+Hash+PartialEq+Eq+Clone+'static
{
fn empty () -> Self;
fn add (Self, e:Elm) -> Self;
fn remove (Self, e:&Elm) -> Self;
fn union (Self, Self) -> Self;
fn inter (Self, Self) -> Self;
fn diff (Self, Self) -> Self;
fn add (_: Self, e:Elm) -> Self;
fn remove (_: Self, e:&Elm) -> Self;
fn union (_: Self, _: Self) -> Self;
fn inter (_: Self, _: Self) -> Self;
fn diff (_: Self, _: Self) -> Self;
}

impl<Elm,Map:MapIntro<Elm,()>+MapElim<Elm,()>> SetIntro<Elm> for Map {
Expand Down Expand Up @@ -486,7 +486,7 @@ pub trait SetElim<Elm>
: Debug+Hash+PartialEq+Eq+Clone+'static
{
fn is_mem (set:&Self, e:&Elm) -> bool;
fn fold<Res,F>(set:Self, Res, F) -> Res where
fn fold<Res,F>(set:Self, _: Res, _: F) -> Res where
F:Fn(Elm, Res) -> Res;
}

Expand Down Expand Up @@ -754,7 +754,7 @@ pub fn filter_list_of_tree
, L:ListIntro<X>+ListElim<X>+'static
, T:TreeElim<Lev,X>+'static
>
(tree:T, pred:Box<Fn(&X) -> bool>) -> L
(tree:T, pred:Box<dyn Fn(&X) -> bool>) -> L
{
let nil = L::nil();
tree_fold_seq
Expand All @@ -775,7 +775,7 @@ pub fn filter_tree_of_tree
, Te:TreeElim<Lev,X>+'static
, Ti:TreeIntro<Lev,X>+TreeElim<Lev,X>+'static
>
(tree:Te, pred:Box<Fn(&X) -> bool>) -> Ti
(tree:Te, pred:Box<dyn Fn(&X) -> bool>) -> Ti
{
tree_fold_up
(tree,
Expand All @@ -797,7 +797,7 @@ pub fn monoid_of_tree
< Lev:Level, X:Debug+Eq+Hash+Clone+'static
, Te:TreeElim<Lev,X>+'static
>
(tree:Te, id_elm:X, bin_op:Rc<Fn(X,X) -> X>) -> X
(tree:Te, id_elm:X, bin_op:Rc<dyn Fn(X,X) -> X>) -> X
{
let bin_op2 = bin_op.clone();
tree_fold_up
Expand Down Expand Up @@ -1067,7 +1067,7 @@ pub fn test_mergesort2 () {
||prune_tree_of_tree::<_,_,_,Tree<_>>(t));
println!("input tree: {:?}", eager_tree_of_tree::<_,_,_,Tree<_>>(t.clone()));
let s = ns(name_of_str("mergesort"),
||mergesort_list_of_tree2::<_,_,_,List<_>>(t, (Some(name_of_usize(666)))));
||mergesort_list_of_tree2::<_,_,_,List<_>>(t, Some(name_of_usize(666))));
let o = vec_of_list(s, None);
println!("output vec: {:?}", o);
o
Expand Down
68 changes: 34 additions & 34 deletions src/catalog/trie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ use std::collections::hash_map::DefaultHasher;
use std::rc::Rc;
use std::cmp::min;

use adapton::catalog::collections::{ListIntro, ListElim, list_fold};
use adapton::catalog::bitstring::*;
use adapton::engine::*;
use macros::*;
use crate::adapton::catalog::collections::{ListIntro, ListElim, list_fold};
use crate::adapton::catalog::bitstring::*;
use crate::adapton::engine::*;
use crate::macros::*;

/// Probablistically Balanced Trie
/// Rough implementation of probabilistic tries from OOPSLA 2015 paper.
Expand All @@ -32,7 +32,7 @@ pub struct Meta {
}

pub trait MetaT {
fn hash_seeded(&self, u64);
fn hash_seeded(&self, _: u64);
}

impl MetaT for Meta {
Expand Down Expand Up @@ -86,52 +86,52 @@ impl MetaT for Meta {
// impl<X: Debug + Hash + PartialEq + Eq + Clone + 'static> Eq for Trie<X> {}

pub trait TrieIntro<X>: Debug + Hash + PartialEq + Eq + Clone + 'static {
fn nil(BS) -> Self;
fn leaf(BS, X) -> Self;
fn bin(BS, Self, Self) -> Self;
fn root(Meta, Self) -> Self;
fn nil(_: BS) -> Self;
fn leaf(_: BS, _: X) -> Self;
fn bin(_: BS, _: Self, _: Self) -> Self;
fn root(_: Meta, _: Self) -> Self;

// requisite "adaptonic" constructors: `name` and `art`:
fn name(Name, Self) -> Self;
fn art(Art<Self>) -> Self;
fn name(_: Name, _: Self) -> Self;
fn art(_: Art<Self>) -> Self;

fn empty(Meta) -> Self;
fn singleton(Meta, Name, X) -> Self;
fn extend(Name, Self, X) -> Self;
fn empty(_: Meta) -> Self;
fn singleton(_: Meta, _: Name, _: X) -> Self;
fn extend(_: Name, _: Self, _: X) -> Self;
}

pub trait TrieElim<X>: Debug + Hash + PartialEq + Eq + Clone + 'static {
fn find(&Self, &X, i64) -> Option<X>;
fn is_empty(&Self) -> bool;
fn split_atomic(Self) -> Self;
fn find(_: &Self, _: &X, _: i64) -> Option<X>;
fn is_empty(_: &Self) -> bool;
fn split_atomic(_: Self) -> Self;

fn elim<Res, NilC, LeafC, BinC, RootC, NameC>(Self, NilC, LeafC, BinC, RootC, NameC) -> Res
fn elim<Res, NilC, LeafC, BinC, RootC, NameC>(_: Self, _: NilC, _: LeafC, _: BinC, _: RootC, _: NameC) -> Res
where NilC: FnOnce(BS) -> Res,
LeafC: FnOnce(BS, X) -> Res,
BinC: FnOnce(BS, Self, Self) -> Res,
RootC: FnOnce(Meta, Self) -> Res,
NameC: FnOnce(Name, Self) -> Res;

fn elim_arg<Arg, Res, NilC, LeafC, BinC, RootC, NameC>(Self,
Arg,
NilC,
LeafC,
BinC,
RootC,
NameC)
fn elim_arg<Arg, Res, NilC, LeafC, BinC, RootC, NameC>(_: Self,
_: Arg,
_: NilC,
_: LeafC,
_: BinC,
_: RootC,
_: NameC)
-> Res
where NilC: FnOnce(BS, Arg) -> Res,
LeafC: FnOnce(BS, X, Arg) -> Res,
BinC: FnOnce(BS, Self, Self, Arg) -> Res,
RootC: FnOnce(Meta, Self, Arg) -> Res,
NameC: FnOnce(Name, Self, Arg) -> Res;

fn elim_ref<Res, NilC, LeafC, BinC, RootC, NameC>(&Self,
NilC,
LeafC,
BinC,
RootC,
NameC)
fn elim_ref<Res, NilC, LeafC, BinC, RootC, NameC>(_: &Self,
_: NilC,
_: LeafC,
_: BinC,
_: RootC,
_: NameC)
-> Res
where NilC: FnOnce(&BS) -> Res,
LeafC: FnOnce(&BS, &X) -> Res,
Expand Down Expand Up @@ -420,16 +420,16 @@ impl<X: Debug + Hash + PartialEq + Eq + Clone + 'static> TrieElim<X> for Trie<X>

pub trait SetIntro<X>: Debug + Hash + PartialEq + Eq + Clone + 'static {
fn empty() -> Self;
fn add(Self, e: X) -> Self;
fn add(_: Self, e: X) -> Self;
// fn remove(Self, e: &X) -> Self;
// fn union(Self, Self) -> Self;
// fn inter(Self, Self) -> Self;
// fn diff(Self, Self) -> Self;
}

pub trait SetElim<X>: Debug + Hash + PartialEq + Eq + Clone + 'static {
fn mem(&Self, &X) -> bool;
fn fold<Res, F>(Self, Res, Rc<F>) -> Res where F: Fn(X, Res) -> Res;
fn mem(_: &Self, _: &X) -> bool;
fn fold<Res, F>(_: Self, _: Res, _: Rc<F>) -> Res where F: Fn(X, Res) -> Res;
}

impl<X, Set: TrieIntro<X> + TrieElim<X>> SetIntro<X> for Set {
Expand Down
Loading

0 comments on commit a205874

Please sign in to comment.