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
use ;
use ;
use HashMap;
/// Collects entries from a stable `BTreeMap` iterator into a `Vec<(K, V)>`.
///
/// This is useful when working with `ic-stable-structures`'s `BTreeMap`
/// and you want to extract all entries as a vector of key-value pairs.
///
/// # Type Parameters
/// - `K`: The key type, which must be `Storable`, `Clone`, and `Ord`.
/// - `V`: The value type, which must be `Storable` and `Clone`.
/// - `M`: The memory backend, which must implement the `Memory` trait.
///
/// # Arguments
/// - `iter`: An iterator over the entries of a stable `BTreeMap`.
///
/// # Returns
/// A vector containing `(K, V)` pairs.
///
/// # Example (using `iter`)
/// ```
/// let vec = collect_stable_vec(my_stable_map.iter());
/// ```
///
/// # Example (using `range`)
/// ```
/// let range = my_stable_map.range(2..3);
/// let entries = collect_stable_vec(range);
/// ```
/// Collects entries from a stable `BTreeMap` iterator into a `HashMap<K, V>`.
///
/// This helper is useful when converting from a stable structure
/// (like `BTreeMap<K, V, M>`) to an in-memory `HashMap`.
///
/// # Type Parameters
/// - `K`: The key type, which must be `Storable`, `Clone`, `Ord`, `Eq`, and `Hash`.
/// - `V`: The value type, which must be `Storable` and `Clone`.
/// - `M`: The memory backend, which must implement the `Memory` trait.
///
/// # Arguments
/// - `iter`: An iterator over the entries of a stable `BTreeMap`.
///
/// # Returns
/// A `HashMap<K, V>` containing the collected entries.
///
/// # Example (using `iter`)
/// ```
/// let map = collect_stable_map(my_stable_map.iter());
/// ```
///
/// # Example (using `range`)
/// ```
/// let range = my_stable_map.range(2..3);
/// let entries = collect_stable_map(range);
/// ```
/// Collects entries from a `BTreeMap` into a `Vec<(K, V)>`.
///
/// This is a convenience wrapper over [`collect_stable_vec`] that calls `.iter()` for you.
///
/// # Type Parameters
/// - `K`: Key type (must be `Storable`, `Clone`, and `Ord`)
/// - `V`: Value type (must be `Storable` and `Clone`)
/// - `M`: Stable memory backend
///
/// # Example
/// ```ignore
/// let vec = collect_stable_vec_from(&my_stable_map);
/// ```
/// Collects entries from a `BTreeMap` into a `HashMap<K, V>`.
///
/// This is a convenience wrapper over [`collect_stable_map`] that calls `.iter()` for you.
///
/// # Type Parameters
/// - `K`: Key type (must be `Storable`, `Clone`, `Ord`, `Eq`, `Hash`)
/// - `V`: Value type (must be `Storable` and `Clone`)
/// - `M`: Stable memory backend
///
/// # Example
/// ```ignore
/// let map = collect_stable_map_from(&my_stable_map);
/// ```