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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
//! Collections which transparently compress data to reduce memory usage
//!
//! This crate offers collections which automatically compress themselves, which reduces memory usage, sometimes
//! substantially, allowing collections to be held in memory that would otherwise be too big.
//!
//! So far, a stack is implemented, which can be used as a dropin replacement for a Vec stack.
//! The only restriction on the datatypes in the collections is that they must be serde serializable.
//!
//! For instance:
//!
//! ```no_run
//! use compressed_collections::Stack;
//!
//! let mut compressed_stack = Stack::new();
//! for _ in 0..(1024 * 1024 * 100) {
//! compressed_stack.push(1);
//! }
//! ```
//!
//! This only allocates around 10MB (the default buffer size), whereas the equivalent vector would be around 100MB in size.
//!
//! Design goals:
//! - Provide collections with a subset of the API of the standard equivalent wherever possible for easy dropin use.
//! - Only implement the efficient operations for each datastructure
//!
//! Datastructures:
//! - [x] Stack
//! - [x] Deque
//! - [ ] Map
use Deserialize;
use Serialize;
pub use Deque;
pub use Stack;
/// The amount of data to buffer before compressing.
///
/// # Examples
///
///
/// This compresses every 1MB
/// ```
/// use compressed_collections::Stack;
/// use compressed_collections::ChunkSize;
///
/// let mut compressed_stack = Stack::new_with_options(ChunkSize::SizeElements(1024 * 1024 * 1), 2);
/// for _ in 0..(1024 * 1024 * 10) {
/// compressed_stack.push(1.0);
/// }
/// ```
///
/// Whereas this compresses every 100MB (so it will never actually get round to compressing)
/// ```
/// use compressed_collections::Stack;
/// use compressed_collections::ChunkSize;
///
/// let mut compressed_stack = Stack::new_with_options(ChunkSize::SizeElements(1024 * 1024 * 100), 2);
/// for _ in 0..(1024 * 1024 * 10) {
/// compressed_stack.push(1.0);
/// }
/// ```
///
/// # Low stability
/// This enum is dependent on the internal implementation, so it is likely to change frequently