1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
use std::convert::From;
use std::vec::IntoIter;
pub struct Vector<T>(Vec<T>);
impl<T> Vector<T> {
pub fn new() -> Self {
Self(vec![])
}
pub fn push(mut self, value: T) -> Self {
self.0.push(value);
self
}
pub fn update(mut self, i: usize, value: T) -> Self {
self.0[i] = value;
self
}
pub fn remove(mut self, i: usize) -> Self {
self.0.remove(i);
self
}
pub fn reverse(mut self) -> Self {
self.0.reverse();
self
}
pub fn sort_by<F>(mut self, compare: F) -> Self
where
F: FnMut(&T, &T) -> std::cmp::Ordering,
{
self.0.sort_by(compare);
self
}
pub fn pop(mut self) -> (Self, Option<T>) {
let v = self.0.pop();
(self, v)
}
pub fn get(&self, i: usize) -> Option<&T> {
self.0.get(i)
}
}
impl<T> Default for Vector<T> {
fn default() -> Self {
Self::new()
}
}
impl<T> IntoIterator for Vector<T> {
type Item = T;
type IntoIter = IntoIter<Self::Item>;
fn into_iter(self) -> Self::IntoIter {
self.0.into_iter()
}
}
impl<T> From<Vec<T>> for Vector<T> {
fn from(vector: Vec<T>) -> Self {
Self(vector)
}
}
impl<T> From<Vector<T>> for Vec<T> {
fn from(vector: Vector<T>) -> Self {
vector.0
}
}