Skip to content

Commit ea8f488

Browse files
authored
Merge pull request #11 from segeljakt/rust-cargo-project
Add cargo project and abstract data types
2 parents 891f1bc + 2d8bc3d commit ea8f488

File tree

3 files changed

+113
-0
lines changed

3 files changed

+113
-0
lines changed

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Generated by Cargo
2+
# will have compiled files and executables
3+
debug/
4+
target/
5+
6+
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
7+
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
8+
Cargo.lock
9+
10+
# These are backup files generated by rustfmt
11+
**/*.rs.bk

rust/Cargo.toml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
[package]
2+
name = "swag"
3+
version = "0.2.0"
4+
authors = ["Klas Segeljakt <[email protected]>"]
5+
description = "General Purpose Sliding Window Aggregator."
6+
homepage = "https://github.com/IBM/sliding-window-aggregators/rust"
7+
repository = "https://github.com/IBM/sliding-window-aggregators/rust"
8+
documentation = "https://github.com/IBM/sliding-window-aggregators/rust"
9+
readme = "README.md"
10+
keywords = ["sliding-window-aggregation", "stream-processing", "incremental-computation"]
11+
categories = ["database", "science"]
12+
license-file = "../LICENSE"
13+
edition = "2018"
14+
publish = false
15+
16+
[lib]
17+
name = "swag"
18+
path = "src/lib.rs"
19+
20+
[dependencies]
21+
num-traits = "0.2.12"
22+
arrayvec = "0.5.1"
23+
alga = "0.9.3"
24+
25+
[dev-dependencies]
26+
criterion = "0.3.3"
27+
28+
[profile.dev]
29+
opt-level = 0
30+
debug = 2
31+
debug-assertions = true
32+
rpath = false
33+
lto = false
34+
panic = 'unwind'
35+
incremental = true
36+
37+
[profile.release]
38+
opt-level = 3
39+
debug = 0
40+
debug-assertions = false
41+
rpath = false
42+
lto = false
43+
codegen-units = 1
44+
panic = 'unwind'
45+
46+
[profile.test]
47+
opt-level = 0
48+
debug = 2
49+
debug-assertions = true
50+
rpath = false
51+
lto = false
52+
codegen-units = 1
53+
54+
[profile.bench]
55+
opt-level = 3
56+
debug = 0
57+
rpath = false
58+
lto = false
59+
debug-assertions = false
60+
codegen-units = 1

rust/src/lib.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
use alga::general::Operator;
2+
use std::ops::Range;
3+
4+
/// An abstract data type which maintains a time-ordered sliding window.
5+
pub trait TimeWindow<Time, Value, BinOp>
6+
where
7+
Time: Ord,
8+
BinOp: Operator,
9+
{
10+
/// Returns an empty window.
11+
fn new() -> Self;
12+
/// Inserts the tuple `(t,v)` at time `t` into the window.
13+
fn insert(&mut self, t: Time, v: Value);
14+
/// Removes the tuple `(t,v)` at time `t` from the window (if any).
15+
fn evict(&mut self, t: Time);
16+
/// Combines the values in time order and returns the result, e.g., `1+v1+v2+...+vn`.
17+
fn query(&self) -> Value;
18+
}
19+
20+
/// An abstract data type which maintains a fifo-ordered sliding window.
21+
pub trait FifoWindow<Value, BinOp>
22+
where
23+
BinOp: Operator,
24+
{
25+
/// Returns an empty window.
26+
fn new() -> Self;
27+
/// Inserts a value at the back of the window.
28+
fn push(&mut self, v: Value);
29+
/// Removes a value at the front of the window (if any).
30+
fn pop(&mut self);
31+
/// Combines the values in fifo order and returns the result, e.g., `1+v1+v2+...+vn`.
32+
fn query(&self) -> Value;
33+
}
34+
35+
/// An abstract data type which maintains sliding sub-window aggregates.
36+
pub trait SubWindow<Time, Value>
37+
where
38+
Time: Ord,
39+
{
40+
/// Returns the aggregate of a subwindow.
41+
fn range_query(&self, range: Range<Time>) -> Value;
42+
}

0 commit comments

Comments
 (0)