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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
/*!
This crate implements various [CqlType](https://docs.rs/cql_model/0.2/cql_model/trait.CqlType.html) derivatives for storing `u64` values in a CQL database.
Will allocate 8 bytes per value [linked](https://docs.rs/cql_db/0.2/cql_db/fn.link_dimensions.html).
# Benchmarks
Benchmarks supplied below are fairly rudimentary (and rounded) and are there to give a rough idea of relative costs.
Full benchmark code can be found in [github](https://github.com/AndrewSisley/CQLDb/tree/master/cql_storage_types/cql_u64) and can be run with
`rustup run nightly cargo bench`.
Operation | Database dimensions | Mean time _unchecked (ns) | Mean time (ns)
--- | --- | --- | ---
Single point read | 1 | 2 450 (+/- 300) | 7 500 (+/- 600)
Single point read | 4 | 14 850 (+/- 1 000) | 37 550 (+/- 2 300)
Single point write | 1 | 2 800 (+/- 400) | 7 700 (+/- 400)
Single point write | 4 | 15 400 (+/- 2 500) | 37 700 (+/- 3 000)
Stream read 1 point | 1 | 2 500 (+/- 300) | 10 000 (+/- 850)
Stream read 1 point | 4 | 14 900 (+/- 600) | 42 500 (+/- 6 500)
Stream read 50 000 points | 1 | 27 650 000 (+/- 31 000) | 27 630 000 (+/- 180 000)
Stream read 50 000 points | 4 | 27 660 000 (+/- 1 200 000) | 27 620 000 (+/- 480 000)
# Examples
The following creates a 1D database, writes 2 values to it, and then streams them into an array.
```
# use std::io::{ Cursor, SeekFrom, Seek };
# use cql_u64::{ U64, unpack_stream };
#
# const DATABASE_LOCATION: &str = "./.test_db";
const N_VALUES_TO_READ: usize = 3;
# use std::error::Error;
# use std::fs::remove_file;
# fn main() -> Result<(), Box<dyn Error>> {
# let _ = remove_file(format!("{}{}", DATABASE_LOCATION, "/db"));
# let _ = remove_file(format!("{}{}", DATABASE_LOCATION, "/ax"));
let base_point = [1];
let value1 = 1;
let value3 = 5;
cql_db::create_db::<U64>(
DATABASE_LOCATION,
&[3]
)?;
cql_db::write_value::<U64>(
DATABASE_LOCATION,
&base_point,
value1
)?;
cql_db::write_value::<U64>(
DATABASE_LOCATION,
&[base_point[0] + 2],
value3
)?;
let mut result = [0; N_VALUES_TO_READ];
let mut stream = Cursor::new(Vec::new());
cql_db::read_to_stream::<U64>(
DATABASE_LOCATION,
&mut stream,
&base_point,
N_VALUES_TO_READ as u64
)?;
stream.seek(SeekFrom::Start(0)).unwrap();
unpack_stream(&mut stream, N_VALUES_TO_READ, |idx, value| {
result[idx] = value
})?;
assert_eq!(result[0], value1);
assert_eq!(result[1], 0);
assert_eq!(result[2], value3);
# Ok(())
# }
```
*/
use ;
use io;
use ;
use ;
use ;
/// Static struct for declaring that you want to work with `u64` values in a CQL database.
///
/// Stateless - used for type information only.
;
/// Unpacks `n_values` of u64 from a stream, calling `value_handler` with each value and it's index.
///
/// # Errors
///
/// Will return any [I/O errors](https://doc.rust-lang.org/nightly/std/io/enum.ErrorKind.html) encountered during the execution of the function. If an error
/// is returned, it may be that values have already been fed into the `value_handler`.
///
/// # Panics
///
/// Function does not actively defend against panics, and may do so if given invalid parameters. If the function panics it may be that values have
/// already been fed into the `value_handler`.
///
/// # Examples
///
/// ```ignore
/// cql_db::read_to_stream::<U64>(
/// DATABASE_LOCATION,
/// &mut stream,
/// &base_point,
/// N_VALUES_TO_READ as u64
/// )?;
///
/// stream.seek(SeekFrom::Start(0));
///
/// unpack_stream(&mut stream, N_VALUES_TO_READ, |idx, value| {
/// result[idx] = value
/// })?;
/// ```