1 /****************************************************************************
2 **
3 ** This file is part of GAP, a system for computational discrete algebra.
4 **
5 ** Copyright of GAP belongs to its developers, whose names are too numerous
6 ** to list here. Please refer to the COPYRIGHT file for details.
7 **
8 ** SPDX-License-Identifier: GPL-2.0-or-later
9 */
10
11 #ifndef GAP_PERMUTAT_INTERN_H
12 #define GAP_PERMUTAT_INTERN_H
13
14 #include "objects.h"
15
16
17 //
18 // Various helper functions for permutations
19 //
20 template <typename T>
21 struct T_PERM {
22 };
23 template <>
24 struct T_PERM<UInt2> {
25 static const UInt tnum = T_PERM2;
26 };
27 template <>
28 struct T_PERM<UInt4> {
29 static const UInt tnum = T_PERM4;
30 };
31
32 template <typename T>
ASSERT_IS_PERM(Obj perm)33 static void ASSERT_IS_PERM(Obj perm)
34 {
35 GAP_ASSERT(TNUM_OBJ(perm) == T_PERM<T>::tnum);
36 }
37
38 template <typename T>
SIZEBAG_PERM(UInt deg)39 static inline UInt SIZEBAG_PERM(UInt deg)
40 {
41 return sizeof(Obj) + deg * sizeof(T);
42 }
43
44 template <typename T>
NEW_PERM(UInt deg)45 static inline Obj NEW_PERM(UInt deg)
46 {
47 return NewBag(T_PERM<T>::tnum, SIZEBAG_PERM<T>(deg));
48 }
49
50 template <typename T>
DEG_PERM(Obj perm)51 static inline UInt DEG_PERM(Obj perm)
52 {
53 ASSERT_IS_PERM<T>(perm);
54 return (SIZE_OBJ(perm) - sizeof(Obj)) / sizeof(T);
55 }
56
57 template <typename T>
ADDR_PERM(Obj perm)58 static inline T * ADDR_PERM(Obj perm)
59 {
60 ASSERT_IS_PERM<T>(perm);
61 return (T *)(ADDR_OBJ(perm) + 1);
62 }
63
64 template <typename T>
CONST_ADDR_PERM(Obj perm)65 static inline const T * CONST_ADDR_PERM(Obj perm)
66 {
67 ASSERT_IS_PERM<T>(perm);
68 return (const T *)(CONST_ADDR_OBJ(perm) + 1);
69 }
70
71
72 //
73 // The 'ResultType' template is used by functions which take two permutations,
74 // partial permutations or transformations as arguments to select the size of
75 // the output they produce: by default, entries are stored as UInt4. But if
76 // both inputs are T_PERM2, T_PPERM2 resp. T_TRANS2,, then as a special case
77 // the output entries are stored as UInt2.
78 //
79 template <typename TL, typename TR>
80 struct ResultType {
81 typedef UInt4 type;
82 };
83 template <>
84 struct ResultType<UInt2, UInt2> {
85 typedef UInt2 type;
86 };
87
88 #endif
89