summaryrefslogtreecommitdiff
path: root/src/prop/cryptominisat/Solver/DoublePackedRow.h
blob: cbeee2f71c810e826617cdbae6a4cc3c16bc6019 (plain)
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
168
169
170
171
172
173
/***********************************************************************************
CryptoMiniSat -- Copyright (c) 2009 Mate Soos

This program 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.

This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.
**************************************************************************************************/

#ifndef DOUBLEPACKEDROW_H
#define DOUBLEPACKEDROW_H

#ifdef _MSC_VER
#include <msvc/stdint.h>
#else
#include <stdint.h>
#endif //_MSC_VER

#include <stdlib.h>

#include "SolverTypes.h"

namespace CMSat
{
using namespace CMSat;

class DoublePackedRow
{
    private:
        class BitIter {
            public:
                inline void operator=(const lbool toSet)
                {
                    val &= ~((unsigned char)3 << offset);
                    val |= toSet.value << offset;
                }
                
                inline operator lbool() const
                {
                    return lbool((val >> offset) & 3);
                }
                
                inline const bool isUndef() const {
                    return ((lbool)*this).isUndef();
                }
                inline const bool isDef() const {
                    return ((lbool)*this).isDef();
                }
                inline const bool getBool() const {
                    return ((lbool)*this).getBool();
                }
                inline const bool operator==(lbool b) const {
                    return ((lbool)*this) == b;
                }
                inline const bool operator!=(lbool b) const {
                    return ((lbool)*this) != b;
                }
                const lbool operator^(const bool b) const {
                    return ((lbool)*this) ^ b;
                }
                
            private:
                friend class DoublePackedRow;
                inline BitIter(unsigned char& mp, const uint32_t _offset) :
                val(mp)
                , offset(_offset)
                {}
                
                unsigned char& val;
                const uint32_t offset;
        };
        
        class BitIterConst {
             public:
                inline operator lbool() const
                {
                    return lbool((val >> offset) & 3);
                }
                
                inline const bool isUndef() const {
                    return ((lbool)*this).isUndef();
                }
                inline const bool isDef() const {
                    return ((lbool)*this).isDef();
                }
                inline const bool getBool() const {
                    return ((lbool)*this).getBool();
                }
                inline const bool operator==(lbool b) const {
                    return ((lbool)*this) == b;
                }
                inline const bool operator!=(lbool b) const {
                    return ((lbool)*this) != b;
                }
                const lbool operator^(const bool b) const {
                    return ((lbool)*this) ^ b;
                }
                
                
            private:
                friend class DoublePackedRow;
                inline BitIterConst(unsigned char& mp, const uint32_t _offset) :
                val(mp)
                , offset(_offset)
                {}
                
                const unsigned char& val;
                const uint32_t offset;
        };
    
    public:
        DoublePackedRow() :
            numElems(0)
            , mp(NULL)
        {}
        
        uint32_t size() const
        {
            return numElems;
        }
        
        void growTo(const uint32_t newNumElems)
        {
            uint32_t oldSize = numElems/4 + (bool)(numElems % 4);
            uint32_t newSize = newNumElems/4 + (bool)(newNumElems % 4);
            
            if (oldSize >= newSize) {
                numElems = std::max(newNumElems, numElems);
                return;
            }
            
            mp = (unsigned char*)realloc(mp, newSize*sizeof(unsigned char));
            numElems = newNumElems;
        }
        
        inline BitIter operator[](const uint32_t at)
        {
            return BitIter(mp[at/4], (at%4)*2);
        }
        
        inline const BitIterConst operator[](const uint32_t at) const
        {
            return BitIterConst(mp[at/4], (at%4)*2);
        }
        
        inline void push(const lbool val)
        {
            growTo(numElems+1);
            (*this)[numElems-1] = val;
        }
        
        /*void clear(const uint32_t at)
        {
            mp[at/32] &= ~((uint64_t)3 << ((at%32)*2));
        }*/
        
    private:
        
        Var numElems;
        unsigned char *mp;
};

}; //NAMESPACE MINISAT

#endif //DOUBLEPACKEDROW_H
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback