summaryrefslogtreecommitdiff
path: root/lib/ising.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/ising.h')
-rw-r--r--lib/ising.h65
1 files changed, 28 insertions, 37 deletions
diff --git a/lib/ising.h b/lib/ising.h
index f08ae58..5932ecf 100644
--- a/lib/ising.h
+++ b/lib/ising.h
@@ -31,58 +31,49 @@ class ising_t {
typedef int M_t;
typedef double F_t;
-};
-void init(ising_t *p) {
- p->x = false;
-}
+ ising_t() {
+ x = false;
+ }
-void free_spin(ising_t s) {
- // do nothing!
-}
+ ising_t(bool x) : x(x) {}
-void free_spin(int s) {
- // do nothing
-}
+ inline int operator*(v_t a) const {
+ if (x) {
+ return -(int)a;
+ } else {
+ return (int)a;
+ }
+ }
-void free_spin(double s) {
- // do nothing
-}
+ inline double operator*(double a) const {
+ if (x) {
+ return -a;
+ } else {
+ return a;
+ }
+ }
-ising_t copy(ising_t s) {
- return s;
-}
+};
-void add(int *s1, int a, ising_t s2) {
- if (s2.x) {
- *s1 -= a;
+inline int& operator+=(int& M, const ising_t &s) {
+ if (s.x) {
+ M--;
} else {
- *s1 += a;
+ M++;
}
-}
-void add(double *s1, double a, ising_t s2) {
- if (s2.x) {
- *s1 -= a;
- } else {
- *s1 += a;
- }
+ return M;
}
-int scalar_multiple(int factor, ising_t s) {
+inline int& operator-=(int& M, const ising_t &s) {
if (s.x) {
- return -factor;
+ M++;
} else {
- return factor;
+ M--;
}
-}
-double scalar_multiple(double factor, ising_t s) {
- if (s.x) {
- return -factor;
- } else {
- return factor;
- }
+ return M;
}
double norm_squared(double s) {