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
//! Package implement Concurrent hash map.
//!
//! Quoting from [Wikipedia][pds]:
//!
//! > A data structure is *partially persistent* if all versions can be
//! > accessed but only the newest version can be modified. The data
//! > structure is *fully persistent* if every version can be both accessed
//! > and modified. If there is also a meld or merge operation that can
//! > create a new version from two previous versions, the data structure is
//! > called *confluently persistent*. Structures that are not persistent are
//! > called *ephemeral* data structures.
//!
//! This implementation of hash map cannot be strictly classified into either
//! of the above definition. It supports concurrent writes, using atomic
//! ``Load``, ``Store`` and ``Cas`` operations under the hood, and _does not_
//! provide point in time snapshot for transactional operations or iterative operations.
//!
//! If point in time snapshots are needed refer to [ppom] package, that
//! implement ordered map with multi-reader concurrency and serialised writes.
//!
//! - Each entry in [Map] instance correspond to a {Key, Value} pair.
//! - Parametrised over `key-type` and `value-type`.
//! - API - set(), get(), remove() using key.
//! - Uses ownership model and borrow semantics to ensure safety.
//! - Implement a custom epoch-based-garbage-collection to handle write
//! concurrency and memory optimization.
//! - No Durability guarantee.
//! - Thread safe for both concurrent writes and concurrent reads.
//!
//! Thread safety
//! -------------
//!
//! As an optimization, creation of a [Map] instance requires the application
//! to supply the level concurrency upfront. That is, if Map is going to be
//! cloned N times for the life-time of the map, then concurrency level is N.
//! Subsequently all access to the internal hash-map is serialized via atomic
//! ``Load``, ``Store`` and ``Cas`` operations.
//!
//! Ownership and Cloning
//! ---------------------
//!
//! Once Map instance is created, cloning is a cheap operation. Maps cloned
//! from the same instances share their hash-trie data structure among
//! its clones. Ownership rules adhere to rust ownership model and all access
//! require mutable reference.
//!
//! Application defined hashing
//! ===========================
//!
//! Parametrise [Map] type with ``H`` for application defined [BuildHasher].
//! This allows interesting and efficient hash-generation for application
//! specific key-set.
//!
//! This package define two off-the-self types implementing BuildHasher.
//!
//! * [U32Hasher], for applications that are going to use u32 as key type
//! and can guarantee unique keys (that is no collision guarantee).
//! * [DefaultHasher], as default hasher that internally uses google's
//! city-hash via [fasthash][fasthash] package, this might change in future
//! releases.
//!
//! [pds]: https://en.wikipedia.org/wiki/Persistent_data_structure
//! [ppom]: https://github.com/bnclabs/cmap
//! [fasthash]: https://github.com/flier/rust-fasthash
use BuildHasher;
use ;
/// Short form to compose Error values.
///
/// Here are few possible ways:
///
/// ```ignore
/// use crate::Error;
/// err_at!(ParseError, msg: format!("bad argument"));
/// ```
///
/// ```ignore
/// use crate::Error;
/// err_at!(ParseError, std::io::read(buf));
/// ```
///
/// ```ignore
/// use crate::Error;
/// err_at!(ParseError, std::fs::read(file_path), format!("read failed"));
/// ```
///
// mod entry;
pub use ;
pub use Map;
/// Error variants that can be returned by this package's API.
///
/// Each variant carries a prefix, typically identifying the
/// error location.
/// Type alias for Result return type, used by this package.
pub type Result<T> = Result;