class OccLists
1 //================================================================================================= 2 // OccLists -- a class for maintaining occurence lists with lazy deletion: 3 // 用于通过延迟删除来维护出现列表的类 4 template<class Idx, class Vec, class Deleted> 5 class OccLists { 6 vec <Vec> occs; 7 vec<char> dirty; 8 vec <Idx> dirties; 9 Deleted deleted; 10 11 public: 12 OccLists(const Deleted &d) : deleted(d) {} 13 14 void init(const Idx &idx) { 15 occs.growTo(toInt(idx) + 1);//设置occs长度 16 dirty.growTo(toInt(idx) + 1, 0);//设置dirty长度,并且元素初始化为0 17 } 18 19 // OccLists[i]返回的是occs[toInt(i)] 20 Vec &operator[](const Idx &idx) { return occs[toInt(idx)]; } 21 22 //如果dirty[toInt(idx)]不为0,执行clean。否则,返回occs[toInt(idx)] 23 Vec &lookup(const Idx &idx) { 24 if (dirty[toInt(idx)]) clean(idx); 25 return occs[toInt(idx)]; 26 } 27 28 void cleanAll(); 29 30 void clean(const Idx &idx); 31 32 //如果dirty[toInt(idx)]为0,将其设置为1,并且在dirties中push(idx) 33 void smudge(const Idx &idx) { 34 if (dirty[toInt(idx)] == 0) { 35 dirty[toInt(idx)] = 1; 36 dirties.push(idx); 37 } 38 } 39 40 //释放内存 41 void clear(bool free = true) { 42 occs.clear(free); 43 dirty.clear(free); 44 dirties.clear(free); 45 } 46 }; 47 48 49 template<class Idx, class Vec, class Deleted> 50 void OccLists<Idx, Vec, Deleted>::cleanAll() { 51 for (int i = 0; i < dirties.size(); i++) 52 // Dirties may contain duplicates so check here if a variable is already cleaned: 53 if (dirty[toInt(dirties[i])]) 54 clean(dirties[i]); 55 dirties.clear(); 56 } 57 58 59 template<class Idx, class Vec, class Deleted> 60 void OccLists<Idx, Vec, Deleted>::clean(const Idx &idx) { 61 Vec &vec = occs[toInt(idx)]; 62 int i, j; 63 for (i = j = 0; i < vec.size(); i++) 64 if (!deleted(vec[i])) 65 vec[j++] = vec[i]; 66 vec.shrink(i - j); 67 dirty[toInt(idx)] = 0; 68 }
类型为OccLists的变量有watchesBin、watches
以watches举例说明
1 OccLists<Lit, vec<Watcher>, WatcherDeleted> watches;
其中idx对应为Lit,Vec对应为vec<Watcher>,Deleted对应为WatcherDeleted
1 struct WatcherDeleted 2 { 3 const ClauseAllocator& ca; 4 WatcherDeleted(const ClauseAllocator& _ca) : ca(_ca) {} 5 bool operator()(const Watcher& w) const { return ca[w.cref].mark() == 1; } 6 };
1 struct Watcher { 2 CRef cref; 3 Lit blocker; 4 Watcher(CRef cr, Lit p) : cref(cr), blocker(p) {} 5 bool operator==(const Watcher& w) const { return cref == w.cref; } 6 bool operator!=(const Watcher& w) const { return cref != w.cref; } 7 };
浙公网安备 33010602011771号