From e3e7bc2497d4d0e4dc8c20cc16c9dd516e752e28 Mon Sep 17 00:00:00 2001 From: freyja Date: Thu, 4 Nov 2021 18:21:23 -0700 Subject: [PATCH] use a gapbuffer for storing volumes --- src/plane/mod.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/plane/mod.rs b/src/plane/mod.rs index 78e3156..55d008d 100644 --- a/src/plane/mod.rs +++ b/src/plane/mod.rs @@ -4,6 +4,8 @@ use std::{ iter::FromIterator, }; +use gapbuf::GapBuffer; + use crate::volume::Volume; use stack::Stack; @@ -25,7 +27,7 @@ enum Vision { pub struct Plane { stack: Stack, - volumes: Vec, + volumes: GapBuffer, current_volume: usize, vision: Vision, // current vision @@ -41,7 +43,7 @@ impl Plane { pub fn new() -> Plane { Plane { stack: Stack::new(), - volumes: Vec::new(), + volumes: GapBuffer::new(), current_volume: 0, @@ -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); }