1 | // Copyright 2023 Brian Smith. |
2 | // |
3 | // Permission to use, copy, modify, and/or distribute this software for any |
4 | // purpose with or without fee is hereby granted, provided that the above |
5 | // copyright notice and this permission notice appear in all copies. |
6 | // |
7 | // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES |
8 | // WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
9 | // MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY |
10 | // SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
11 | // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION |
12 | // OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
13 | // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
14 | |
15 | pub trait ArraySplitMap<I, O, const CN: usize, const ON: usize> { |
16 | fn array_split_map(self, f: impl Fn([I; CN]) -> O) -> [O; ON]; |
17 | } |
18 | |
19 | impl<I, O> ArraySplitMap<I, O, 4, 3> for [I; 12] { |
20 | #[inline ] |
21 | fn array_split_map(self, f: impl Fn([I; 4]) -> O) -> [O; 3] { |
22 | let [a0: I, a1: I, a2: I, a3: I, b0: I, b1: I, b2: I, b3: I, c0: I, c1: I, c2: I, c3: I] = self; |
23 | [ |
24 | f([a0, a1, a2, a3]), |
25 | f([b0, b1, b2, b3]), |
26 | f([c0, c1, c2, c3]), |
27 | ] |
28 | } |
29 | } |
30 | |
31 | impl<I, O> ArraySplitMap<I, O, 4, 4> for [I; 16] { |
32 | #[inline ] |
33 | fn array_split_map(self, f: impl Fn([I; 4]) -> O) -> [O; 4] { |
34 | let [a0: I, a1: I, a2: I, a3: I, b0: I, b1: I, b2: I, b3: I, c0: I, c1: I, c2: I, c3: I, d0: I, d1: I, d2: I, d3: I] = self; |
35 | [ |
36 | f([a0, a1, a2, a3]), |
37 | f([b0, b1, b2, b3]), |
38 | f([c0, c1, c2, c3]), |
39 | f([d0, d1, d2, d3]), |
40 | ] |
41 | } |
42 | } |
43 | |
44 | impl<I, O> ArraySplitMap<I, O, 4, 8> for [I; 32] { |
45 | #[inline ] |
46 | fn array_split_map(self, f: impl Fn([I; 4]) -> O) -> [O; 8] { |
47 | let [a0: I, a1: I, a2: I, a3: I, b0: I, b1: I, b2: I, b3: I, c0: I, c1: I, c2: I, c3: I, d0: I, d1: I, d2: I, d3: I, e0: I, e1: I, e2: I, e3: I, f0: I, f1: I, f2: I, f3: I, g0: I, g1: I, g2: I, g3: I, h0: I, h1: I, h2: I, h3: I] = |
48 | self; |
49 | [ |
50 | f([a0, a1, a2, a3]), |
51 | f([b0, b1, b2, b3]), |
52 | f([c0, c1, c2, c3]), |
53 | f([d0, d1, d2, d3]), |
54 | f([e0, e1, e2, e3]), |
55 | f([f0, f1, f2, f3]), |
56 | f([g0, g1, g2, g3]), |
57 | f([h0, h1, h2, h3]), |
58 | ] |
59 | } |
60 | } |
61 | |
62 | impl<I, O> ArraySplitMap<I, O, 8, 2> for [I; 16] { |
63 | #[inline ] |
64 | fn array_split_map(self, f: impl Fn([I; 8]) -> O) -> [O; 2] { |
65 | let [a0: I, a1: I, a2: I, a3: I, a4: I, a5: I, a6: I, a7: I, b0: I, b1: I, b2: I, b3: I, b4: I, b5: I, b6: I, b7: I] = self; |
66 | [ |
67 | f([a0, a1, a2, a3, a4, a5, a6, a7]), |
68 | f([b0, b1, b2, b3, b4, b5, b6, b7]), |
69 | ] |
70 | } |
71 | } |
72 | |