The description of a single subgraph for processing.
| 31 | |
| 32 | // The description of a single subgraph for processing. |
| 33 | class Subgraph { |
| 34 | public: |
| 35 | // Identity of a single subgraph as a set of nodes. |
| 36 | class Identity : public gtl::FlatSet<const GenNode*> { |
| 37 | public: |
| 38 | using InitializerList = std::initializer_list<GenNode*>; |
| 39 | |
| 40 | Identity() = default; |
| 41 | Identity(InitializerList init); |
| 42 | bool operator<(const Identity& other) const; |
| 43 | bool operator==(const Identity& other) const; |
| 44 | |
| 45 | // Compute the hash. |
| 46 | size_t Hash() const; |
| 47 | }; |
| 48 | |
| 49 | explicit Subgraph(Identity id) : id_(std::move(id)), hash_(id_.Hash()) {} |
| 50 | |
| 51 | // Construct by extending the parent identity with an extra node. |
| 52 | Subgraph(const Identity& parent_id, GenNode* add_node); |
| 53 | |
| 54 | Subgraph() = delete; |
| 55 | Subgraph(const Subgraph& other) = delete; |
| 56 | void operator=(const Subgraph& other) = delete; |
| 57 | |
| 58 | // Order for building sets of subgraphs. |
| 59 | bool operator<(const Subgraph& other) const { return this->id_ < other.id_; } |
| 60 | // Support for hashed sets. |
| 61 | bool operator==(const Subgraph& other) const { |
| 62 | return this->id_ == other.id_; |
| 63 | } |
| 64 | size_t Hash() const { return hash_; } |
| 65 | |
| 66 | // Dump the subgraph information to a string. |
| 67 | string Dump(); |
| 68 | |
| 69 | // Extract this subgraph into a separate graph representation for signature |
| 70 | // building, that includes only the links between the nodes in the subgraph |
| 71 | // and drops all the external links. The result map should be clear before the |
| 72 | // call. |
| 73 | void ExtractForSignature(SigNodeMap* result); |
| 74 | |
| 75 | const Identity& id() const { return id_; } |
| 76 | bool specific() const { return specific_; } |
| 77 | void SetSpecific(bool value) { specific_ = value; } |
| 78 | int32_t collation_count() const { return collation_count_; } |
| 79 | void AddCollation(int32_t n = 1) { collation_count_ += n; } |
| 80 | void ResetCollation() { collation_count_ = 1; } |
| 81 | void MergeCollation(const Subgraph& other) { |
| 82 | collation_count_ += other.collation_count_; |
| 83 | } |
| 84 | |
| 85 | private: |
| 86 | // Identity also serves as the list of nodes. It never changes throughout the |
| 87 | // life of subgraph. |
| 88 | Identity id_; |
| 89 | size_t hash_; // Cached from the identity. |
| 90 | // Whether the dump should include the specific names of the nodes. The |