Skip to content

Commit 1bd325f

Browse files
authored
Merge pull request #20 from segeljakt/rust-dev
Minor changes
2 parents 00e2b0a + ff16d4a commit 1bd325f

File tree

6 files changed

+21
-19
lines changed

6 files changed

+21
-19
lines changed

rust/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use alga::general::Operator;
22
use std::ops::Range;
33

44
/// An abstract data type which maintains a time-ordered sliding window.
5-
pub trait TimeWindow<Time, Value, BinOp>
5+
pub trait TimeWindow<Time, Value, BinOp>: Clone
66
where
77
Time: Ord,
88
BinOp: Operator,
@@ -18,7 +18,7 @@ where
1818
}
1919

2020
/// An abstract data type which maintains a fifo-ordered sliding window.
21-
pub trait FifoWindow<Value, BinOp>
21+
pub trait FifoWindow<Value, BinOp>: Clone
2222
where
2323
BinOp: Operator,
2424
{

rust/src/reactive/flat_fat.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use alga::general::AbstractMonoid;
22
use alga::general::Operator;
33
use std::collections::HashSet;
44

5-
pub(crate) trait FAT<Value, BinOp>
5+
pub(crate) trait FAT<Value, BinOp>: Clone
66
where
77
Value: AbstractMonoid<BinOp> + Clone,
88
BinOp: Operator,
@@ -33,6 +33,7 @@ where
3333
fn suffix(&self, i: usize) -> Value;
3434
}
3535

36+
#[derive(Clone)]
3637
pub(crate) struct FlatFAT<Value, BinOp>
3738
where
3839
Value: AbstractMonoid<BinOp> + Clone,
@@ -141,7 +142,7 @@ where
141142
let leaf = self.leaf(idx);
142143
self.tree[leaf] = val;
143144
});
144-
(0..self.leaf(0)).into_iter().rev().for_each(|parent| {
145+
(0..self.leaf(0)).rev().for_each(|parent| {
145146
let left = self.left(parent);
146147
let right = self.right(parent);
147148
self.tree[parent] = self.tree[left].operate(&self.tree[right]);
@@ -163,7 +164,7 @@ where
163164
}
164165
node = parent;
165166
}
166-
return agg;
167+
agg
167168
}
168169

169170
fn suffix(&self, i: usize) -> Value {
@@ -176,6 +177,6 @@ where
176177
}
177178
node = parent;
178179
}
179-
return agg;
180+
agg
180181
}
181182
}

rust/src/reactive/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use crate::FifoWindow;
55
use alga::general::AbstractMonoid;
66
use alga::general::Operator;
77

8+
#[derive(Clone)]
89
pub struct Reactive<Value, BinOp>
910
where
1011
Value: AbstractMonoid<BinOp> + Clone,
@@ -31,7 +32,7 @@ where
3132
}
3233
}
3334
fn inverted(&self) -> bool {
34-
return self.front > self.back;
35+
self.front > self.back
3536
}
3637
fn resize(&mut self, capacity: usize) {
3738
let leaves = self.fat.leaves();

rust/src/recalc/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use crate::FifoWindow;
22
use alga::general::AbstractMonoid;
33
use alga::general::Operator;
4-
use std::marker::PhantomData;
54
use std::collections::VecDeque;
5+
use std::marker::PhantomData;
66

7-
#[derive(Debug)]
7+
#[derive(Clone)]
88
pub struct ReCalc<Value, BinOp>
99
where
1010
Value: AbstractMonoid<BinOp> + Clone,
@@ -19,8 +19,8 @@ where
1919
Value: AbstractMonoid<BinOp> + Clone,
2020
BinOp: Operator,
2121
{
22-
fn new() -> ReCalc<Value, BinOp> {
23-
ReCalc {
22+
fn new() -> Self {
23+
Self {
2424
stack: VecDeque::new(),
2525
op: PhantomData,
2626
}

rust/src/soe/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use alga::general::Operator;
44
use std::collections::VecDeque;
55
use std::marker::PhantomData;
66

7-
#[derive(Debug)]
7+
#[derive(Clone)]
88
pub struct SoE<Value, BinOp>
99
where
1010
Value: AbstractGroup<BinOp> + Clone,
@@ -20,8 +20,8 @@ where
2020
Value: AbstractGroup<BinOp> + Clone,
2121
BinOp: Operator,
2222
{
23-
fn new() -> SoE<Value, BinOp> {
24-
SoE {
23+
fn new() -> Self {
24+
Self {
2525
stack: VecDeque::new(),
2626
agg: Value::identity(),
2727
op: PhantomData,

rust/src/two_stacks/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use alga::general::AbstractMonoid;
33
use alga::general::Operator;
44
use std::marker::PhantomData;
55

6-
#[derive(Debug)]
6+
#[derive(Clone)]
77
struct Item<Value>
88
where
99
Value: Clone,
@@ -12,7 +12,7 @@ where
1212
val: Value,
1313
}
1414

15-
#[derive(Debug)]
15+
#[derive(Clone)]
1616
pub struct TwoStacks<Value, BinOp>
1717
where
1818
Value: AbstractMonoid<BinOp> + Clone,
@@ -28,8 +28,8 @@ where
2828
Value: AbstractMonoid<BinOp> + Clone,
2929
BinOp: Operator,
3030
{
31-
fn new() -> TwoStacks<Value, BinOp> {
32-
TwoStacks {
31+
fn new() -> Self {
32+
Self {
3333
front: Vec::new(),
3434
back: Vec::new(),
3535
op: PhantomData,
@@ -63,7 +63,7 @@ where
6363
BinOp: Operator,
6464
{
6565
#[inline(always)]
66-
fn agg(stack: &Vec<Item<Value>>) -> Value {
66+
fn agg(stack: &[Item<Value>]) -> Value {
6767
if let Some(top) = stack.last() {
6868
top.agg.clone()
6969
} else {

0 commit comments

Comments
 (0)