Skip to content

Commit

Permalink
search for multiple TRMC opportunities
Browse files Browse the repository at this point in the history
  • Loading branch information
folkertdev committed Jun 21, 2023
1 parent cb3f96a commit b848128
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 117 deletions.
2 changes: 1 addition & 1 deletion crates/cli_testing_examples/benchmarks/CFold.roc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ main =
|> Task.putLine

Err GetIntError ->
Task.putLine "Error: Failed to get Integer from stdin."
Task.putLine "Error: Failed to get Integer from stdin."

Expr : [
Add Expr Expr,
Expand Down
1 change: 0 additions & 1 deletion crates/cli_testing_examples/benchmarks/Deriv.roc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ main =

Err GetIntError ->
Task.putLine "Error: Failed to get Integer from stdin."


nest : (I64, Expr -> IO Expr), I64, Expr -> IO Expr
nest = \f, n, e -> Task.loop { s: n, f, m: n, x: e } nestHelp
Expand Down
9 changes: 4 additions & 5 deletions crates/cli_testing_examples/benchmarks/NQueens.roc
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ main =
when inputResult is
Ok n ->
queens n # original koka 13
|> Num.toStr
|> Task.putLine
|> Num.toStr
|> Task.putLine

Err GetIntError ->
Task.putLine "Error: Failed to get Integer from stdin."
Expand All @@ -21,7 +21,8 @@ ConsList a : [Nil, Cons a (ConsList a)]
queens = \n -> length (findSolutions n n)

findSolutions = \n, k ->
if k <= 0 then # should we use U64 as input type here instead?
if k <= 0 then
# should we use U64 as input type here instead?
Cons Nil Nil
else
extend n Nil (findSolutions n (k - 1))
Expand All @@ -40,7 +41,6 @@ appendSafe = \k, soln, solns ->
else
appendSafe (k - 1) soln solns


safe : I64, I64, ConsList I64 -> Bool
safe = \queen, diagonal, xs ->
when xs is
Expand All @@ -51,7 +51,6 @@ safe = \queen, diagonal, xs ->
else
Bool.false


length : ConsList a -> I64
length = \xs ->
lengthHelp xs 0
Expand Down
1 change: 0 additions & 1 deletion crates/cli_testing_examples/benchmarks/QuicksortApp.roc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ main =

Err GetIntError ->
Task.putLine "Error: Failed to get Integer from stdin."


sort : List I64 -> List I64
sort = \list ->
Expand Down
10 changes: 8 additions & 2 deletions crates/cli_testing_examples/benchmarks/RBTreeCk.roc
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,15 @@ ins = \tree, kx, vx ->

Node Black a ky vy b ->
if lt kx ky then
(if isRed a then balance1 (Node Black Leaf ky vy b) (ins a kx vx) else Node Black (ins a kx vx) ky vy b)
if isRed a then
balance1 (Node Black Leaf ky vy b) (ins a kx vx)
else
Node Black (ins a kx vx) ky vy b
else if lt ky kx then
(if isRed b then balance2 (Node Black a ky vy Leaf) (ins b kx vx) else Node Black a ky vy (ins b kx vx))
if isRed b then
balance2 (Node Black a ky vy Leaf) (ins b kx vx)
else
Node Black a ky vy (ins b kx vx)
else
Node Black a kx vx b

Expand Down
1 change: 0 additions & 1 deletion crates/cli_testing_examples/benchmarks/RBTreeDel.roc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ main =

Err GetIntError ->
Task.putLine "Error: Failed to get Integer from stdin."


boom : Str -> a
boom = \_ -> boom ""
Expand Down
16 changes: 16 additions & 0 deletions crates/compiler/collections/src/vec_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ impl<T: PartialEq> VecSet<T> {
self.elements.is_empty()
}

pub fn singleton(value: T) -> Self {
Self {
elements: vec![value],
}
}

pub fn swap_remove(&mut self, index: usize) -> T {
self.elements.swap_remove(index)
}
Expand Down Expand Up @@ -96,6 +102,16 @@ impl<T: PartialEq> VecSet<T> {
{
self.elements.retain(f)
}

pub fn keep_if_in_both(&mut self, other: &Self) {
self.elements.retain(|e| other.contains(e));
}

pub fn keep_if_in_either(&mut self, other: Self) {
for e in other.elements {
self.insert(e);
}
}
}

impl<A: Ord> Extend<A> for VecSet<A> {
Expand Down
Loading

0 comments on commit b848128

Please sign in to comment.