Skip to content

Commit

Permalink
use a gapbuffer for storing volumes
Browse files Browse the repository at this point in the history
  • Loading branch information
geremachek committed Nov 5, 2021
1 parent 99f3943 commit e3e7bc2
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/plane/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use std::{
iter::FromIterator,
};

use gapbuf::GapBuffer;

use crate::volume::Volume;
use stack::Stack;

Expand All @@ -25,7 +27,7 @@ enum Vision {
pub struct Plane {
stack: Stack,

volumes: Vec<Volume>,
volumes: GapBuffer<Volume>,
current_volume: usize,

vision: Vision, // current vision
Expand All @@ -41,7 +43,7 @@ impl Plane {
pub fn new() -> Plane {
Plane {
stack: Stack::new(),
volumes: Vec::new(),
volumes: GapBuffer::new(),

current_volume: 0,

Expand Down Expand Up @@ -74,7 +76,7 @@ impl Plane {

fn push_volume(&mut self, v: Volume) {
if self.volumes.is_empty() || self.current_volume == self.volumes.len()-1 {
self.volumes.push(v);
self.volumes.push_back(v);
} else {
self.volumes.insert(self.current_volume+1, v);
}
Expand Down

0 comments on commit e3e7bc2

Please sign in to comment.