Skip to content

Instantly share code, notes, and snippets.

@dylanede
Forked from anonymous/playground.rs
Last active August 25, 2017 15:20
Show Gist options
  • Save dylanede/1b793898b6bd620a719a1ff5b588efa8 to your computer and use it in GitHub Desktop.
Save dylanede/1b793898b6bd620a719a1ff5b588efa8 to your computer and use it in GitHub Desktop.
Rust code shared from the playground
// Need an endpoint to drive everything (provide top level criteria) - Nodes don't actually have the data going through them - only construct and modify callbacks
// Need an abstraction for a dynamically updating time serise - notification of points adding, updating and removing, refreshing - NOT a stream, kind of like a signal for multiple values in parallel
// Node - given criteria object, constructs a collection of output points, delegating where necessary
// criteria object may be modified at runtime - node should then modify the subscription
// Should be possible to have node sub-graph templates (maybe just functions) for generation based on changes in data source sets
// Internally to the graph, criteria may be dynamically updated at run time (e.g. to implement "join-on")
// Criteria:
//
// At points in time
// Filtering ranges of time (collection of ranges - indexed by start or end time) with optional priority ordering (i.e. closest to one end of the range first, if possible)
// Filter based on time+data together
// Is the following point worth it compared to a static list (an enum)?
// The set of possible criteria is an extensible set (use Any) and a node type need not support understanding all of them - as long as it is conservative in the data it returns.
// So, two main traits to interact with: nodes and collections
// Points in time:
// Node -> Collection<Timestamp> -> Collection<Point>
// In ranges, ordered:
// Node -> Collection<Ordered Ranges> -> Collection<Point>
// Collections are both streams (of collection edits - add/remove/replace) and queryable in themselves - queries limited to "give me data (of type T) for a range of time, as a future that resolves to an actual list of T"
// Depending on collection, interpretation of whether data is in a range may differ (i.e. where the data itself is ranges of time)
// May need global timestamps for organising query results and stream results
// - Need to detect happens-before in changes downstream from other collections - not as simple as just an atomic integer
trait Stream {
type Item;
type Error;
fn poll(&mut self) -> Result<Self::Item, Self::Error>;
}
type Time = i64;
enum Bound<T> {
Including(T),
Excluding(T),
Unbounded(T)
}
struct TimeRange(Bound<Time>, Bound<Time>);
struct Criteria {}
enum WhereChange {
Replace(Criteria),
}
trait DataWhere<T> {
type Out : View<T>;
}
trait Node {
type Data;
//type View<WS> : View<Self::Data>;
fn data_where<WS>(&self, where_stream: WS) -> <(WS, Self) as DataWhere<Self::Data>>::Out where (WS, Self) : DataWhere<Self::Data>;//WS : Stream<WhereChange>;
}
enum Change<T> {
NewPoint(Time, T),
UpdatePoint(Time, T),
RemovePoint(Time)
}
trait Refreshable {
fn refresh(&self, range: TimeRange);
}
trait View<T> {
type ChangeStream : Stream<Item=Change<T>> + Refreshable;
fn changes(&self) -> Self::ChangeStream;
}
struct SimpleNode {
}
fn main() {}
fn foo<S>(scope: S) {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment