From d3b3e39a525d0c3aa9663f824ba96e0c429a8313 Mon Sep 17 00:00:00 2001 From: Jaron Kent-Dobias Date: Thu, 26 Jul 2018 00:32:38 -0400 Subject: partially class-ified, ising and On work but potts and height do not --- lib/ising.h | 65 ++++++++++++++++++++++++++----------------------------------- 1 file changed, 28 insertions(+), 37 deletions(-) (limited to 'lib/ising.h') 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) { -- cgit v1.2.3-70-g09d2