1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//! `tinyset` contains a few collections that are optimized to scale
//! in size well for small numbers of elements, while still scaling
//! well in time (and size) for numbers of elements.  We have two set types:
//!
//! 1. `Set` is basically interchangeable with `HashSet`, although it
//!    does require that its elements implement the `Copy` trait,
//!    since otherwise I would have to learn to write correct `unsafe`
//!    code, which would be scary.  It uses FNV hashing when there are
//!    large numbers of elements.
//!
//! 2. `TinySet` is places a stronger requirement on its elements,
//!     which must have trait `HasInvalid`.  This is intended for
//!     elements that are `Copy`, are `Hash`, and have an "invalid"
//!     value.  For the unsigned integer types, we take their maximum
//!     value to mean invalid.  This constraint allows us to save a
//!     bit more space.
//!
//! Both of these set types will do no heap allocation for small sets
//! of small elements.  `TinySet` will store up to 16 bytes of
//! elements before doing any heap allocation, while `Set` stores sets
//! up to size 8 without allocation.  Both sets are similar in speed
//! to `fnv::HashSet`.
//!
//! # Examples
//!
//! ```
//! use tinyset::Set;
//! let mut s: Set<usize> = Set::new();
//! s.insert(1);
//! assert!(s.contains(&1));
//! ```
//!
//! ```
//! use tinyset::TinySet;
//! let mut s: TinySet<usize> = TinySet::new();
//! s.insert(1);
//! assert!(s.contains(&1));
//! ```
//!
//! ```
//! use tinyset::Set64;
//! let mut s: Set64<usize> = Set64::new();
//! s.insert(1);
//! assert!(s.contains(&1));
//! ```

#![deny(missing_docs)]

extern crate fnv;

pub mod vecset;
pub use vecset::VecSet;

pub mod set;
pub use set::Set;

pub mod tinyset;
pub use tinyset::*;

pub mod usizeset;
pub use usizeset::USizeSet;

pub mod u64set;
pub use u64set::{Set64, Fits64, U64Set};

#[cfg(test)]
extern crate rand;

#[cfg(test)]
#[macro_use]
extern crate quickcheck;