tiny-bit-set.hpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 namespace Gecode { namespace Int { namespace Extensional {
00039
00040
00041
00042
00043
00044 template<unsigned int sz>
00045 forceinline
00046 TinyBitSet<sz>::TinyBitSet(Space&, unsigned int n) {
00047 assert(n <= sz);
00049 for (unsigned int i=0U; i < n; i++)
00050 bits[i].init(true);
00052 for (unsigned int i=n; i < sz; i++)
00053 bits[i].init(false);
00054 }
00055
00056 template<unsigned int sz>
00057 template<unsigned int largersz>
00058 forceinline
00059 TinyBitSet<sz>::TinyBitSet(Space&, const TinyBitSet<largersz>& sbs) {
00060 GECODE_ASSUME(sz <= largersz);
00061 assert(!sbs.empty());
00062 for (unsigned int i = sz; i--; )
00063 bits[i] = sbs.bits[i];
00064 assert(!empty());
00065 }
00066
00067 template<unsigned int sz>
00068 template<class IndexType>
00069 forceinline
00070 TinyBitSet<sz>::TinyBitSet(Space&, const BitSet<IndexType>& sbs) {
00071 assert(sz == sbs.width());
00072 assert(!sbs.empty());
00073 for (unsigned int i = sz; i--; )
00074 bits[i].init(false);
00075 for (unsigned int i = sbs.words(); i--; ) {
00076 bits[sbs.index[i]] = sbs.bits[i];
00077 }
00078 assert(!empty());
00079 }
00080
00081 template<unsigned int sz>
00082 forceinline void
00083 TinyBitSet<sz>::clear_mask(BitSetData* mask) {
00084 for (unsigned int i=sz; i--; ) {
00085 mask[i].init(false);
00086 assert(mask[i].none());
00087 }
00088 }
00089
00090 template<unsigned int sz>
00091 forceinline void
00092 TinyBitSet<sz>::add_to_mask(const BitSetData* b, BitSetData* mask) const {
00093 for (unsigned int i=sz; i--; )
00094 mask[i] = BitSetData::o(mask[i],b[i]);
00095 }
00096
00097 template<unsigned int sz>
00098 template<bool sparse>
00099 forceinline void
00100 TinyBitSet<sz>::intersect_with_mask(const BitSetData* mask) {
00101 for (unsigned int i=sz; i--; )
00102 bits[i] = BitSetData::a(bits[i], mask[i]);
00103 }
00104
00105 template<unsigned int sz>
00106 forceinline void
00107 TinyBitSet<sz>::intersect_with_masks(const BitSetData* a, const BitSetData* b) {
00108 for (unsigned int i=sz; i--; )
00109 bits[i] = BitSetData::a(bits[i], BitSetData::o(a[i],b[i]));
00110 }
00111
00112 template<unsigned int sz>
00113 forceinline void
00114 TinyBitSet<sz>::nand_with_mask(const BitSetData* b) {
00115 for (unsigned int i=sz; i--; )
00116 bits[i] = BitSetData::a(bits[i],~(b[i]));
00117 }
00118
00119 template<unsigned int sz>
00120 forceinline bool
00121 TinyBitSet<sz>::intersects(const BitSetData* b) {
00122 for (unsigned int i=sz; i--; )
00123 if (!BitSetData::a(bits[i],b[i]).none())
00124 return true;
00125 return false;
00126 }
00127
00128 template<unsigned int sz>
00129 forceinline bool
00130 TinyBitSet<sz>::empty(void) const {
00131 for (unsigned int i=sz; i--; )
00132 if (!bits[i].none())
00133 return false;
00134 return true;
00135 }
00136
00137 template<unsigned int sz>
00138 forceinline unsigned int
00139 TinyBitSet<sz>::width(void) const {
00140 assert(!empty());
00142 for (unsigned int i=sz; i--; )
00143 if (!bits[i].none())
00144 return i+1U;
00145 GECODE_NEVER;
00146 return 0U;
00147 }
00148
00149 template<unsigned int sz>
00150 forceinline unsigned int
00151 TinyBitSet<sz>::words(void) const {
00152 return width();
00153 }
00154
00155 template<unsigned int sz>
00156 forceinline unsigned int
00157 TinyBitSet<sz>::size(void) const {
00158 return sz;
00159 }
00160
00161 }}}
00162
00163