1 //===-- llvm/ADT/IntEqClasses.h - Equiv. Classes of Integers ----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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.
13 // Initially each integer has its own equivalence class. Classes are joined by
14 // passing a representative member of each class to join().
16 // Once the classes are built, compress() will number them 0 .. M-1 and prevent
19 //===----------------------------------------------------------------------===//
21 #ifndef LLVM_ADT_INTEQCLASSES_H
22 #define LLVM_ADT_INTEQCLASSES_H
24 #include "llvm/ADT/SmallVector.h"
29 /// EC - When uncompressed, map each integer to a smaller member of its
30 /// equivalence class. The class leader is the smallest member and maps to
33 /// When compressed, EC[i] is the equivalence class of i.
34 SmallVector<unsigned, 8> EC;
36 /// NumClasses - The number of equivalence classes when compressed, or 0 when
41 /// IntEqClasses - Create an equivalence class mapping for 0 .. N-1.
42 IntEqClasses(unsigned N) : NumClasses(0) { grow(N); }
44 /// grow - Increase capacity to hold 0 .. N-1, putting new integers in unique
45 /// equivalence classes.
46 /// This requires an uncompressed map.
47 void grow(unsigned N);
49 /// join - Join the equivalence classes of a and b. After joining classes,
50 /// findLeader(a) == findLeader(b).
51 /// This requires an uncompressed map.
52 void join(unsigned a, unsigned b);
54 /// findLeader - Compute the leader of a's equivalence class. This is the
55 /// smallest member of the class.
56 /// This requires an uncompressed map.
57 unsigned findLeader(unsigned a) const;
59 /// compress - Compress equivalence classes by numbering them 0 .. M.
60 /// This makes the equivalence class map immutable.
63 /// getNumClasses - Return the number of equivalence classes after compress()
65 unsigned getNumClasses() const { return NumClasses; }
67 /// operator[] - Return a's equivalence class number, 0 .. getNumClasses()-1.
68 /// This requires a compressed map.
69 unsigned operator[](unsigned a) const {
70 assert(NumClasses && "operator[] called before compress()");
74 /// uncompress - Change back to the uncompressed representation that allows
79 } // End llvm namespace