xref: /aosp_15_r20/external/stg/stable_hash.h (revision 9e3b08ae94a55201065475453d799e8b1378bea6)
1 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2 // -*- mode: C++ -*-
3 //
4 // Copyright 2022-2024 Google LLC
5 //
6 // Licensed under the Apache License v2.0 with LLVM Exceptions (the
7 // "License"); you may not use this file except in compliance with the
8 // License.  You may obtain a copy of the License at
9 //
10 //     https://llvm.org/LICENSE.txt
11 //
12 // Unless required by applicable law or agreed to in writing, software
13 // distributed under the License is distributed on an "AS IS" BASIS,
14 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 // See the License for the specific language governing permissions and
16 // limitations under the License.
17 //
18 // Author: Siddharth Nayyar
19 
20 #ifndef STG_STABLE_HASH_H_
21 #define STG_STABLE_HASH_H_
22 
23 #include <unordered_map>
24 
25 #include "graph.h"
26 #include "hashing.h"
27 
28 namespace stg {
29 
30 class StableHash {
31  public:
StableHash(const Graph & graph)32   explicit StableHash(const Graph& graph) : graph_(graph) {}
33   HashValue operator()(Id);
34 
35  private:
36   const Graph& graph_;
37   std::unordered_map<Id, HashValue> cache_;
38 };
39 
40 }  // namespace stg
41 
42 #endif  // STG_STABLE_HASH_H_
43