diff options
| author | Tim Foley <tfoley@nvidia.com> | 2017-06-15 13:24:25 -0700 |
|---|---|---|
| committer | Tim Foley <tfoley@nvidia.com> | 2017-06-15 13:24:25 -0700 |
| commit | 205187b561c3b31fa931e73e8f7263f0c4b1de41 (patch) | |
| tree | 7bd2cd5ae3c14416b71ef8319ff02ace429d1132 /source/core/int-set.h | |
| parent | 517513645afb8eaf4841e7b7035f1ba3a9c7cd57 (diff) | |
Rename `CoreLib::*` to `Slang`
Getting rid of more namespace complexity and stripping things down to the basics.
This also gets rid of some dead code in the "core" library.
Diffstat (limited to 'source/core/int-set.h')
| -rw-r--r-- | source/core/int-set.h | 285 |
1 files changed, 141 insertions, 144 deletions
diff --git a/source/core/int-set.h b/source/core/int-set.h index cb8f788f2..a56a58d64 100644 --- a/source/core/int-set.h +++ b/source/core/int-set.h @@ -8,159 +8,156 @@ #include <memory.h> -namespace CoreLib +namespace Slang { - namespace Basic + class IntSet { - class IntSet - { - private: - List<int> 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); - } - int Size() const - { - return buffer.Count()*32; - } - void SetMax(int val) - { - Resize(val); - Clear(); - } - void SetAll() - { - for (int i = 0; i<buffer.Count(); i++) - buffer[i] = 0xFFFFFFFF; - } - void Resize(int size) - { - int oldBufferSize = buffer.Count(); - buffer.SetSize((size+31)>>5); - if (buffer.Count() > oldBufferSize) - memset(buffer.Buffer()+oldBufferSize, 0, (buffer.Count()-oldBufferSize) * sizeof(int)); - } - void Clear() - { - for (int i = 0; i<buffer.Count(); i++) - buffer[i] = 0; - } - void Add(int val) - { - int id = val>>5; - if (id < buffer.Count()) - buffer[id] |= (1<<(val&31)); - else - { - int oldSize = buffer.Count(); - buffer.SetSize(id+1); - memset(buffer.Buffer() + oldSize, 0, (buffer.Count()-oldSize)*sizeof(int)); - buffer[id] |= (1<<(val&31)); - } - } - void Remove(int val) - { - if ((val>>5) < buffer.Count()) - buffer[(val>>5)] &= ~(1<<(val&31)); - } - bool Contains(int val) const - { - if ((val>>5) >= buffer.Count()) - return false; - return (buffer[(val>>5)] & (1<<(val&31))) != 0; - } - void UnionWith(const IntSet & set) + private: + List<int> 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); + } + int Size() const + { + return buffer.Count()*32; + } + void SetMax(int val) + { + Resize(val); + Clear(); + } + void SetAll() + { + for (int i = 0; i<buffer.Count(); i++) + buffer[i] = 0xFFFFFFFF; + } + void Resize(int size) + { + int oldBufferSize = buffer.Count(); + buffer.SetSize((size+31)>>5); + if (buffer.Count() > oldBufferSize) + memset(buffer.Buffer()+oldBufferSize, 0, (buffer.Count()-oldBufferSize) * sizeof(int)); + } + void Clear() + { + for (int i = 0; i<buffer.Count(); i++) + buffer[i] = 0; + } + void Add(int val) + { + int id = val>>5; + if (id < buffer.Count()) + buffer[id] |= (1<<(val&31)); + else + { + int oldSize = buffer.Count(); + buffer.SetSize(id+1); + memset(buffer.Buffer() + oldSize, 0, (buffer.Count()-oldSize)*sizeof(int)); + buffer[id] |= (1<<(val&31)); + } + } + void Remove(int val) + { + if ((val>>5) < buffer.Count()) + buffer[(val>>5)] &= ~(1<<(val&31)); + } + bool Contains(int val) const + { + if ((val>>5) >= buffer.Count()) + return false; + return (buffer[(val>>5)] & (1<<(val&31))) != 0; + } + void UnionWith(const IntSet & set) + { + for (int i = 0; i<Math::Min(set.buffer.Count(), buffer.Count()); i++) { - for (int i = 0; i<Math::Min(set.buffer.Count(), buffer.Count()); i++) - { - buffer[i] |= set.buffer[i]; - } - if (set.buffer.Count() > buffer.Count()) - buffer.AddRange(set.buffer.Buffer()+buffer.Count(), set.buffer.Count()-buffer.Count()); + buffer[i] |= set.buffer[i]; } - bool operator == (const IntSet & set) - { - if (buffer.Count() != set.buffer.Count()) + if (set.buffer.Count() > 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 (int i = 0; i<buffer.Count(); i++) + if (buffer[i] != set.buffer[i]) return false; - for (int i = 0; i<buffer.Count(); i++) - if (buffer[i] != set.buffer[i]) - return false; - return true; - } - bool operator != (const IntSet & set) - { - return !(*this == set); - } - void IntersectWith(const IntSet & set) - { - if (set.buffer.Count() < buffer.Count()) - memset(buffer.Buffer() + set.buffer.Count(), 0, (buffer.Count()-set.buffer.Count())*sizeof(int)); - for (int i = 0; i<Math::Min(set.buffer.Count(), buffer.Count()); i++) - { - buffer[i] &= set.buffer[i]; - } - } - static void Union(IntSet & rs, const IntSet & set1, const IntSet & set2) - { - rs.buffer.SetSize(Math::Max(set1.buffer.Count(), set2.buffer.Count())); - rs.Clear(); - for (int i = 0; i<set1.buffer.Count(); i++) - rs.buffer[i] |= set1.buffer[i]; - for (int i = 0; i<set2.buffer.Count(); i++) - rs.buffer[i] |= set2.buffer[i]; - } - static void Intersect(IntSet & rs, const IntSet & set1, const IntSet & set2) - { - rs.buffer.SetSize(Math::Min(set1.buffer.Count(), set2.buffer.Count())); - for (int i = 0; i<rs.buffer.Count(); i++) - rs.buffer[i] = set1.buffer[i] & set2.buffer[i]; - } - static void Subtract(IntSet & rs, const IntSet & set1, const IntSet & set2) + return true; + } + bool operator != (const IntSet & set) + { + return !(*this == set); + } + void IntersectWith(const IntSet & set) + { + if (set.buffer.Count() < buffer.Count()) + memset(buffer.Buffer() + set.buffer.Count(), 0, (buffer.Count()-set.buffer.Count())*sizeof(int)); + for (int i = 0; i<Math::Min(set.buffer.Count(), buffer.Count()); i++) { - rs.buffer.SetSize(set1.buffer.Count()); - for (int i = 0; i<Math::Min(set1.buffer.Count(), set2.buffer.Count()); i++) - rs.buffer[i] = set1.buffer[i] & (~set2.buffer[i]); + buffer[i] &= set.buffer[i]; } - static bool HasIntersection(const IntSet & set1, const IntSet & set2) + } + static void Union(IntSet & rs, const IntSet & set1, const IntSet & set2) + { + rs.buffer.SetSize(Math::Max(set1.buffer.Count(), set2.buffer.Count())); + rs.Clear(); + for (int i = 0; i<set1.buffer.Count(); i++) + rs.buffer[i] |= set1.buffer[i]; + for (int i = 0; i<set2.buffer.Count(); i++) + rs.buffer[i] |= set2.buffer[i]; + } + static void Intersect(IntSet & rs, const IntSet & set1, const IntSet & set2) + { + rs.buffer.SetSize(Math::Min(set1.buffer.Count(), set2.buffer.Count())); + for (int i = 0; i<rs.buffer.Count(); i++) + rs.buffer[i] = set1.buffer[i] & set2.buffer[i]; + } + static void Subtract(IntSet & rs, const IntSet & set1, const IntSet & set2) + { + rs.buffer.SetSize(set1.buffer.Count()); + for (int i = 0; i<Math::Min(set1.buffer.Count(), set2.buffer.Count()); i++) + rs.buffer[i] = set1.buffer[i] & (~set2.buffer[i]); + } + static bool HasIntersection(const IntSet & set1, const IntSet & set2) + { + for (int i = 0; i<Math::Min(set1.buffer.Count(), set2.buffer.Count()); i++) { - for (int i = 0; i<Math::Min(set1.buffer.Count(), set2.buffer.Count()); i++) - { - if (set1.buffer[i] & set2.buffer[i]) - return true; - } - return false; + if (set1.buffer[i] & set2.buffer[i]) + return true; } - }; - } + return false; + } + }; } #endif
\ No newline at end of file |
