Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

131 lines
3.8 KiB

  1. //===- llvm/ADT/DenseSet.h - Dense probed hash table ------------*- C++ -*-===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file defines the DenseSet class.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_ADT_DENSESET_H
  14. #define LLVM_ADT_DENSESET_H
  15. #include "llvm/ADT/DenseMap.h"
  16. namespace llvm {
  17. /// DenseSet - This implements a dense probed hash-table based set.
  18. ///
  19. /// FIXME: This is currently implemented directly in terms of DenseMap, this
  20. /// should be optimized later if there is a need.
  21. template<typename ValueT, typename ValueInfoT = DenseMapInfo<ValueT> >
  22. class DenseSet {
  23. typedef DenseMap<ValueT, char, ValueInfoT> MapTy;
  24. MapTy TheMap;
  25. public:
  26. DenseSet(const DenseSet &Other) : TheMap(Other.TheMap) {}
  27. explicit DenseSet(unsigned NumInitBuckets = 0) : TheMap(NumInitBuckets) {}
  28. bool empty() const { return TheMap.empty(); }
  29. unsigned size() const { return TheMap.size(); }
  30. size_t getMemorySize() const { return TheMap.getMemorySize(); }
  31. /// Grow the DenseSet so that it has at least Size buckets. Will not shrink
  32. /// the Size of the set.
  33. void resize(size_t Size) { TheMap.resize(Size); }
  34. void clear() {
  35. TheMap.clear();
  36. }
  37. bool count(const ValueT &V) const {
  38. return TheMap.count(V);
  39. }
  40. bool erase(const ValueT &V) {
  41. return TheMap.erase(V);
  42. }
  43. void swap(DenseSet& RHS) {
  44. TheMap.swap(RHS.TheMap);
  45. }
  46. DenseSet &operator=(const DenseSet &RHS) {
  47. TheMap = RHS.TheMap;
  48. return *this;
  49. }
  50. // Iterators.
  51. class Iterator {
  52. typename MapTy::iterator I;
  53. friend class DenseSet;
  54. public:
  55. typedef typename MapTy::iterator::difference_type difference_type;
  56. typedef ValueT value_type;
  57. typedef value_type *pointer;
  58. typedef value_type &reference;
  59. typedef std::forward_iterator_tag iterator_category;
  60. Iterator(const typename MapTy::iterator &i) : I(i) {}
  61. ValueT& operator*() { return I->first; }
  62. ValueT* operator->() { return &I->first; }
  63. Iterator& operator++() { ++I; return *this; }
  64. bool operator==(const Iterator& X) const { return I == X.I; }
  65. bool operator!=(const Iterator& X) const { return I != X.I; }
  66. };
  67. class ConstIterator {
  68. typename MapTy::const_iterator I;
  69. friend class DenseSet;
  70. public:
  71. typedef typename MapTy::const_iterator::difference_type difference_type;
  72. typedef ValueT value_type;
  73. typedef value_type *pointer;
  74. typedef value_type &reference;
  75. typedef std::forward_iterator_tag iterator_category;
  76. ConstIterator(const typename MapTy::const_iterator &i) : I(i) {}
  77. const ValueT& operator*() { return I->first; }
  78. const ValueT* operator->() { return &I->first; }
  79. ConstIterator& operator++() { ++I; return *this; }
  80. bool operator==(const ConstIterator& X) const { return I == X.I; }
  81. bool operator!=(const ConstIterator& X) const { return I != X.I; }
  82. };
  83. typedef Iterator iterator;
  84. typedef ConstIterator const_iterator;
  85. iterator begin() { return Iterator(TheMap.begin()); }
  86. iterator end() { return Iterator(TheMap.end()); }
  87. const_iterator begin() const { return ConstIterator(TheMap.begin()); }
  88. const_iterator end() const { return ConstIterator(TheMap.end()); }
  89. iterator find(const ValueT &V) { return Iterator(TheMap.find(V)); }
  90. void erase(Iterator I) { return TheMap.erase(I.I); }
  91. void erase(ConstIterator CI) { return TheMap.erase(CI.I); }
  92. std::pair<iterator, bool> insert(const ValueT &V) {
  93. return TheMap.insert(std::make_pair(V, 0));
  94. }
  95. // Range insertion of values.
  96. template<typename InputIt>
  97. void insert(InputIt I, InputIt E) {
  98. for (; I != E; ++I)
  99. insert(*I);
  100. }
  101. };
  102. } // end namespace llvm
  103. #endif