Returns true if Merge caused a significant change
| 76 | |
| 77 | // Returns true if Merge caused a significant change |
| 78 | bool Merge(const SparseState<T> &other, int ignoreAfter) { |
| 79 | // Changes caused beyond ignoreAfter are not significant |
| 80 | Delete(ignoreAfter+1); |
| 81 | |
| 82 | bool different = true; |
| 83 | bool changed = false; |
| 84 | typename stateVector::iterator low = Find(other.positionFirst); |
| 85 | if (static_cast<size_t>(states.end() - low) == other.states.size()) { |
| 86 | // Same number in other as after positionFirst in this |
| 87 | different = !std::equal(low, states.end(), other.states.begin()); |
| 88 | } |
| 89 | if (different) { |
| 90 | if (low != states.end()) { |
| 91 | states.erase(low, states.end()); |
| 92 | changed = true; |
| 93 | } |
| 94 | typename stateVector::const_iterator startOther = other.states.begin(); |
| 95 | if (!states.empty() && !other.states.empty() && states.back().value == startOther->value) |
| 96 | ++startOther; |
| 97 | if (startOther != other.states.end()) { |
| 98 | states.insert(states.end(), startOther, other.states.end()); |
| 99 | changed = true; |
| 100 | } |
| 101 | } |
| 102 | return changed; |
| 103 | } |
| 104 | }; |
| 105 | |
| 106 | #ifdef SCI_NAMESPACE |