Skip to main content

ConsolidateMrsP

Struct ConsolidateMrsP 

Source
pub struct ConsolidateMrsP<T, R, S>
where R: GetBeginEnd<T>, S: RangeBounds<T>,
{ /* private fields */ }
Expand description

This struct acts as an owned wrapper for the Option::Some produced by the Consolidate Iterator, which then acts as a normal instance of GetBeginEnd.

Implementations§

Source§

impl<T, R, S> ConsolidateMrsP<T, R, S>
where R: GetBeginEnd<T>, S: RangeBounds<T>,

Source

pub fn new(src: (R, Vec<(usize, S)>)) -> Self

Wwraps the data set and makes it operate as if it is the instance src.0.

Source

pub fn as_src(self) -> (R, Vec<(usize, S)>)

Converts back to the orignal data set used to create this instance.

Examples found in repository?
examples/overlaps.rs (line 21)
3fn main() {
4    for result in Consolidate::num_defaults(
5        [
6            1..=4,
7            3..=5,
8            10..=12,
9            10..=11,
10            13..=13,
11            // This will produce an error, because 13..=13 is "After" 1..=2.
12            1..=2,
13        ]
14        .into_iter(),
15    )
16    .to_consolidate_checker(ConsolidationOrder::Forward)
17    {
18        match result {
19            Ok(row) => {
20                // get our outer range and src rows.
21                let (outer, src) = row.as_src();
22                println!("Outer Range: {}->{}", outer.start(), outer.end());
23                for (id, original) in src {
24                    println!(
25                        "  Row: {}, Range: {}->{}",
26                        id,
27                        original.start(),
28                        original.end()
29                    );
30                }
31            }
32            Err((msg, row)) => {
33                let (outer, src) = row.as_src();
34                println!(
35                    "Error: {}, \n    Produced range: {}->{}",
36                    msg,
37                    outer.start(),
38                    outer.end()
39                );
40                for (id, original) in src {
41                    println!(
42                        "      Caused by: Row: {}, Range: {}->{}",
43                        id,
44                        original.start(),
45                        original.end()
46                    );
47                }
48            }
49        }
50    }
51}
Source

pub fn src(&self) -> &Vec<(usize, S)>

Returns a ref to the internal data set.

Examples found in repository?
examples/columns.rs (line 90)
3fn main() {
4    // We create all of our column data unsorted
5    let mut col_a = vec![0..=11, 2..=3, 7..=9, 22..=33, 34..=39];
6    let mut col_b = vec![6..=9, 6..=9, 6..=7, 11..=22, 7..=11, 9..=9];
7    let mut col_c = vec![3..=4, 3..=9, 4..=6, 30..=41];
8
9    // ** Full Sort Example here! **
10    // We will use this to drive the internals of the sort function
11    let t = NumberIncDecCpCmp::defaults();
12
13    // We create our sort function here
14    let sort_by = |a: &std::ops::RangeInclusive<i32>, b: &std::ops::RangeInclusive<i32>| {
15        sort_forward(a, b, &t.default_rebound(), &t)
16    };
17
18    // Sort all of our rows and force them to exist in the correct order!
19    col_a.sort_by(sort_by);
20    col_b.sort_by(sort_by);
21    col_c.sort_by(sort_by);
22    // ** End Full Sort Example **
23
24    // Create our Columns instance using number defaults.
25    let cols = Columns::num_defaults();
26
27    // give up if we fail to add a column!
28    assert!(cols.add_column(col_a.into_iter()).is_ok());
29    assert!(cols.add_column(col_b.into_iter()).is_ok());
30    assert!(cols.add_column(col_c.into_iter()).is_ok());
31
32    // Just pretty printing our text table border
33    println!(
34        "+---------+-----------+{:-<35}+{:-<61}+{:-<35}+",
35        "", "", ""
36    );
37
38    // Pretty preint our text table header
39    println!(
40        "| Overlap | State(id) |{:^35}|{:^61}|{:^35}|",
41        "Column(A)", "Column(B)", "Column(C)"
42    );
43
44    // In order to access the iter.get_column(column_id) method, the iter instance must remain in scope.
45    // If access to the causal ranges is not required, then a standard for lopp iterator will work.
46    let mut iter = cols.into_iter();
47    let mut id = 0;
48    loop {
49        let next = iter.next();
50        if next.is_none() {
51            // print out the last text bumper.
52            println!(
53                "+---------+-----------+{:-<35}+{:-<61}+{:-<35}+",
54                "", "", ""
55            );
56            return;
57        }
58        let (overlap, res, columns) = next.unwrap();
59        // print a bumper text row.
60        println!(
61            "+---------+-----------+{:-<35}+{:-<61}+{:-<35}+",
62            "", "", ""
63        );
64
65        // Print out the common intersecting range!
66        print!("|  {:^2}->{:^2} |", overlap.get_begin(), overlap.get_end());
67        let mut stop = false;
68        if res.is_err() {
69            print!("   Err({})  |", id);
70            // We still want to access the column or columns that error out before we stop
71            stop = true;
72        } else {
73            print!("   Ok({})   |", id);
74        }
75        for (column_id, col) in columns.iter().enumerate() {
76            let mut txt = Vec::new();
77            match col {
78                Ok(src) => {
79                    for row in src {
80                        // This range contains all of the ranges that were used to create it!
81                        let container = row.as_ref();
82                        txt.push(format!(
83                            "[{}->{}](",
84                            container.get_begin(),
85                            container.get_end()
86                        ));
87                        let mut r = Vec::new();
88
89                        // walk our raw source ranges that caused this larger range
90                        for (row_id, range) in container.src().iter() {
91                            r.push(format!("{}({}->{})", row_id, range.start(), range.end()));
92                        }
93                        txt.push(r.join(","));
94                        txt.push(String::from(")"));
95                    }
96                }
97                Err(msg) => {
98                    // This code exists but does not execute in this example.
99                    // The Err code block, exists to demonstrate how to gain access to the ranges that
100                    // caused a given error.
101
102                    // Save our error for output
103                    txt.push(String::from(*msg));
104
105                    // get our raw column and the original rows that caused the error!
106                    let col = iter.get_column(column_id).unwrap();
107
108                    // This Vec contains the rows that caused the error!
109                    let rows = col.get_rows();
110                    for row in rows {
111                        let result_range = row.as_ref();
112                        // The range that was generated from the raw ranges
113                        txt.push(format!(
114                            "Invalid Range: ({}->{})",
115                            result_range.get_begin(),
116                            result_range.get_end()
117                        ));
118                        for (row_id, range) in result_range.src().iter() {
119                            // One ore more of these ranges caused the error!
120                            txt.push(format!("({}){}->{}", row_id, range.start(), range.end()))
121                        }
122                    }
123                }
124            }
125            match column_id {
126                0 => print!("{:^35}|", txt.join("")),
127                1 => print!("{:^61}|", txt.join("")),
128                2 => print!("{:^35}|", txt.join("")),
129                _ => (),
130            }
131        }
132
133        println!();
134        if stop {
135            // stop here if we ran into an error processing an iterator.
136            break;
137        }
138        id += 1;
139    }
140}

