collections: Switch field privacy as necessary
This commit is contained in:
parent
9a3d04ae76
commit
8ad7e5481f
12 changed files with 112 additions and 110 deletions
|
@ -227,9 +227,9 @@ enum Op {Union, Intersect, Assign, Difference}
|
|||
#[deriving(Clone)]
|
||||
pub struct Bitv {
|
||||
/// Internal representation of the bit vector (small or large)
|
||||
priv rep: BitvVariant,
|
||||
rep: BitvVariant,
|
||||
/// The number of valid bits in the internal representation
|
||||
priv nbits: uint
|
||||
nbits: uint
|
||||
}
|
||||
|
||||
fn die() -> ! {
|
||||
|
@ -587,9 +587,9 @@ fn iterate_bits(base: uint, bits: uint, f: |uint| -> bool) -> bool {
|
|||
|
||||
/// An iterator for `Bitv`.
|
||||
pub struct Bits<'a> {
|
||||
priv bitv: &'a Bitv,
|
||||
priv next_idx: uint,
|
||||
priv end_idx: uint,
|
||||
bitv: &'a Bitv,
|
||||
next_idx: uint,
|
||||
end_idx: uint,
|
||||
}
|
||||
|
||||
impl<'a> Iterator<bool> for Bits<'a> {
|
||||
|
@ -648,12 +648,12 @@ impl<'a> RandomAccessIterator<bool> for Bits<'a> {
|
|||
/// as a `uint`.
|
||||
#[deriving(Clone)]
|
||||
pub struct BitvSet {
|
||||
priv size: uint,
|
||||
size: uint,
|
||||
|
||||
// In theory this is a `Bitv` instead of always a `BigBitv`, but knowing that
|
||||
// there's an array of storage makes our lives a whole lot easier when
|
||||
// performing union/intersection/etc operations
|
||||
priv bitv: BigBitv
|
||||
bitv: BigBitv
|
||||
}
|
||||
|
||||
impl BitvSet {
|
||||
|
@ -912,8 +912,8 @@ impl BitvSet {
|
|||
}
|
||||
|
||||
pub struct BitPositions<'a> {
|
||||
priv set: &'a BitvSet,
|
||||
priv next_idx: uint
|
||||
set: &'a BitvSet,
|
||||
next_idx: uint
|
||||
}
|
||||
|
||||
impl<'a> Iterator<uint> for BitPositions<'a> {
|
||||
|
|
|
@ -23,10 +23,10 @@ use std::fmt::Show;
|
|||
|
||||
#[allow(missing_doc)]
|
||||
pub struct BTree<K, V> {
|
||||
priv root: Node<K, V>,
|
||||
priv len: uint,
|
||||
priv lower_bound: uint,
|
||||
priv upper_bound: uint
|
||||
root: Node<K, V>,
|
||||
len: uint,
|
||||
lower_bound: uint,
|
||||
upper_bound: uint
|
||||
}
|
||||
|
||||
impl<K: TotalOrd, V> BTree<K, V> {
|
||||
|
|
|
@ -32,9 +32,9 @@ use deque::Deque;
|
|||
|
||||
/// A doubly-linked list.
|
||||
pub struct DList<T> {
|
||||
priv length: uint,
|
||||
priv list_head: Link<T>,
|
||||
priv list_tail: Rawlink<Node<T>>,
|
||||
length: uint,
|
||||
list_head: Link<T>,
|
||||
list_tail: Rawlink<Node<T>>,
|
||||
}
|
||||
|
||||
type Link<T> = Option<~Node<T>>;
|
||||
|
@ -48,9 +48,9 @@ struct Node<T> {
|
|||
|
||||
/// Double-ended DList iterator
|
||||
pub struct Items<'a, T> {
|
||||
priv head: &'a Link<T>,
|
||||
priv tail: Rawlink<Node<T>>,
|
||||
priv nelem: uint,
|
||||
head: &'a Link<T>,
|
||||
tail: Rawlink<Node<T>>,
|
||||
nelem: uint,
|
||||
}
|
||||
|
||||
// FIXME #11820: the &'a Option<> of the Link stops clone working.
|
||||
|
@ -60,16 +60,16 @@ impl<'a, T> Clone for Items<'a, T> {
|
|||
|
||||
/// Double-ended mutable DList iterator
|
||||
pub struct MutItems<'a, T> {
|
||||
priv list: &'a mut DList<T>,
|
||||
priv head: Rawlink<Node<T>>,
|
||||
priv tail: Rawlink<Node<T>>,
|
||||
priv nelem: uint,
|
||||
list: &'a mut DList<T>,
|
||||
head: Rawlink<Node<T>>,
|
||||
tail: Rawlink<Node<T>>,
|
||||
nelem: uint,
|
||||
}
|
||||
|
||||
/// DList consuming iterator
|
||||
#[deriving(Clone)]
|
||||
pub struct MoveItems<T> {
|
||||
priv list: DList<T>
|
||||
list: DList<T>
|
||||
}
|
||||
|
||||
/// Rawlink is a type like Option<T> but for holding a raw pointer
|
||||
|
|
|
@ -20,7 +20,7 @@ use std::num::Bitwise;
|
|||
pub struct EnumSet<E> {
|
||||
// We must maintain the invariant that no bits are set
|
||||
// for which no variant exists
|
||||
priv bits: uint
|
||||
bits: uint
|
||||
}
|
||||
|
||||
/// An interface for casting C-like enum to uint and back.
|
||||
|
@ -102,8 +102,8 @@ impl<E:CLike> BitAnd<EnumSet<E>, EnumSet<E>> for EnumSet<E> {
|
|||
|
||||
/// An iterator over an EnumSet
|
||||
pub struct Items<E> {
|
||||
priv index: uint,
|
||||
priv bits: uint,
|
||||
index: uint,
|
||||
bits: uint,
|
||||
}
|
||||
|
||||
impl<E:CLike> Items<E> {
|
||||
|
|
|
@ -100,25 +100,25 @@ mod table {
|
|||
/// this and going "what? of course there are debug-only asserts!", then
|
||||
/// please make this use them!
|
||||
pub struct RawTable<K, V> {
|
||||
priv capacity: uint,
|
||||
priv size: uint,
|
||||
priv hashes: *mut u64,
|
||||
priv keys: *mut K,
|
||||
priv vals: *mut V,
|
||||
capacity: uint,
|
||||
size: uint,
|
||||
hashes: *mut u64,
|
||||
keys: *mut K,
|
||||
vals: *mut V,
|
||||
}
|
||||
|
||||
/// Represents an index into a `RawTable` with no key or value in it.
|
||||
pub struct EmptyIndex {
|
||||
priv idx: int,
|
||||
priv nocopy: marker::NoCopy,
|
||||
idx: int,
|
||||
nocopy: marker::NoCopy,
|
||||
}
|
||||
|
||||
/// Represents an index into a `RawTable` with a key, value, and hash
|
||||
/// in it.
|
||||
pub struct FullIndex {
|
||||
priv idx: int,
|
||||
priv hash: SafeHash,
|
||||
priv nocopy: marker::NoCopy,
|
||||
idx: int,
|
||||
hash: SafeHash,
|
||||
nocopy: marker::NoCopy,
|
||||
}
|
||||
|
||||
impl FullIndex {
|
||||
|
@ -142,7 +142,7 @@ mod table {
|
|||
/// A hash that is not zero, since we use that to represent empty buckets.
|
||||
#[deriving(Eq)]
|
||||
pub struct SafeHash {
|
||||
priv hash: u64,
|
||||
hash: u64,
|
||||
}
|
||||
|
||||
impl SafeHash {
|
||||
|
@ -376,18 +376,18 @@ mod table {
|
|||
}
|
||||
|
||||
pub struct Entries<'a, K, V> {
|
||||
priv table: &'a RawTable<K, V>,
|
||||
priv idx: uint,
|
||||
table: &'a RawTable<K, V>,
|
||||
idx: uint,
|
||||
}
|
||||
|
||||
pub struct MutEntries<'a, K, V> {
|
||||
priv table: &'a mut RawTable<K, V>,
|
||||
priv idx: uint,
|
||||
table: &'a mut RawTable<K, V>,
|
||||
idx: uint,
|
||||
}
|
||||
|
||||
pub struct MoveEntries<K, V> {
|
||||
priv table: RawTable<K, V>,
|
||||
priv idx: uint,
|
||||
table: RawTable<K, V>,
|
||||
idx: uint,
|
||||
}
|
||||
|
||||
impl<'a, K, V> Iterator<(&'a K, &'a V)> for Entries<'a, K, V> {
|
||||
|
@ -675,19 +675,19 @@ static INITIAL_LOAD_FACTOR: Fraction = (9, 10);
|
|||
#[deriving(Clone)]
|
||||
pub struct HashMap<K, V, H = sip::SipHasher> {
|
||||
// All hashes are keyed on these values, to prevent hash collision attacks.
|
||||
priv hasher: H,
|
||||
hasher: H,
|
||||
|
||||
// When size == grow_at, we double the capacity.
|
||||
priv grow_at: uint,
|
||||
grow_at: uint,
|
||||
|
||||
// The capacity must never drop below this.
|
||||
priv minimum_capacity: uint,
|
||||
minimum_capacity: uint,
|
||||
|
||||
priv table: table::RawTable<K, V>,
|
||||
table: table::RawTable<K, V>,
|
||||
|
||||
// We keep this at the end since it's 4-bytes, unlike everything else
|
||||
// in this struct. Might as well save a word of padding!
|
||||
priv load_factor: Fraction,
|
||||
load_factor: Fraction,
|
||||
}
|
||||
|
||||
/// Get the number of elements which will force the capacity to grow.
|
||||
|
@ -1385,7 +1385,7 @@ pub type SetMoveItems<K> =
|
|||
/// requires that the elements implement the `Eq` and `Hash` traits.
|
||||
#[deriving(Clone)]
|
||||
pub struct HashSet<T, H = sip::SipHasher> {
|
||||
priv map: HashMap<T, (), H>
|
||||
map: HashMap<T, (), H>
|
||||
}
|
||||
|
||||
impl<T: TotalEq + Hash<S>, S, H: Hasher<S>> Eq for HashSet<T, H> {
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
|
||||
#![feature(macro_rules, managed_boxes, default_type_params, phase)]
|
||||
|
||||
#![allow(visible_private_types)] // NOTE: remove after a stage0 snap
|
||||
|
||||
extern crate rand;
|
||||
|
||||
#[cfg(test)] extern crate test;
|
||||
|
|
|
@ -56,10 +56,10 @@ struct LruEntry<K, V> {
|
|||
|
||||
/// An LRU Cache.
|
||||
pub struct LruCache<K, V> {
|
||||
priv map: HashMap<KeyRef<K>, ~LruEntry<K, V>>,
|
||||
priv max_size: uint,
|
||||
priv head: *mut LruEntry<K, V>,
|
||||
priv tail: *mut LruEntry<K, V>,
|
||||
map: HashMap<KeyRef<K>, ~LruEntry<K, V>>,
|
||||
max_size: uint,
|
||||
head: *mut LruEntry<K, V>,
|
||||
tail: *mut LruEntry<K, V>,
|
||||
}
|
||||
|
||||
impl<S, K: Hash<S>> Hash<S> for KeyRef<K> {
|
||||
|
|
|
@ -19,7 +19,7 @@ use std::slice;
|
|||
/// A priority queue implemented with a binary heap
|
||||
#[deriving(Clone)]
|
||||
pub struct PriorityQueue<T> {
|
||||
priv data: ~[T],
|
||||
data: ~[T],
|
||||
}
|
||||
|
||||
impl<T:Ord> Container for PriorityQueue<T> {
|
||||
|
@ -181,7 +181,7 @@ impl<T:Ord> PriorityQueue<T> {
|
|||
|
||||
/// PriorityQueue iterator
|
||||
pub struct Items <'a, T> {
|
||||
priv iter: slice::Items<'a, T>,
|
||||
iter: slice::Items<'a, T>,
|
||||
}
|
||||
|
||||
impl<'a, T> Iterator<&'a T> for Items<'a, T> {
|
||||
|
|
|
@ -25,9 +25,9 @@ static MINIMUM_CAPACITY: uint = 2u;
|
|||
/// RingBuf is a circular buffer that implements Deque.
|
||||
#[deriving(Clone)]
|
||||
pub struct RingBuf<T> {
|
||||
priv nelts: uint,
|
||||
priv lo: uint,
|
||||
priv elts: ~[Option<T>]
|
||||
nelts: uint,
|
||||
lo: uint,
|
||||
elts: ~[Option<T>]
|
||||
}
|
||||
|
||||
impl<T> Container for RingBuf<T> {
|
||||
|
@ -230,10 +230,10 @@ impl<T> RingBuf<T> {
|
|||
|
||||
/// RingBuf iterator
|
||||
pub struct Items<'a, T> {
|
||||
priv lo: uint,
|
||||
priv index: uint,
|
||||
priv rindex: uint,
|
||||
priv elts: &'a [Option<T>],
|
||||
lo: uint,
|
||||
index: uint,
|
||||
rindex: uint,
|
||||
elts: &'a [Option<T>],
|
||||
}
|
||||
|
||||
impl<'a, T> Iterator<&'a T> for Items<'a, T> {
|
||||
|
@ -285,9 +285,9 @@ impl<'a, T> RandomAccessIterator<&'a T> for Items<'a, T> {
|
|||
|
||||
/// RingBuf mutable iterator
|
||||
pub struct MutItems<'a, T> {
|
||||
priv remaining1: &'a mut [Option<T>],
|
||||
priv remaining2: &'a mut [Option<T>],
|
||||
priv nelts: uint,
|
||||
remaining1: &'a mut [Option<T>],
|
||||
remaining2: &'a mut [Option<T>],
|
||||
nelts: uint,
|
||||
}
|
||||
|
||||
impl<'a, T> Iterator<&'a mut T> for MutItems<'a, T> {
|
||||
|
|
|
@ -21,7 +21,7 @@ use std::slice;
|
|||
|
||||
#[allow(missing_doc)]
|
||||
pub struct SmallIntMap<T> {
|
||||
priv v: ~[Option<T>],
|
||||
v: ~[Option<T>],
|
||||
}
|
||||
|
||||
impl<V> Container for SmallIntMap<V> {
|
||||
|
@ -234,9 +234,9 @@ macro_rules! double_ended_iterator {
|
|||
}
|
||||
|
||||
pub struct Entries<'a, T> {
|
||||
priv front: uint,
|
||||
priv back: uint,
|
||||
priv iter: slice::Items<'a, Option<T>>
|
||||
front: uint,
|
||||
back: uint,
|
||||
iter: slice::Items<'a, Option<T>>
|
||||
}
|
||||
|
||||
iterator!(impl Entries -> (uint, &'a T), get_ref)
|
||||
|
@ -244,9 +244,9 @@ double_ended_iterator!(impl Entries -> (uint, &'a T), get_ref)
|
|||
pub type RevEntries<'a, T> = Rev<Entries<'a, T>>;
|
||||
|
||||
pub struct MutEntries<'a, T> {
|
||||
priv front: uint,
|
||||
priv back: uint,
|
||||
priv iter: slice::MutItems<'a, Option<T>>
|
||||
front: uint,
|
||||
back: uint,
|
||||
iter: slice::MutItems<'a, Option<T>>
|
||||
}
|
||||
|
||||
iterator!(impl MutEntries -> (uint, &'a mut T), get_mut_ref)
|
||||
|
|
|
@ -36,8 +36,8 @@ use std::ptr;
|
|||
#[allow(missing_doc)]
|
||||
#[deriving(Clone)]
|
||||
pub struct TreeMap<K, V> {
|
||||
priv root: Option<~TreeNode<K, V>>,
|
||||
priv length: uint
|
||||
root: Option<~TreeNode<K, V>>,
|
||||
length: uint
|
||||
}
|
||||
|
||||
impl<K: Eq + TotalOrd, V: Eq> Eq for TreeMap<K, V> {
|
||||
|
@ -273,24 +273,24 @@ impl<K: TotalOrd, V> TreeMap<K, V> {
|
|||
|
||||
/// Lazy forward iterator over a map
|
||||
pub struct Entries<'a, K, V> {
|
||||
priv stack: ~[&'a TreeNode<K, V>],
|
||||
stack: ~[&'a TreeNode<K, V>],
|
||||
// See the comment on MutEntries; this is just to allow
|
||||
// code-sharing (for this immutable-values iterator it *could* very
|
||||
// well be Option<&'a TreeNode<K,V>>).
|
||||
priv node: *TreeNode<K, V>,
|
||||
priv remaining_min: uint,
|
||||
priv remaining_max: uint
|
||||
node: *TreeNode<K, V>,
|
||||
remaining_min: uint,
|
||||
remaining_max: uint
|
||||
}
|
||||
|
||||
/// Lazy backward iterator over a map
|
||||
pub struct RevEntries<'a, K, V> {
|
||||
priv iter: Entries<'a, K, V>,
|
||||
iter: Entries<'a, K, V>,
|
||||
}
|
||||
|
||||
/// Lazy forward iterator over a map that allows for the mutation of
|
||||
/// the values.
|
||||
pub struct MutEntries<'a, K, V> {
|
||||
priv stack: ~[&'a mut TreeNode<K, V>],
|
||||
stack: ~[&'a mut TreeNode<K, V>],
|
||||
// Unfortunately, we require some unsafe-ness to get around the
|
||||
// fact that we would be storing a reference *into* one of the
|
||||
// nodes in the stack.
|
||||
|
@ -310,14 +310,14 @@ pub struct MutEntries<'a, K, V> {
|
|||
// it under control.
|
||||
//
|
||||
// (This field can legitimately be null.)
|
||||
priv node: *mut TreeNode<K, V>,
|
||||
priv remaining_min: uint,
|
||||
priv remaining_max: uint
|
||||
node: *mut TreeNode<K, V>,
|
||||
remaining_min: uint,
|
||||
remaining_max: uint
|
||||
}
|
||||
|
||||
/// Lazy backward iterator over a map
|
||||
pub struct RevMutEntries<'a, K, V> {
|
||||
priv iter: MutEntries<'a, K, V>,
|
||||
iter: MutEntries<'a, K, V>,
|
||||
}
|
||||
|
||||
|
||||
|
@ -482,8 +482,8 @@ fn mut_deref<K, V>(x: &mut Option<~TreeNode<K, V>>) -> *mut TreeNode<K, V> {
|
|||
|
||||
/// Lazy forward iterator over a map that consumes the map while iterating
|
||||
pub struct MoveEntries<K, V> {
|
||||
priv stack: ~[TreeNode<K, V>],
|
||||
priv remaining: uint
|
||||
stack: ~[TreeNode<K, V>],
|
||||
remaining: uint
|
||||
}
|
||||
|
||||
impl<K, V> Iterator<(K, V)> for MoveEntries<K,V> {
|
||||
|
@ -551,7 +551,7 @@ impl<'a, T> Iterator<&'a T> for RevSetItems<'a, T> {
|
|||
/// `TotalOrd` trait.
|
||||
#[deriving(Clone)]
|
||||
pub struct TreeSet<T> {
|
||||
priv map: TreeMap<T, ()>
|
||||
map: TreeMap<T, ()>
|
||||
}
|
||||
|
||||
impl<T: Eq + TotalOrd> Eq for TreeSet<T> {
|
||||
|
@ -703,36 +703,36 @@ impl<T: TotalOrd> TreeSet<T> {
|
|||
|
||||
/// Lazy forward iterator over a set
|
||||
pub struct SetItems<'a, T> {
|
||||
priv iter: Entries<'a, T, ()>
|
||||
iter: Entries<'a, T, ()>
|
||||
}
|
||||
|
||||
/// Lazy backward iterator over a set
|
||||
pub struct RevSetItems<'a, T> {
|
||||
priv iter: RevEntries<'a, T, ()>
|
||||
iter: RevEntries<'a, T, ()>
|
||||
}
|
||||
|
||||
/// Lazy iterator producing elements in the set difference (in-order)
|
||||
pub struct DifferenceItems<'a, T> {
|
||||
priv a: Peekable<&'a T, SetItems<'a, T>>,
|
||||
priv b: Peekable<&'a T, SetItems<'a, T>>,
|
||||
a: Peekable<&'a T, SetItems<'a, T>>,
|
||||
b: Peekable<&'a T, SetItems<'a, T>>,
|
||||
}
|
||||
|
||||
/// Lazy iterator producing elements in the set symmetric difference (in-order)
|
||||
pub struct SymDifferenceItems<'a, T> {
|
||||
priv a: Peekable<&'a T, SetItems<'a, T>>,
|
||||
priv b: Peekable<&'a T, SetItems<'a, T>>,
|
||||
a: Peekable<&'a T, SetItems<'a, T>>,
|
||||
b: Peekable<&'a T, SetItems<'a, T>>,
|
||||
}
|
||||
|
||||
/// Lazy iterator producing elements in the set intersection (in-order)
|
||||
pub struct IntersectionItems<'a, T> {
|
||||
priv a: Peekable<&'a T, SetItems<'a, T>>,
|
||||
priv b: Peekable<&'a T, SetItems<'a, T>>,
|
||||
a: Peekable<&'a T, SetItems<'a, T>>,
|
||||
b: Peekable<&'a T, SetItems<'a, T>>,
|
||||
}
|
||||
|
||||
/// Lazy iterator producing elements in the set intersection (in-order)
|
||||
pub struct UnionItems<'a, T> {
|
||||
priv a: Peekable<&'a T, SetItems<'a, T>>,
|
||||
priv b: Peekable<&'a T, SetItems<'a, T>>,
|
||||
a: Peekable<&'a T, SetItems<'a, T>>,
|
||||
b: Peekable<&'a T, SetItems<'a, T>>,
|
||||
}
|
||||
|
||||
/// Compare `x` and `y`, but return `short` if x is None and `long` if y is None
|
||||
|
|
|
@ -30,8 +30,8 @@ enum Child<T> {
|
|||
|
||||
#[allow(missing_doc)]
|
||||
pub struct TrieMap<T> {
|
||||
priv root: TrieNode<T>,
|
||||
priv length: uint
|
||||
root: TrieNode<T>,
|
||||
length: uint
|
||||
}
|
||||
|
||||
impl<T> Container for TrieMap<T> {
|
||||
|
@ -278,7 +278,7 @@ impl<T> Extendable<(uint, T)> for TrieMap<T> {
|
|||
|
||||
#[allow(missing_doc)]
|
||||
pub struct TrieSet {
|
||||
priv map: TrieMap<()>
|
||||
map: TrieMap<()>
|
||||
}
|
||||
|
||||
impl Container for TrieSet {
|
||||
|
@ -474,19 +474,19 @@ fn remove<T>(count: &mut uint, child: &mut Child<T>, key: uint,
|
|||
|
||||
/// Forward iterator over a map
|
||||
pub struct Entries<'a, T> {
|
||||
priv stack: [slice::Items<'a, Child<T>>, .. NUM_CHUNKS],
|
||||
priv length: uint,
|
||||
priv remaining_min: uint,
|
||||
priv remaining_max: uint
|
||||
stack: [slice::Items<'a, Child<T>>, .. NUM_CHUNKS],
|
||||
length: uint,
|
||||
remaining_min: uint,
|
||||
remaining_max: uint
|
||||
}
|
||||
|
||||
/// Forward iterator over the key-value pairs of a map, with the
|
||||
/// values being mutable.
|
||||
pub struct MutEntries<'a, T> {
|
||||
priv stack: [slice::MutItems<'a, Child<T>>, .. NUM_CHUNKS],
|
||||
priv length: uint,
|
||||
priv remaining_min: uint,
|
||||
priv remaining_max: uint
|
||||
stack: [slice::MutItems<'a, Child<T>>, .. NUM_CHUNKS],
|
||||
length: uint,
|
||||
remaining_min: uint,
|
||||
remaining_max: uint
|
||||
}
|
||||
|
||||
// FIXME #5846: see `addr!` above.
|
||||
|
@ -605,7 +605,7 @@ iterator_impl! { MutEntries, iter = mut_iter, mutability = mut }
|
|||
|
||||
/// Forward iterator over a set
|
||||
pub struct SetItems<'a> {
|
||||
priv iter: Entries<'a, ()>
|
||||
iter: Entries<'a, ()>
|
||||
}
|
||||
|
||||
impl<'a> Iterator<uint> for SetItems<'a> {
|
||||
|
|
Loading…
Add table
Reference in a new issue