summaryrefslogtreecommitdiff
path: root/lib/ising.h
diff options
context:
space:
mode:
authorJaron Kent-Dobias <jaron@kent-dobias.com>2018-07-26 00:32:38 -0400
committerJaron Kent-Dobias <jaron@kent-dobias.com>2018-07-26 00:32:38 -0400
commitd3b3e39a525d0c3aa9663f824ba96e0c429a8313 (patch)
tree942a902af332a532ab76fccbdb51c83e98338d5e /lib/ising.h
parent225905d1ad11a0f10d63ab0c6c71e6a5265e0894 (diff)
downloadc++-d3b3e39a525d0c3aa9663f824ba96e0c429a8313.tar.gz
c++-d3b3e39a525d0c3aa9663f824ba96e0c429a8313.tar.bz2
c++-d3b3e39a525d0c3aa9663f824ba96e0c429a8313.zip
partially class-ified, ising and On work but potts and height do not
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) {