Skip to content

Commit 4462d4b

Browse files
committed
move Point and Interpolate to database crate
1 parent 9f3fe88 commit 4462d4b

File tree

8 files changed

+70
-69
lines changed

8 files changed

+70
-69
lines changed

site/src/interpolate.rs renamed to database/src/interpolate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//! Given a series with some missing data `[1, 2, ?, 4]`,
1111
//! this iterator yields `[1, 2, 2, 4]`.
1212
13-
use crate::db::Point;
13+
use crate::selector::Point;
1414

1515
/// Whether a point has been interpolated or not
1616
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]

database/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use std::ops::{Add, Sub};
99
use std::sync::Arc;
1010
use std::time::Duration;
1111

12+
pub mod interpolate;
1213
pub mod pool;
1314
pub mod selector;
1415

database/src/selector.rs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::fmt;
2+
13
use crate::{ArtifactId, ArtifactIdIter};
24

35
#[derive(Debug)]
@@ -16,3 +18,60 @@ impl Iterator for StatisticSeries {
1618
self.artifact_ids.size_hint()
1719
}
1820
}
21+
22+
pub trait Point {
23+
type Key: fmt::Debug + PartialEq + Clone;
24+
25+
fn key(&self) -> &Self::Key;
26+
fn set_key(&mut self, key: Self::Key);
27+
fn value(&self) -> Option<f64>;
28+
fn set_value(&mut self, value: f64);
29+
fn interpolated(&self) -> bool;
30+
fn set_interpolated(&mut self);
31+
}
32+
33+
impl<T: Clone + PartialEq + fmt::Debug> Point for (T, Option<f64>) {
34+
type Key = T;
35+
36+
fn key(&self) -> &T {
37+
&self.0
38+
}
39+
fn set_key(&mut self, key: T) {
40+
self.0 = key;
41+
}
42+
fn value(&self) -> Option<f64> {
43+
self.1
44+
}
45+
fn set_value(&mut self, value: f64) {
46+
self.1 = Some(value);
47+
}
48+
fn interpolated(&self) -> bool {
49+
false
50+
}
51+
fn set_interpolated(&mut self) {
52+
// no-op
53+
}
54+
}
55+
56+
impl<T: Clone + PartialEq + fmt::Debug> Point for (T, f64) {
57+
type Key = T;
58+
59+
fn key(&self) -> &T {
60+
&self.0
61+
}
62+
fn set_key(&mut self, key: T) {
63+
self.0 = key;
64+
}
65+
fn value(&self) -> Option<f64> {
66+
Some(self.1)
67+
}
68+
fn set_value(&mut self, value: f64) {
69+
self.1 = value;
70+
}
71+
fn interpolated(&self) -> bool {
72+
false
73+
}
74+
fn set_interpolated(&mut self) {
75+
// no-op
76+
}
77+
}

site/src/average.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::db::Point;
1+
use database::selector::Point;
22

33
/// This aggregates interpolated iterators.
44
///
@@ -80,12 +80,13 @@ where
8080

