-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ebf9789
commit 4ced894
Showing
3 changed files
with
63 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,60 @@ | ||
use std::cmp::Ordering; | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct IndexPath(pub Vec<usize>); | ||
pub struct IndexPath { | ||
pub indices: Vec<usize>, | ||
// Should use Arc<Vec<usize>> | ||
//pub child_index: 0, // All children should share parent index | ||
} | ||
|
||
impl IndexPath { | ||
pub fn new(vec: Vec<usize>) -> IndexPath { | ||
IndexPath(vec) | ||
pub fn new(indices: Vec<usize>) -> IndexPath { | ||
IndexPath { indices } | ||
} | ||
|
||
pub fn adding(&self, index: usize) -> IndexPath { | ||
let mut indices = self.indices.clone(); | ||
indices.push(index); | ||
IndexPath::new(indices) | ||
} | ||
|
||
pub fn push(&mut self, index: usize) { | ||
self.0.push(index); | ||
self.indices.push(index); | ||
} | ||
|
||
pub fn increment_last(&mut self) { | ||
*self.0.last_mut().unwrap() += 1; | ||
*self.indices.last_mut().unwrap() += 1; | ||
} | ||
|
||
pub fn pop(&mut self) -> Option<usize> { | ||
self.0.pop() | ||
self.indices.pop() | ||
} | ||
|
||
pub fn len(&self) -> usize { | ||
self.0.len() | ||
self.indices.len() | ||
} | ||
|
||
pub fn is_empty(&self) -> bool { | ||
self.0.is_empty() | ||
self.indices.is_empty() | ||
} | ||
} | ||
|
||
impl PartialEq for IndexPath { | ||
fn eq(&self, o: &Self) -> bool { | ||
self.0.eq(&o.0) | ||
self.indices.eq(&o.indices) | ||
} | ||
} | ||
|
||
impl Eq for IndexPath {} | ||
|
||
impl PartialOrd for IndexPath { | ||
fn partial_cmp(&self, o: &Self) -> Option<Ordering> { | ||
self.0.partial_cmp(&o.0) | ||
self.indices.partial_cmp(&o.indices) | ||
} | ||
} | ||
|
||
impl Ord for IndexPath { | ||
fn cmp(&self, o: &Self) -> Ordering { | ||
self.0.cmp(&o.0) | ||
self.indices.cmp(&o.indices) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters