bool StructureSet::merge(const StructureSet& other) { if (other.isThin()) { if (other.singleStructure()) return add(other.singleStructure()); return false; } OutOfLineList* list = other.structureList(); if (list->m_length >= 2) { if (isThin()) { OutOfLineList* myNewList = OutOfLineList::create( list->m_length + !!singleStructure()); if (singleStructure()) { myNewList->m_length = 1; myNewList->list()[0] = singleStructure(); } set(myNewList); } bool changed = false; for (unsigned i = 0; i < list->m_length; ++i) changed |= addOutOfLine(list->list()[i]); return changed; } ASSERT(list->m_length); return add(list->list()[0]); }
void StructureSet::exclude(const StructureSet& other) { if (other.isThin()) { if (other.singleStructure()) remove(other.singleStructure()); return; } if (isThin()) { if (!singleStructure()) return; if (other.contains(singleStructure())) clear(); return; } OutOfLineList* list = structureList(); for (unsigned i = 0; i < list->m_length; ++i) { if (!other.containsOutOfLine(list->list()[i])) continue; list->list()[i--] = list->list()[--list->m_length]; } if (!list->m_length) clear(); }
bool StructureSet::isSubsetOf(const StructureSet& other) const { if (isThin()) { if (!singleStructure()) return true; return other.contains(singleStructure()); } if (other.isThin()) { if (!other.singleStructure()) return false; OutOfLineList* list = structureList(); if (list->m_length >= 2) return false; if (list->list()[0] == other.singleStructure()) return true; return false; } OutOfLineList* list = structureList(); for (unsigned i = 0; i < list->m_length; ++i) { if (!other.containsOutOfLine(list->list()[i])) return false; } return true; }
void StructureSet::filter(const StructureSet& other) { if (other.isThin()) { if (!other.singleStructure() || !contains(other.singleStructure())) clear(); else { clear(); set(other.singleStructure()); } return; } ContainsOutOfLine containsOutOfLine(other); genericFilter(containsOutOfLine); }