#ifndef BIT_VECTOR_INT_SET_H #define BIT_VECTOR_INT_SET_H #include "list.h" #include "slang-math.h" #include "common.h" #include "exception.h" #include namespace Slang { class IntSet { private: List buffer; public: IntSet() {} IntSet(const IntSet & other) { buffer = other.buffer; } IntSet(IntSet && other) { *this = (_Move(other)); } IntSet & operator = (IntSet && other) { buffer = _Move(other.buffer); return *this; } IntSet & operator = (const IntSet & other) { buffer = other.buffer; return *this; } int GetHashCode() { int rs = 0; for (auto val : buffer) rs ^= val; return rs; } IntSet(int maxVal) { SetMax(maxVal); } UInt Size() const { return buffer.Count()*32; } void SetMax(int val) { Resize(val); Clear(); } void SetAll() { for (UInt i = 0; i>5); if (buffer.Count() > oldBufferSize) memset(buffer.Buffer()+oldBufferSize, 0, (buffer.Count()-oldBufferSize) * sizeof(int)); } void Clear() { for (UInt i = 0; i>5; if (id < buffer.Count()) buffer[id] |= (1<<(val&31)); else { UInt oldSize = buffer.Count(); buffer.SetSize(id+1); memset(buffer.Buffer() + oldSize, 0, (buffer.Count()-oldSize)*sizeof(int)); buffer[id] |= (1<<(val&31)); } } void Remove(UInt val) { if ((val>>5) < buffer.Count()) buffer[(val>>5)] &= ~(1<<(val&31)); } bool Contains(UInt val) const { if ((val>>5) >= buffer.Count()) return false; return (buffer[(val>>5)] & (1<<(val&31))) != 0; } void UnionWith(const IntSet & set) { for (UInt i = 0; i buffer.Count()) buffer.AddRange(set.buffer.Buffer()+buffer.Count(), set.buffer.Count()-buffer.Count()); } bool operator == (const IntSet & set) { if (buffer.Count() != set.buffer.Count()) return false; for (UInt i = 0; i