File: cl_functors.hh

package info (click to toggle)
packup 0.6-3.2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 832 kB
  • sloc: cpp: 10,857; makefile: 111; sh: 6
file content (167 lines) | stat: -rw-r--r-- 5,434 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/******************************************************************************\
 *    This file is part of packup.                                            *
 *                                                                            *
 *    packup is free software: you can redistribute it and/or modify          *
 *    it under the terms of the GNU General Public License as published by    *
 *    the Free Software Foundation, either version 3 of the License, or       *
 *    (at your option) any later version.                                     *
 *                                                                            *
 *    packup is distributed in the hope that it will be useful,               *
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of          *
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
 *    GNU General Public License for more details.                            *
 *                                                                            *
 *    You should have received a copy of the GNU General Public License       *
 *    along with packup.  If not, see <http://www.gnu.org/licenses/>.         *            
\******************************************************************************/           
//jpms:bc
/*----------------------------------------------------------------------------*\
 * File:        cl_functors.hh
 *
 * Description: Functors based on clauses.
 *
 * Author:      jpms
 * 
 * Revision:    $Id$.
 *
 *                                     Copyright (c) 2009, Joao Marques-Silva
\*----------------------------------------------------------------------------*/
//jpms:ec

#ifndef _CL_FUNCTORS_H
#define _CL_FUNCTORS_H 1

#include "basic_clause.hh"


//jpms:bc
/*----------------------------------------------------------------------------*\
 * Functors based on class BasicClause
\*----------------------------------------------------------------------------*/
//jpms:ec

class ClauseHash {
public:
  ULINT operator()(BasicClause* clref) const {  // see below new hash functions
    //return clref->clhash(); // -> Very slow; unable to undertand why
    register ULINT hashv = 0;
    for(Literator pos = clref->begin(); pos != clref->end(); ++pos) {
      hashv ^= (*pos>0) ? *pos : -*pos;
    }  cout << "Hash value: " << hashv << endl; cout.flush();
    return hashv;
  }
};
 
class ClauseEqual {
public:
  bool operator()(BasicClause* cl1, BasicClause* cl2) const {
    if (cl1->size() != cl2->size()) { return false; }
    Literator pos1 = cl1->begin();  // Vectors assumed to be sorted
    Literator pos2 = cl2->begin();
    for(; pos1 != cl1->end(); ++pos1, ++pos2) {
      if (*pos1 != *pos2) { return false; }
    }
    return true;
  }
};

class ClPtrHash {
public:
  ULINT operator()(const BasicClause* ptr) const { return (ULINT)ptr; }
};
 
class ClPtrEqual {
public:
  bool operator()(const BasicClause* ptr1, const BasicClause* ptr2) const {
    return ptr1 == ptr2;
  }
};

class ClSizeIDLess {
public:
  bool operator()(BasicClause* ptr1, BasicClause* ptr2) const {
    return
      ptr1->size() < ptr2->size() ||
      ptr1->size() == ptr2->size() && ptr1->get_id() < ptr2->get_id();
  }
};

class ClSizeIDGreater {
public:
  bool operator()(BasicClause* ptr1, BasicClause* ptr2) const {
    return
      ptr1->size() > ptr2->size() ||
      ptr1->size() == ptr2->size() && ptr1->get_id() > ptr2->get_id();
  }
};

class ClIDLess {
public:
  bool operator()(BasicClause* ptr1, BasicClause* ptr2) const
  {
    return ptr1->get_id() < ptr2->get_id();
  }
};

class ClIDGreater {
public:
  bool operator()(BasicClause* ptr1, BasicClause* ptr2) const
  {
    return ptr1->get_id() > ptr2->get_id();
  }
};


#define HPSHIFT 3
#define HNSHIFT 2

class LitVectHash {
public:
  ULINT operator()(vector<LINT>* lvect) const {
    //cout << "VECT SIZE:" << lvect->size() <<endl;
    register ULINT hashv = 0;
    //register ULINT hashv = 1;
    //cout << "Hash value: " << hashv << endl; cout.flush();
    for(vector<LINT>::iterator pos=lvect->begin(); pos!=lvect->end(); ++pos) {
      // v3:
      hashv = (hashv << HPSHIFT) ^ ((*pos>0) ? *pos : -*pos);
      /*
      // v5:
      hashv = (hashv << HPSHIFT) ^ (*pos);
      // v4:
      hashv =
      (*pos>0) ? ((hashv << HPSHIFT) ^ *pos) : ((hashv >> HNSHIFT) ^ -*pos);
      // v3:
      hashv = (hashv << HPSHIFT) ^ ((*pos>0) ? *pos : -*pos);
      // v2:
      hashv ^= ((*pos>0) ? *pos : -*pos);
      // v1:
      hashv *= fabs(*pos);
      */
    } //cout << "Hash value: " << hashv << endl; cout.flush();
    return hashv;
  }
};
 
class LitVectEqual {
public:
  bool operator()(vector<LINT>* lv1, vector<LINT>* lv2) const {
    if (lv1->size() != lv2->size()) { return false; }
    Literator pos1 = lv1->begin();  // Vectors assumed to be sorted
    Literator pos2 = lv2->begin();
    for(; pos1 != lv1->end(); ++pos1, ++pos2) {  // vectors w/ the same size
      if (*pos1 != *pos2) { return false; }
    }
    /* Not as efficient...
      for(register int k=0; k<lv1->size(); ++k) {    // vectors w/ the same size
      if ((*lv1)[k] != (*lv2)[k]) { return false; }
      } //cout<<((pos1==lv1->end()&&pos2==lv2->end())?"TRUE":"FALSE B")<<endl;
      // Also tried reverse iterators, to no avail
    */
    return true;
  }
};

#endif /* _CL_FUNCTORS_H */

/*----------------------------------------------------------------------------*/