summaryrefslogtreecommitdiff
path: root/lib/symmetric.h
diff options
context:
space:
mode:
authorJaron Kent-Dobias <jaron@kent-dobias.com>2018-07-26 13:06:54 -0400
committerJaron Kent-Dobias <jaron@kent-dobias.com>2018-07-26 13:06:54 -0400
commit870555f569bc63fecdc7c0b16e72e4e002f21c13 (patch)
tree704fc4669fa3c69af8882b10eff0e89321b3be83 /lib/symmetric.h
parent215c40813a35c4fdc0bb5f1b8fdea125b9e9d2e4 (diff)
downloadc++-870555f569bc63fecdc7c0b16e72e4e002f21c13.tar.gz
c++-870555f569bc63fecdc7c0b16e72e4e002f21c13.tar.bz2
c++-870555f569bc63fecdc7c0b16e72e4e002f21c13.zip
all the R_t have been objectified
Diffstat (limited to 'lib/symmetric.h')
-rw-r--r--lib/symmetric.h98
1 files changed, 32 insertions, 66 deletions
diff --git a/lib/symmetric.h b/lib/symmetric.h
index 41c8fb6..9e9b6e4 100644
--- a/lib/symmetric.h
+++ b/lib/symmetric.h
@@ -2,84 +2,50 @@
#pragma once
#include <stdlib.h>
+#include <array>
#include "types.h"
#include "potts.h"
template <q_t q>
-class symmetric_t {
+class symmetric_t : public std::array<q_t, q> {
public:
- q_t *perm;
-};
-
-template <q_t q>
-void init(symmetric_t<q> *p) {
- p->perm = (q_t *)malloc(q * sizeof(q_t));
-
- for (q_t i = 0; i < q; i++) {
- p->perm[i] = i;
- }
-}
-
-template <q_t q>
-void free_spin(symmetric_t<q> p) {
- free(p.perm);
-}
-template <q_t q>
-symmetric_t<q> copy(symmetric_t<q> x) {
- symmetric_t<q> x2;
- x2.perm = (q_t *)malloc(q * sizeof(q_t));
-
- for (q_t i = 0; i < q; i++) {
- x2.perm[i] = x.perm[i];
- }
-
- return x2;
-}
-
-template <q_t q>
-potts_t<q> act(symmetric_t<q> r, potts_t<q> s) {
- potts_t<q> s2;
- s2.x = r.perm[s.x];
- return s2;
-}
-
-template <q_t q>
-symmetric_t<q> act(symmetric_t<q> r1, symmetric_t<q> r2) {
- symmetric_t<q> r3;
- r3.perm = (q_t *)malloc(q * sizeof(q_t));
- for (q_t i = 0; i < q; i++) {
- r3.perm[i] = r1.perm[r2.perm[i]];
- }
-
- return r3;
-}
+ symmetric_t() {
+ for (q_t i = 0; i < q; i++) {
+ (*this)[i] = i;
+ }
+ }
-template <q_t q>
-potts_t<q> act_inverse(symmetric_t<q> r, potts_t<q> s) {
- potts_t<q> s2;
+ potts_t<q> act(const potts_t<q> &s) const {
+ return potts_t<q>((*this)[s.x]);
+ }
- q_t i;
+ symmetric_t<q> act(const symmetric_t<q>& r) const {
+ symmetric_t<q> r_rot;
+ for (q_t i = 0; i < q; i++) {
+ r_rot[i] = (*this)[r[i]];
+ }
- for (i = 0; i < q; i++) {
- if (r.perm[i] == s.x) {
- break;
+ return r_rot;
}
- }
- s2.x = i;
+ potts_t<q> act_inverse(const potts_t<q>& s) const {
+ for (q_t i = 0; i < q; i++) {
+ if ((*this)[i] == s.x) {
+ return potts_t<q>(i);
+ }
+ }
- return s2;
-}
+ exit(EXIT_FAILURE);
+ }
-template <q_t q>
-symmetric_t<q> act_inverse(symmetric_t<q> r1, symmetric_t<q> r2) {
- symmetric_t<q> r3;
- r3.perm = (q_t *)malloc(q * sizeof(q_t));
- for (q_t i = 0; i < q; i++) {
- r3.perm[r1.perm[i]] = r2.perm[i];
- }
+ symmetric_t<q> act_inverse(const symmetric_t<q>& r) const {
+ symmetric_t<q> r_rot;
+ for (q_t i = 0; i < q; i++) {
+ r_rot[(*this)[i]] = r[i];
+ }
- return r3;
-}
+ return r_rot;
+ }
+};