Where Online Learning is simpler!
The C and C++ Include Header Files
cat -n /usr/include/wabt/binding-hash.h
1 /* 2 * Copyright 2016 WebAssembly Community Group participants 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef WABT_BINDING_HASH_H_ 18 #define WABT_BINDING_HASH_H_ 19 20 #include <functional> 21 #include <string> 22 #include <string_view> 23 #include <unordered_map> 24 #include <vector> 25 26 #include "wabt/common.h" 27 28 namespace wabt { 29 30 struct Var; 31 32 struct Binding { 33 explicit Binding(Index index) : index(index) {} 34 Binding(const Location& loc, Index index) : loc(loc), index(index) {} 35 36 Location loc; 37 Index index; 38 }; 39 40 // This class derives from a C++ container, which is usually not advisable 41 // because they don't have virtual destructors. So don't delete a BindingHash 42 // object through a pointer to std::unordered_multimap. 43 class BindingHash : public std::unordered_multimap<std::string, Binding> { 44 public: 45 using DuplicateCallback = 46 std::function<void(const value_type&, const value_type&)>; 47 48 void FindDuplicates(DuplicateCallback callback) const; 49 50 Index FindIndex(const Var&) const; 51 52 Index FindIndex(const std::string& name) const { 53 auto iter = find(name); 54 return iter != end() ? iter->second.index : kInvalidIndex; 55 } 56 57 Index FindIndex(std::string_view name) const { 58 return FindIndex(std::string(name)); 59 } 60 61 private: 62 using ValueTypeVector = std::vector<const value_type*>; 63 64 void CreateDuplicatesVector(ValueTypeVector* out_duplicates) const; 65 void SortDuplicatesVectorByLocation(ValueTypeVector* duplicates) const; 66 void CallCallbacks(const ValueTypeVector& duplicates, 67 DuplicateCallback callback) const; 68 }; 69 70 } // namespace wabt 71 72 #endif /* WABT_BINDING_HASH_H_ */