Fix yield bug part 2
[satcheck.git] / cgoal.cc
1 /*      Copyright (c) 2015 Regents of the University of California
2  *
3  *      Author: Brian Demsky <bdemsky@uci.edu>
4  *
5  *      This program is free software; you can redistribute it and/or
6  *      modify it under the terms of the GNU General Public License
7  *      version 2 as published by the Free Software Foundation.
8  */
9
10 #include "cgoal.h"
11 #include "execpoint.h"
12 #include "eprecord.h"
13
14 CGoal::CGoal(unsigned int _num, uint64_t *vals) :
15         outputvalue(0),
16         num(_num),
17         hash(_num)
18 {
19         valarray=(uint64_t *)model_malloc(sizeof(uint64_t)*num);
20         for(unsigned int i=0;i<num;i++) {
21                 hash^=(valarray[i]=vals[i]);
22         }
23 }
24
25 CGoal::~CGoal() {
26         if (valarray)
27                 model_free(valarray);
28 }
29
30 void CGoal::print() {
31         model_print("goal: ");
32         model_print("(");
33         for(uint i=0;i<num;i++) {
34                 model_print("%llu",valarray[i]);
35                 if ((i+1)!=num)
36                         model_print(", ");
37         }
38         model_print(")");
39 }
40
41 bool CGoalEquals(CGoal *cg1, CGoal *cg2) {
42         if (cg1==NULL) {
43                 return cg2==NULL;
44         }
45         if (cg1->hash!=cg2->hash||
46                         cg1->num!=cg2->num)
47                 return false;
48         if (cg1->valarray) {
49                 for(unsigned int i=0;i<cg1->num;i++) {
50                         if (cg1->valarray[i]!=cg2->valarray[i])
51                                 return false;
52                 }
53         }
54
55         return true;
56 }
57
58 unsigned int CGoalHash(CGoal *cg) {
59         return cg->hash;
60 }
61