8181
#[cfg(test)]
8282
mod tests {
83+
use database::selector::Point;
84+
8385
use super::average;
8486

8587
#[test]
8688
fn test_no_interpolation_average() {
8789
// Test that averaging works without interpolation.
88-
use crate::db::Point;
8990

9091
let v = vec![
9192
vec![("a", 0.0), ("b", 200.0)],
@@ -109,8 +110,7 @@ mod tests {
109110
#[test]
110111
fn test_interpolation_average() {
111112
// Test that averaging works with interpolation.
112-
use crate::db::Point;
113-
use crate::interpolate::{Interpolate, IsInterpolated};
113+
use database::interpolate::{Interpolate, IsInterpolated};
114114

115115
let v = vec![
116116
vec![("a", Some(0.0)), ("b", Some(200.0))],

site/src/db.rs

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,2 @@
1-
use std::fmt;
2-
31
pub use crate::average::average;
42
pub use database::*;
5-
6-
pub trait Point {
7-
type Key: fmt::Debug + PartialEq + Clone;
8-
9-
fn key(&self) -> &Self::Key;
10-
fn set_key(&mut self, key: Self::Key);
11-
fn value(&self) -> Option<f64>;
12-
fn set_value(&mut self, value: f64);
13-
fn interpolated(&self) -> bool;
14-
fn set_interpolated(&mut self);
15-
}
16-
17-
impl<T: Clone + PartialEq + fmt::Debug> Point for (T, Option<f64>) {
18-
type Key = T;
19-
20-
fn key(&self) -> &T {
21-
&self.0
22-
}
23-
fn set_key(&mut self, key: T) {
24-
self.0 = key;
25-
}
26-
fn value(&self) -> Option<f64> {
27-
self.1
28-
}
29-
fn set_value(&mut self, value: f64) {
30-
self.1 = Some(value);
31-
}
32-
fn interpolated(&self) -> bool {
33-
false
34-
}
35-
fn set_interpolated(&mut self) {
36-
// no-op
37-
}
38-
}
39-
40-
impl<T: Clone + PartialEq + fmt::Debug> Point for (T, f64) {
41-
type Key = T;
42-
43-
fn key(&self) -> &T {
44-
&self.0
45-
}
46-
fn set_key(&mut self, key: T) {
47-
self.0 = key;
48-
}
49-
fn value(&self) -> Option<f64> {
50-
Some(self.1)
51-
}
52-
fn set_value(&mut self, value: f64) {
53-
self.1 = value;
54-
}
55-
fn interpolated(&self) -> bool {
56-
false
57-
}
58-
fn set_interpolated(&mut self) {
59-
// no-op
60-
}
61-
}

site/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ pub mod server;
1010
mod average;
1111
mod benchmark_metadata;
1212
mod comparison;
13-
mod interpolate;
1413
mod request_handlers;
1514
mod resources;
1615
mod selector;

site/src/request_handlers/graph.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ use crate::api::detail_sections::CompilationSections;
77
use crate::api::graphs::GraphKind;
88
use crate::api::{detail_graphs, detail_sections, graphs, runtime_detail_graphs, ServerResult};
99
use crate::db::{self, ArtifactId, Profile, Scenario};
10-
use crate::interpolate::IsInterpolated;
1110
use crate::load::SiteCtxt;
1211
use crate::selector::{
1312
CompileBenchmarkQuery, CompileTestCase, RuntimeBenchmarkQuery, Selector, SeriesResponse,
1413
};
1514
use crate::self_profile::get_or_download_self_profile;
1615

16+
use database::interpolate::IsInterpolated;
17+
1718
/// Returns data for before/after graphs when comparing a single test result comparison
1819
/// for a compile-time benchmark.
1920
pub async fn handle_compile_detail_graphs(

site/src/selector.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@
2222
//! there are multiple `None`s.
2323
2424
use crate::db::{ArtifactId, Profile, Scenario};
25-
use crate::interpolate::Interpolate;
2625
use crate::load::SiteCtxt;
2726

2827
use collector::Bound;
28+
use database::interpolate::Interpolate;
2929
use database::selector::StatisticSeries;
3030
use database::ArtifactIdIter;
31-
use database::{Benchmark, CodegenBackend, Commit, Connection, Index, Lookup};
31+
use database::{selector::Point, Benchmark, CodegenBackend, Commit, Connection, Index, Lookup};
3232

3333
use crate::comparison::Metric;
3434
use async_trait::async_trait;
@@ -149,7 +149,7 @@ impl<TestCase, T> SeriesResponse<TestCase, T> {
149149
pub fn interpolate(self) -> SeriesResponse<TestCase, Interpolate<T>>
150150
where
151151
T: Iterator,
152-
T::Item: crate::db::Point,
152+
T::Item: Point,
153153
{
154154
self.map(|s| Interpolate::new(s))
155155
}

0 commit comments

Comments
 (0)