Skip to content

Commit 9f2261b

Browse files
committed
TreeRepr: make most of the fields private
1 parent 7fd4f93 commit 9f2261b

File tree

3 files changed

+27
-27
lines changed

3 files changed

+27
-27
lines changed

src/applied/interval_tree.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ impl<Iv: Interval, V> AppliedTree<IvNode<Iv, V>> for IvTree<Iv, V> {
261261
let mut tree = Self::with_nodes(nodes);
262262

263263
// initialize maxb values
264-
for i in (1..tree.data.len()).rev() {
264+
for i in (1..tree.capacity()).rev() {
265265
if !tree.is_nil(i) {
266266
tree.update_parent_maxb(i);
267267
}

src/base/base_repr.rs

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use base::{Node, Entry, Sink, lefti, righti, parenti, SlotStack};
1+
use base::{Node, Entry, Sink, lefti, righti, parenti, SlotStack, Refill};
22
use base::bulk_delete::DeleteRangeCache;
33
use std::fmt::{Debug, Formatter};
44
use std::fmt;
@@ -21,11 +21,11 @@ impl<N: Node, T> TreeDerefMut<N> for T where T: Deref<Target=TreeRepr<N>> + Dere
2121

2222
#[derive(Clone)]
2323
pub struct TreeRepr<N: Node> {
24-
pub data: Vec<N>,
25-
pub mask: Vec<bool>,
24+
data: Vec<N>,
25+
mask: Vec<bool>,
2626
pub size: usize,
2727

28-
pub delete_range_cache: DeleteRangeCache,
28+
delete_range_cache: DeleteRangeCache,
2929
}
3030

3131

@@ -119,14 +119,18 @@ impl<N: Node> TreeRepr<N> {
119119
pub fn clear(&mut self) {
120120
self.drop_items();
121121
}
122+
123+
pub fn capacity(&self) -> usize {
124+
self.data.len()
125+
}
122126
}
123127

124128

125129
//---- Accessors -----------------------------------------------------------------------------------
126130
impl<N: Node> TreeRepr<N> {
127131
// The caller must make sure idx is inside bounds.
128132
#[inline(always)]
129-
fn mask(&self, idx: usize) -> bool {
133+
pub fn mask(&self, idx: usize) -> bool {
130134
debug_assert!(idx < self.data.len());
131135
unsafe {
132136
*self.mask.get_unchecked(idx)
@@ -135,7 +139,7 @@ impl<N: Node> TreeRepr<N> {
135139

136140
// The caller must make sure idx is inside bounds.
137141
#[inline(always)]
138-
fn mask_mut(&mut self, idx: usize) -> &mut bool {
142+
pub fn mask_mut(&mut self, idx: usize) -> &mut bool {
139143
debug_assert!(idx < self.data.len());
140144
unsafe {
141145
self.mask.get_unchecked_mut(idx)
@@ -674,6 +678,19 @@ impl<N: Node> TraverseMut<N> for TreeRepr<N> {}
674678

675679

676680

681+
impl<N: Node> Refill for TreeRepr<N> where N::K: Copy, N::V: Copy {
682+
fn refill(&mut self, master: &TreeRepr<N>) {
683+
let len = self.data.len();
684+
debug_assert!(len == master.data.len());
685+
unsafe {
686+
ptr::copy_nonoverlapping(master.data.as_ptr(), self.data.as_mut_ptr(), len);
687+
ptr::copy_nonoverlapping(master.mask.as_ptr(), self.mask.as_mut_ptr(), len);
688+
}
689+
self.size = master.size;
690+
}
691+
}
692+
693+
677694
/// Returns the closest subtree A enclosing `idx`, such that A is the left child (or 0 if no such
678695
/// node is found). `idx` is considered to enclose itself, so we return `idx` if it is the left
679696
/// child.

src/base/mod.rs

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ pub use self::drivers::*;
1515
pub use self::base_repr::*;
1616
pub use self::node::*;
1717

18-
use std::ptr;
19-
20-
2118
pub trait Sink<T> {
2219
fn consume(&mut self, x: T);
2320
}
@@ -29,20 +26,6 @@ pub trait Refill {
2926
}
3027

3128

32-
33-
impl<N: Node> Refill for TreeRepr<N> where N::K: Copy, N::V: Copy {
34-
fn refill(&mut self, master: &TreeRepr<N>) {
35-
let len = self.data.len();
36-
debug_assert!(len == master.data.len());
37-
unsafe {
38-
ptr::copy_nonoverlapping(master.data.as_ptr(), self.data.as_mut_ptr(), len);
39-
ptr::copy_nonoverlapping(master.mask.as_ptr(), self.mask.as_mut_ptr(), len);
40-
}
41-
self.size = master.size;
42-
}
43-
}
44-
45-
4629
//impl<T: Clone+Item> Refill<T> for TeardownTree<T> {
4730
// fn refill(&mut self, master: &TeardownTree<T>) {
4831
// let len = self.data().len();
@@ -150,9 +133,9 @@ pub mod validation {
150133
pub fn check_integrity<N: Node>(tree: &Tree<N>) -> Result<(), isize> {
151134
let mut noccupied = 0;
152135

153-
for i in 0..tree.data.len() {
154-
if tree.mask[i] {
155-
if i != 0 && !tree.mask[parenti(i)] {
136+
for i in 0..tree.capacity() {
137+
if tree.mask(i) {
138+
if i != 0 && !tree.mask(parenti(i)) {
156139
return Err(i as isize);
157140
}
158141

0 commit comments

Comments
 (0)