-
-
Notifications
You must be signed in to change notification settings - Fork 15k
Expand file tree
/
Copy pathpretty-std-collections.rs
More file actions
178 lines (130 loc) · 6.23 KB
/
pretty-std-collections.rs
File metadata and controls
178 lines (130 loc) · 6.23 KB
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
//@ ignore-android: FIXME(#10381)
//@ ignore-windows-gnu: #128981
//@ compile-flags:-g
// === GDB TESTS ===================================================================================
// gdb-command: run
// gdb-command: print btree_set
// gdb-check:$1 = BTreeSet(size=15) = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}
// gdb-command: print empty_btree_set
// gdb-check:$2 = BTreeSet(size=0)
// gdb-command: print btree_map
// gdb-check:$3 = BTreeMap(size=15) = {[0] = 0, [1] = 1, [2] = 2, [3] = 3, [4] = 4, [5] = 5, [6] = 6, [7] = 7, [8] = 8, [9] = 9, [10] = 10, [11] = 11, [12] = 12, [13] = 13, [14] = 14}
// gdb-command: print empty_btree_map
// gdb-check:$4 = BTreeMap(size=0)
// gdb-command: print option_btree_map
// gdb-check:$5 = BTreeMap(size=2) = {[false] = [...], [true] = [...]}
// (abbreviated because both values vary wildly over gdb versions and/or linux distributions)
// gdb-command: print nasty_btree_map
// gdb-check:$6 = BTreeMap(size=15) = {[0] = pretty_std_collections::MyLeafNode (0), [...]}
// (abbreviated because it's boring but we need enough elements to include internal nodes)
// gdb-command: print zst_key_btree_map
// gdb-check:$7 = BTreeMap(size=1) = {[()] = 1}
// gdb-command: print zst_val_btree_map
// gdb-check:$8 = BTreeMap(size=1) = {[1] = ()}
// gdb-command: print zst_key_val_btree_map
// gdb-check:$9 = BTreeMap(size=1) = {[()] = ()}
// gdb-command: print vec_deque
// gdb-check:$10 = VecDeque(size=3) = {5, 3, 7}
// gdb-command: print vec_deque2
// gdb-check:$11 = VecDeque(size=7) = {2, 3, 4, 5, 6, 7, 8}
// gdb-command: print hash_map
// gdb-check:$12 = HashMap(size=4) = {[1] = 10, [2] = 20, [3] = 30, [4] = 40}
// gdb-command: print hash_set
// gdb-check:$13 = HashSet(size=4) = {1, 2, 3, 4}
// === LLDB TESTS ==================================================================================
// lldb-command:run
// lldb-command: v btree_set
// lldb-check:[...] size=15 { [0] = 0 [1] = 1 [2] = 2 [3] = 3 [4] = 4 [5] = 5 [6] = 6 [7] = 7 [8] = 8 [9] = 9 [10] = 10 [11] = 11 [12] = 12 [13] = 13 [14] = 14 }
// lldb-command: v empty_btree_set
// lldb-check:[...] size=0
// lldb-command: v btree_map
// lldb-check:[...] size=15 { [0] = { 0 = 0 1 = 0 } [1] = { 0 = 1 1 = 1 } [2] = { 0 = 2 1 = 2 } [3] = { 0 = 3 1 = 3 } [4] = { 0 = 4 1 = 4 } [5] = { 0 = 5 1 = 5 } [6] = { 0 = 6 1 = 6 } [7] = { 0 = 7 1 = 7 } [8] = { 0 = 8 1 = 8 } [9] = { 0 = 9 1 = 9 } [10] = { 0 = 10 1 = 10 } [11] = { 0 = 11 1 = 11 } [12] = { 0 = 12 1 = 12 } [13] = { 0 = 13 1 = 13 } [14] = { 0 = 14 1 = 14 } }
// lldb-command: v option_btree_map
// lldb-check:[...] size=2 { [0] = { 0 = false 1 = [...] } [1] = { 0 = true 1 = [...]
// (The matching here is lazy, so we cannot add braces at the end because they would match
// intermediate braces and fail because not the entire input was consumed.)
// lldb-command: v nasty_btree_map
// lldb-check:[...] size=15 { [0] = { 0 = 0 1 = { 0 = 0 } } [1] = { 0 = 1 1 = { 0 = 1 } } [2] = { 0 = 2 1 = { 0 = 2 } } [3] = { 0 = 3 1 = { 0 = 3 } } [4] = { 0 = 4 1 = { 0 = 4 } } [5] = { 0 = 5 1 = { 0 = 5 } } [6] = { 0 = 6 1 = { 0 = 6 } } [7] = { 0 = 7 1 = { 0 = 7 } } [8] = { 0 = 8 1 = { 0 = 8 } } [9] = { 0 = 9 1 = { 0 = 9 } } [10] = { 0 = 10 1 = { 0 = 10 } } [11] = { 0 = 11 1 = { 0 = 11 } } [12] = { 0 = 12 1 = { 0 = 12 } } [13] = { 0 = 13 1 = { 0 = 13 } } [14] = { 0 = 14 1 = { 0 = 14 } } }
// (Does not print out the type name in lldb)
// lldb-command: v zst_key_btree_map
// lldb-check:[...] size=1 { [0] = { 1 = 1 } }
// lldb-command: v zst_val_btree_map
// lldb-check:[...] size=1 { [0] = { 0 = 1 } }
// lldb-command: v zst_key_val_btree_map
// lldb-check:[...] size=1 { [0] = {} }
// lldb-command:v vec_deque
// lldb-check:[...] size=3 { [0] = 5 [1] = 3 [2] = 7 }
// lldb-command:v vec_deque2
// lldb-check:[...] size=7 { [0] = 2 [1] = 3 [2] = 4 [3] = 5 [4] = 6 [5] = 7 [6] = 8 }
// lldb-command:v hash_map
// lldb-check:[...] size=4 { [0] = { 0 = 1 1 = 10 } [1] = { 0 = 2 1 = 20 } [2] = { 0 = 3 1 = 30 } [3] = { 0 = 4 1 = 40 } }
// lldb-command:v hash_set
// lldb-check:[...] size=4 { [0] = 1 [1] = 2 [2] = 3 [3] = 4 }
#![allow(unused_variables)]
use std::collections::BTreeMap;
use std::collections::BTreeSet;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;
use std::hash::{BuildHasherDefault, Hasher};
struct MyLeafNode(i32); // helps to ensure we don't blindly replace substring "LeafNode"
#[derive(Default)]
struct SimpleHasher { hash: u64 }
impl Hasher for SimpleHasher {
fn finish(&self) -> u64 { self.hash }
fn write(&mut self, bytes: &[u8]) {}
fn write_u64(&mut self, i: u64) { self.hash = i }
}
fn main() {
// BTreeSet
let mut btree_set = BTreeSet::new();
for i in 0..15 {
btree_set.insert(i);
}
let empty_btree_set: BTreeSet<i32> = BTreeSet::new();
// BTreeMap
let mut btree_map = BTreeMap::new();
for i in 0..15 {
btree_map.insert(i, i);
}
let empty_btree_map: BTreeMap<i32, u32> = BTreeMap::new();
let mut option_btree_map: BTreeMap<bool, Option<bool>> = BTreeMap::new();
option_btree_map.insert(false, None);
option_btree_map.insert(true, Some(true));
let mut nasty_btree_map: BTreeMap<i32, MyLeafNode> = BTreeMap::new();
for i in 0..15 {
nasty_btree_map.insert(i, MyLeafNode(i));
}
let mut zst_key_btree_map: BTreeMap<(), i32> = BTreeMap::new();
zst_key_btree_map.insert((), 1);
let mut zst_val_btree_map: BTreeMap<i32, ()> = BTreeMap::new();
zst_val_btree_map.insert(1, ());
let mut zst_key_val_btree_map: BTreeMap<(), ()> = BTreeMap::new();
zst_key_val_btree_map.insert((), ());
// VecDeque
let mut vec_deque = VecDeque::new();
vec_deque.push_back(5);
vec_deque.push_back(3);
vec_deque.push_back(7);
// VecDeque where an element was popped.
let mut vec_deque2 = VecDeque::new();
for i in 1..8 {
vec_deque2.push_back(i)
}
vec_deque2.pop_front();
vec_deque2.push_back(8);
// HashMap
let mut hash_map = HashMap::<u64, u64, BuildHasherDefault<SimpleHasher>>::default();
for i in 1..5 {
hash_map.insert(i, i * 10);
}
// HashSet
let mut hash_set = HashSet::<u64, BuildHasherDefault<SimpleHasher>>::default();
for i in 1..5 {
hash_set.insert(i);
}
zzz(); // #break
}
fn zzz() {
()
}