File: permutat_intern.hh

package info (click to toggle)
gap 4.15.1-1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 110,212 kB
  • sloc: ansic: 97,261; xml: 48,343; cpp: 13,946; sh: 4,900; perl: 1,650; javascript: 255; makefile: 252; ruby: 9
file content (88 lines) | stat: -rw-r--r-- 1,994 bytes parent folder | download | duplicates (4)
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
/****************************************************************************
**
**  This file is part of GAP, a system for computational discrete algebra.
**
**  Copyright of GAP belongs to its developers, whose names are too numerous
**  to list here. Please refer to the COPYRIGHT file for details.
**
**  SPDX-License-Identifier: GPL-2.0-or-later
*/

#ifndef GAP_PERMUTAT_INTERN_H
#define GAP_PERMUTAT_INTERN_H

#include "objects.h"


//
// Various helper functions for permutations
//
template <typename T>
struct T_PERM {
};
template <>
struct T_PERM<UInt2> {
    static const UInt tnum = T_PERM2;
};
template <>
struct T_PERM<UInt4> {
    static const UInt tnum = T_PERM4;
};

template <typename T>
static void ASSERT_IS_PERM(Obj perm)
{
    GAP_ASSERT(TNUM_OBJ(perm) == T_PERM<T>::tnum);
}

template <typename T>
static inline UInt SIZEBAG_PERM(UInt deg)
{
    return sizeof(Obj) + deg * sizeof(T);
}

template <typename T>
static inline Obj NEW_PERM(UInt deg)
{
    return NewBag(T_PERM<T>::tnum, SIZEBAG_PERM<T>(deg));
}

template <typename T>
static inline UInt DEG_PERM(Obj perm)
{
    ASSERT_IS_PERM<T>(perm);
    return (SIZE_OBJ(perm) - sizeof(Obj)) / sizeof(T);
}

template <typename T>
static inline T * ADDR_PERM(Obj perm)
{
    ASSERT_IS_PERM<T>(perm);
    return (T *)(ADDR_OBJ(perm) + 1);
}

template <typename T>
static inline const T * CONST_ADDR_PERM(Obj perm)
{
    ASSERT_IS_PERM<T>(perm);
    return (const T *)(CONST_ADDR_OBJ(perm) + 1);
}


//
// The 'ResultType' template is used by functions which take two permutations,
// partial permutations or transformations as arguments to select the size of
// the output they produce: by default, entries are stored  as UInt4. But if
// both inputs are T_PERM2, T_PPERM2 resp. T_TRANS2,, then as a special case
// the output entries are stored as UInt2.
//
template <typename TL, typename TR>
struct ResultType {
    typedef UInt4 type;
};
template <>
struct ResultType<UInt2, UInt2> {
    typedef UInt2 type;
};

#endif