Trait Implementations§

Source§

impl<T, R: GetBeginEnd<T>, S: RangeBounds<T>> GetBeginEnd<T> for ConsolidateMrsP<T, R, S>

Source§

fn get_begin(&self) -> &T

Wrapper for internal Mrs instance.

Source§

fn get_end(&self) -> &T

Wrapper for internal Mrs instance.

Source§

fn to_tuple(self) -> (T, T)

This will drop the sources if used. Consider using ConsolidateMrsP::as_src in stead.

Source§

fn to_tuple_ref(&self) -> (&T, &T)

Source§

impl<T, R: GetBeginEnd<T>, S: RangeBounds<T>> RangeBounds<T> for ConsolidateMrsP<T, R, S>

Source§

fn start_bound(&self) -> Bound<&T>

Wraps the return value from self.get_begin() in a std::ops::Bound::Included.

Source§

fn end_bound(&self) -> Bound<&T>

Wraps the return value from self.get_end() in a std::ops::Bound::Included.

1.35.0 (const: unstable) · Source§

fn contains<U>(&self, item: &U) -> bool
where T: PartialOrd<U>, U: PartialOrd<T> + ?Sized,

Returns true if item is contained in the range. Read more
Source§

fn is_empty(&self) -> bool
where T: PartialOrd,

🔬This is a nightly-only experimental API. (range_bounds_is_empty)
Returns true if the range contains no items. One-sided ranges (RangeFrom, etc) always return false. Read more

Auto Trait Implementations§

§

impl<T, R, S> Freeze for ConsolidateMrsP<T, R, S>
where R: Freeze,

§

impl<T, R, S> RefUnwindSafe for ConsolidateMrsP<T, R, S>

§

impl<T, R, S> Send for ConsolidateMrsP<T, R, S>
where R: Send, T: Send, S: Send,

§

impl<T, R, S> Sync for ConsolidateMrsP<T, R, S>
where R: Sync, T: Sync, S: Sync,

§

impl<T, R, S> Unpin for ConsolidateMrsP<T, R, S>
where R: Unpin, T: Unpin, S: Unpin,

§

impl<T, R, S> UnsafeUnpin for ConsolidateMrsP<T, R, S>
where R: UnsafeUnpin,

§

impl<T, R, S> UnwindSafe for ConsolidateMrsP<T, R, S>
where R: UnwindSafe, T: UnwindSafe, S: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.