mightymandel v16

GPU-based Mandelbrot set explorer

ref_set.c
Go to the documentation of this file.
1 // mightymandel -- GPU-based Mandelbrot Set explorer
2 // Copyright (C) 2012,2013,2014,2015 Claude Heiland-Allen
3 // License GPL3+ http://www.gnu.org/licenses/gpl.html
4 
10 #include <stdlib.h>
11 
12 #include "logging.h"
13 #include "ref_set.h"
14 
20 struct ref_set *ref_set_new() {
21  struct ref_set *s = (struct ref_set *) calloc(1, sizeof(struct ref_set));
22  debug_message("ref_set_new s: %p\n", s);
23  return s;
24 }
25 
31 void ref_set_delete(struct ref_set *s) {
32  debug_message("ref_set_delete s: %p\n", s);
33  struct ref_set_node *node = s->set;
34  while (node) {
35  struct ref_set_node *next = node->next;
36  mpfr_clear(node->x);
37  mpfr_clear(node->y);
38  free(node);
39  node = next;
40  }
41  free(s);
42 }
43 
53 void ref_set_insert(struct ref_set *s, const mpfr_t x, const mpfr_t y) {
54  debug_message("ref_set_insert x: %Re\n", x);
55  debug_message("ref_set_insert y: %Re\n", y);
56  struct ref_set_node *node = (struct ref_set_node *) calloc(1, sizeof(struct ref_set_node));
57  node->next = s->set;
58  mpfr_init2(node->x, mpfr_get_prec(x));
59  mpfr_init2(node->y, mpfr_get_prec(y));
60  mpfr_set(node->x, x, GMP_RNDN);
61  mpfr_set(node->y, y, GMP_RNDN);
62  s->set = node;
63 }
64 
73 bool ref_set_contains(const struct ref_set *s, const mpfr_t x, const mpfr_t y) {
74  struct ref_set_node *node = s->set;
75  while (node) {
76  if (mpfr_equal_p(x, node->x) && mpfr_equal_p(y, node->y)) {
77  return true;
78  }
79  node = node->next;
80  }
81  return false;
82 }