1use crate :: *;
10#[ allow( unused ) ]
11use collection_tools ::BinaryHeap;
12
13impl< E > Collection for BinaryHeap< E >
14{
15 type Entry = E;
16 type Val = E;
17
18 #[ inline( always ) ]
19 fn entry_to_val(e: Self ::Entry) -> Self ::Val
20 {
21 e
22 }
23}
24
25impl< E > CollectionAdd for BinaryHeap< E >
26where
27 E: Ord,
28{
29 #[ inline( always ) ]
30 fn add(&mut self, e: Self ::Entry) -> bool
31 {
32 self.push(e);
33 true
34 }
35}
36
37impl< E > CollectionAssign for BinaryHeap< E >
38where
39 E: Ord,
40{
41 #[ inline( always ) ]
42 fn assign< Elements >(&mut self, elements: Elements) -> usize
43 where
44 Elements: IntoIterator< Item = Self ::Entry >,
45 {
46 let initial_len = self.len();
47 self.extend(elements);
48 self.len() - initial_len
49 }
50}
51
52impl< E > CollectionValToEntry< E > for BinaryHeap< E >
53{
54 type Entry = E;
55 #[ inline( always ) ]
56 fn val_to_entry(val: E) -> Self ::Entry
57 {
58 val
59 }
60}
61
62impl< E > Storage for BinaryHeap< E >
65where
66 E: Ord,
67{
68 type Preformed = BinaryHeap< E >;
69}
70
71impl< E > StoragePreform for BinaryHeap< E >
72where
73 E: Ord,
74{
75 fn preform(self) -> Self ::Preformed
76 {
77 self
78 }
79}
80
81#[ derive( Debug, Default ) ]
95pub struct BinaryHeapDefinition< E, Context, Formed, End >
96where
97 E: Ord,
98 End: FormingEnd< BinaryHeapDefinitionTypes<E, Context, Formed >>,
99{
100 _phantom: core ::marker ::PhantomData< (E, Context, Formed, End) >,
101}
102
103impl< E, Context, Formed, End > FormerDefinition for BinaryHeapDefinition< E, Context, Formed, End >
104where
105 E: Ord,
106 End: FormingEnd< BinaryHeapDefinitionTypes<E, Context, Formed >>,
107{
108 type Storage = BinaryHeap< E >;
109 type Context = Context;
110 type Formed = Formed;
111
112 type Types = BinaryHeapDefinitionTypes< E, Context, Formed >;
113 type End = End;
114}
115
116#[ derive( Debug, Default ) ]
129pub struct BinaryHeapDefinitionTypes< E, Context = (), Formed = BinaryHeap<E >>
130{
131 _phantom: core ::marker ::PhantomData< (E, Context, Formed) >,
132}
133
134impl< E, Context, Formed > FormerDefinitionTypes for BinaryHeapDefinitionTypes< E, Context, Formed >
135where
136 E: Ord,
137{
138 type Storage = BinaryHeap< E >;
139 type Context = Context;
140 type Formed = Formed;
141}
142
143impl< E, Context, Formed > FormerMutator for BinaryHeapDefinitionTypes< E, Context, Formed > where E: Ord {}
146
147impl< E, Definition > EntityToFormer< Definition > for BinaryHeap< E >
150where
151 E: Ord,
152 Definition: FormerDefinition<
153 Storage = BinaryHeap< E >,
154 Types = BinaryHeapDefinitionTypes<
155 E,
156 < Definition as definition ::FormerDefinition > ::Context,
157 < Definition as definition ::FormerDefinition > ::Formed,
158 >,
159 >,
160 Definition ::End: forming ::FormingEnd< Definition ::Types >,
161{
162 type Former = BinaryHeapFormer< E, Definition ::Context, Definition ::Formed, Definition ::End >;
163}
164
165impl< E > crate ::EntityToStorage for BinaryHeap< E >
166{
167 type Storage = BinaryHeap< E >;
168}
169
170impl< E, Context, Formed, End > crate ::EntityToDefinition< Context, Formed, End > for BinaryHeap< E >
171where
172 E: Ord,
173 End: crate ::FormingEnd< BinaryHeapDefinitionTypes<E, Context, Formed >>,
174{
175 type Definition = BinaryHeapDefinition< E, Context, Formed, End >;
176 type Types = BinaryHeapDefinitionTypes< E, Context, Formed >;
177}
178
179impl< E, Context, Formed > crate ::EntityToDefinitionTypes< Context, Formed > for BinaryHeap< E >
180where
181 E: Ord,
182{
183 type Types = BinaryHeapDefinitionTypes< E, Context, Formed >;
184}
185
186pub type BinaryHeapFormer< E, Context, Formed, End > = CollectionFormer< E, BinaryHeapDefinition<E, Context, Formed, End >>;
200
201pub trait BinaryHeapExt< E > : sealed ::Sealed
211where
212 E: Ord,
213{
214 fn former() -> BinaryHeapFormer< E, (), BinaryHeap<E >, ReturnStorage>;
216}
217
218impl< E > BinaryHeapExt< E > for BinaryHeap< E >
219where
220 E: Ord,
221{
222 #[ allow( clippy ::default_constructed_unit_structs ) ]
223 fn former() -> BinaryHeapFormer< E, (), BinaryHeap<E >, ReturnStorage>
224 {
225 BinaryHeapFormer :: < E, (), BinaryHeap<E >, ReturnStorage> ::new(ReturnStorage ::default())
226 }
227}
228
229mod sealed
230{
231 pub trait Sealed {}
232 impl< E > Sealed for super ::BinaryHeap< E > {}
233}