11use std:: borrow:: Borrow ;
22
3- /// MarkMap is a key value data structure that uses an API similar to that of
4- /// `std::collections::HashMap` and `std::collections::BTreeMap`.
5- ///
6- /// The current implementation is based on a sorted `Vec` is not optimized for
7- /// storing large number of items.
8- ///
9- /// On top of the familiar `std::collections` API it has a few additions:
10- ///
11- /// * Marking a key with a condition.
12- /// * Marking a key with a merge behavior.
13- /// * A merge operator.
14- ///
15- /// The current *conditions* are [`Used`](MarkMap::mark_used) and [`Required`](MarkMap::mark_required).
16- ///
17- /// The available merge behaviors are [`Theirs`](MergeBehavior::Theirs), [`Ours`](MergeBehavior::Ours),
18- /// and [`MutuallyExclusive`](MergeBehavior::MutuallyExclusive).
19- ///
20- /// Merge behaviors configure how the merge operator handles cases where both `MarkMaps` being merged
21- /// contain a particular key.
3+ // MarkMap is a key value data structure that uses an API similar to that of
4+ // `std::collections::HashMap` and `std::collections::BTreeMap`.
5+ //
6+ // The current implementation is based on a sorted `Vec` is not optimized for
7+ // storing large number of items.
8+ //
9+ // On top of the familiar `std::collections` API it has a few additions:
10+ //
11+ // * Marking a key with a condition.
12+ // * Marking a key with a merge behavior.
13+ // * A merge operator.
14+ //
15+ // The current *conditions* are [`Used`](MarkMap::mark_used) and [`Required`](MarkMap::mark_required).
16+ //
17+ // The available merge behaviors are [`Theirs`](MergeBehavior::Theirs), [`Ours`](MergeBehavior::Ours),
18+ // and [`MutuallyExclusive`](MergeBehavior::MutuallyExclusive).
19+ //
20+ // Merge behaviors configure how the merge operator handles cases where both `MarkMaps` being merged
21+ // contain a particular key.
2222#[ derive( Debug , PartialEq , Eq ) ]
2323pub struct MarkMap < K , V > {
2424 contents : Vec < ( K , u16 , Option < V > ) > ,
@@ -27,6 +27,7 @@ pub struct MarkMap<K, V> {
2727/// Defines the merge behavior for a single key in the markmap.
2828#[ repr( u8 ) ]
2929#[ derive( Clone , Copy ) ]
30+ #[ doc( hidden) ]
3031pub enum MergeBehavior {
3132 /// The value in `self` takes precedence.
3233 Theirs = 1 << 0 ,
@@ -40,19 +41,22 @@ pub enum MergeBehavior {
4041/// Conflicting values were present while merging, and the
4142/// merge behavior did not specify a means to resolve them.
4243#[ derive( Debug ) ]
44+ #[ doc( hidden) ]
4345pub enum MergeError < K , V > {
4446 // Contains the key which was present in both, and the value which was present in `Theirs`.
4547 Exclusivity ( K , V ) ,
4648}
4749
4850/// A view into a single entry in a `MarkMap`, which may either be vacant or occupied.
51+ #[ doc( hidden) ]
4952pub enum Entry < ' a , K , V > {
5053 Occupied ( OccupiedEntry < ' a , K , V > ) ,
5154 Vacant ( VacantEntry < ' a , K , V > ) ,
5255}
5356
5457#[ repr( u8 ) ]
5558#[ derive( Clone , Copy ) ]
59+ #[ doc( hidden) ]
5660enum Mark {
5761 // There are some other interesting marks that could be added based on row polymorphic records.
5862 // Marks such as `Prohibited` could be used to prove disjointedness.
@@ -179,12 +183,14 @@ impl<K: Ord, V> OccupiedEntry<'_, K, V> {
179183}
180184
181185/// A view into an occupied entry in a `MarkMap`. It is part of the `Entry` enum.
186+ #[ doc( hidden) ]
182187pub struct OccupiedEntry < ' a , K , V > {
183188 pos : usize ,
184189 map : & ' a mut MarkMap < K , V > ,
185190}
186191
187192/// A view into a vacant entry in a `MarkMap`. It is part of the `Entry` enum.
193+ #[ doc( hidden) ]
188194pub struct VacantEntry < ' a , K , V > {
189195 pos : Result < usize , usize > ,
190196 key : K ,
@@ -199,6 +205,7 @@ impl<K: Ord + Clone, V> MarkMap<K, V> {
199205 }
200206
201207 /// Inserts a `key` `value` pair.
208+ #[ doc( hidden) ]
202209 pub fn insert ( & mut self , key : K , val : V ) -> Option < V > {
203210 let pos = self . contents . binary_search_by ( |( k, _, _) | k. cmp ( & key) ) ;
204211 match pos {
@@ -225,6 +232,7 @@ impl<K: Ord + Clone, V> MarkMap<K, V> {
225232 }
226233
227234 /// Marks `key` as used.
235+ #[ doc( hidden) ]
228236 pub fn mark_used ( & mut self , key : & K ) {
229237 let pos = self . contents . binary_search_by ( |( k, _, _) | k. cmp ( key) ) ;
230238 match pos {
@@ -241,6 +249,7 @@ impl<K: Ord + Clone, V> MarkMap<K, V> {
241249 }
242250
243251 /// Marks `key` as a required value.
252+ #[ doc( hidden) ]
244253 pub fn mark_required ( & mut self , key : & K ) {
245254 let pos = self . contents . binary_search_by ( |( k, _, _) | k. cmp ( key) ) ;
246255 match pos {
@@ -257,6 +266,7 @@ impl<K: Ord + Clone, V> MarkMap<K, V> {
257266 }
258267
259268 /// Returns whether `key` is required.
269+ #[ doc( hidden) ]
260270 pub fn is_required ( & self , key : & K ) -> bool {
261271 let pos = self . contents . binary_search_by ( |( k, _, _) | k. cmp ( key) ) ;
262272 match pos {
@@ -266,6 +276,7 @@ impl<K: Ord + Clone, V> MarkMap<K, V> {
266276 }
267277
268278 /// Sets the merge behavior for `key`.
279+ #[ doc( hidden) ]
269280 pub fn set_merge_behavior ( & mut self , key : & K , mb : MergeBehavior ) {
270281 let pos = self . contents . binary_search_by ( |( k, _, _) | k. cmp ( key) ) ;
271282 match pos {
@@ -287,6 +298,7 @@ impl<K: Ord + Clone, V> MarkMap<K, V> {
287298 }
288299
289300 /// Returns a `Some(value)` associated with `key` if present otherwise `None`.
301+ #[ doc( hidden) ]
290302 pub fn get < Q > ( & self , key : & Q ) -> Option < & V >
291303 where
292304 K : Borrow < Q > ,
@@ -303,6 +315,7 @@ impl<K: Ord + Clone, V> MarkMap<K, V> {
303315 }
304316
305317 /// Returns true if the `MarkMap` contains `key` otherwise false.
318+ #[ doc( hidden) ]
306319 pub fn contains_key < Q > ( & self , key : & Q ) -> bool
307320 where
308321 K : Borrow < Q > ,
@@ -312,6 +325,7 @@ impl<K: Ord + Clone, V> MarkMap<K, V> {
312325 }
313326
314327 /// Removes `key` from the `MarkMap` and returns the previous value when present.
328+ #[ doc( hidden) ]
315329 pub fn remove ( & mut self , key : & K ) -> Option < V > {
316330 let pos = self . contents . binary_search_by ( |( k, _, _) | k. cmp ( key) ) ;
317331 match pos {
@@ -321,6 +335,7 @@ impl<K: Ord + Clone, V> MarkMap<K, V> {
321335 }
322336
323337 /// Returns an `Entry` for `key`.
338+ #[ doc( hidden) ]
324339 pub fn entry ( & mut self , key : K ) -> Entry < K , V > {
325340 let pos = self . contents . binary_search_by ( |( k, _, _) | k. cmp ( & key) ) ;
326341 match pos {
@@ -353,6 +368,7 @@ impl<K: Ord + Clone, V> MarkMap<K, V> {
353368 ///
354369 /// For the behavior of exclusive or mark the behavior as also `Mark::Required`, then after merge call `missing()`
355370 /// to check all required values.
371+ #[ doc( hidden) ]
356372 pub fn merge_from ( & mut self , other : Self ) -> Result < ( ) , MergeError < K , Box < V > > > {
357373 for ( their_key, their_mark, their_val) in other. contents {
358374 let pos = self . contents . binary_search_by ( |x| x. 0 . cmp ( & their_key) ) ;
@@ -399,6 +415,7 @@ impl<K: Ord + Clone, V> MarkMap<K, V> {
399415 }
400416
401417 /// Returns whether `key` has been marked as used.
418+ #[ doc( hidden) ]
402419 pub fn is_used < Q > ( & self , key : & Q ) -> bool
403420 where
404421 K : Borrow < Q > ,
@@ -415,6 +432,7 @@ impl<K: Ord + Clone, V> MarkMap<K, V> {
415432 }
416433
417434 /// Returns a `Vec` containing all the keys that are not marked as used.
435+ #[ doc( hidden) ]
418436 pub fn unused ( & self ) -> Vec < K > {
419437 let mut ret = Vec :: new ( ) ;
420438 for ( k, mark, v) in & self . contents {
@@ -428,6 +446,7 @@ impl<K: Ord + Clone, V> MarkMap<K, V> {
428446
429447 /// Returns a `Vec` containing all the keys that are marked as required,
430448 /// but have values that are not present in the `MarkMap`.
449+ #[ doc( hidden) ]
431450 pub fn missing ( & self ) -> Vec < & K > {
432451 let mut ret = Vec :: new ( ) ;
433452 for ( k, mark, v) in & self . contents {
@@ -441,10 +460,12 @@ impl<K: Ord + Clone, V> MarkMap<K, V> {
441460}
442461
443462/// Iterator over the owned keys and values of a `MarkMap`.
463+ #[ doc( hidden) ]
444464pub struct MarkMapIter < K , V > {
445465 map : MarkMap < K , V > ,
446466}
447467
468+ #[ doc( hidden) ]
448469impl < K , V > Iterator for MarkMapIter < K , V > {
449470 type Item = ( K , V ) ;
450471
@@ -459,11 +480,13 @@ impl<K, V> Iterator for MarkMapIter<K, V> {
459480}
460481
461482/// Iterator over references to keys and values of a `MarkMap`.
483+ #[ doc( hidden) ]
462484pub struct MarkMapIterRef < ' a , K , V > {
463485 pos : usize ,
464486 map : & ' a MarkMap < K , V > ,
465487}
466488
489+ #[ doc( hidden) ]
467490impl < ' a , K , V > Iterator for MarkMapIterRef < ' a , K , V > {
468491 type Item = ( & ' a K , & ' a V ) ;
469492
@@ -477,6 +500,7 @@ impl<'a, K, V> Iterator for MarkMapIterRef<'a, K, V> {
477500 }
478501}
479502
503+ #[ doc( hidden) ]
480504impl < ' a , K , V > IntoIterator for & ' a MarkMap < K , V > {
481505 type Item = ( & ' a K , & ' a V ) ;
482506 type IntoIter = MarkMapIterRef < ' a , K , V > ;
0 commit comments