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.

88 lines
2.8 KiB

  1. //===-- llvm/ADT/IntEqClasses.h - Equiv. Classes of Integers ----*- 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. // Equivalence classes for small integers. This is a mapping of the integers
  11. // 0 .. N-1 into M equivalence classes numbered 0 .. M-1.
  12. //
  13. // Initially each integer has its own equivalence class. Classes are joined by
  14. // passing a representative member of each class to join().
  15. //
  16. // Once the classes are built, compress() will number them 0 .. M-1 and prevent
  17. // further changes.
  18. //
  19. //===----------------------------------------------------------------------===//
  20. #ifndef LLVM_ADT_INTEQCLASSES_H
  21. #define LLVM_ADT_INTEQCLASSES_H
  22. #include "llvm/ADT/SmallVector.h"
  23. namespace llvm {
  24. class IntEqClasses {
  25. /// EC - When uncompressed, map each integer to a smaller member of its
  26. /// equivalence class. The class leader is the smallest member and maps to
  27. /// itself.
  28. ///
  29. /// When compressed, EC[i] is the equivalence class of i.
  30. SmallVector<unsigned, 8> EC;
  31. /// NumClasses - The number of equivalence classes when compressed, or 0 when
  32. /// uncompressed.
  33. unsigned NumClasses;
  34. public:
  35. /// IntEqClasses - Create an equivalence class mapping for 0 .. N-1.
  36. IntEqClasses(unsigned N = 0) : NumClasses(0) { grow(N); }
  37. /// grow - Increase capacity to hold 0 .. N-1, putting new integers in unique
  38. /// equivalence classes.
  39. /// This requires an uncompressed map.
  40. void grow(unsigned N);
  41. /// clear - Clear all classes so that grow() will assign a unique class to
  42. /// every integer.
  43. void clear() {
  44. EC.clear();
  45. NumClasses = 0;
  46. }
  47. /// join - Join the equivalence classes of a and b. After joining classes,
  48. /// findLeader(a) == findLeader(b).
  49. /// This requires an uncompressed map.
  50. void join(unsigned a, unsigned b);
  51. /// findLeader - Compute the leader of a's equivalence class. This is the
  52. /// smallest member of the class.
  53. /// This requires an uncompressed map.
  54. unsigned findLeader(unsigned a) const;
  55. /// compress - Compress equivalence classes by numbering them 0 .. M.
  56. /// This makes the equivalence class map immutable.
  57. void compress();
  58. /// getNumClasses - Return the number of equivalence classes after compress()
  59. /// was called.
  60. unsigned getNumClasses() const { return NumClasses; }
  61. /// operator[] - Return a's equivalence class number, 0 .. getNumClasses()-1.
  62. /// This requires a compressed map.
  63. unsigned operator[](unsigned a) const {
  64. assert(NumClasses && "operator[] called before compress()");
  65. return EC[a];
  66. }
  67. /// uncompress - Change back to the uncompressed representation that allows
  68. /// editing.
  69. void uncompress();
  70. };
  71. } // End llvm namespace
  72. #endif