llvm/llvm/include/llvm/ADT/ScopedHashTable.h

//===- ScopedHashTable.h - A simple scoped hash table -----------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file implements an efficient scoped hash table, which is useful for
// things like dominator-based optimizations.  This allows clients to do things
// like this:
//
//  ScopedHashTable<int, int> HT;
//  {
//    ScopedHashTableScope<int, int> Scope1(HT);
//    HT.insert(0, 0);
//    HT.insert(1, 1);
//    {
//      ScopedHashTableScope<int, int> Scope2(HT);
//      HT.insert(0, 42);
//    }
//  }
//
// Looking up the value for "0" in the Scope2 block will return 42.  Looking
// up the value for 0 before 42 is inserted or after Scope2 is popped will
// return 0.
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_ADT_SCOPEDHASHTABLE_H
#define LLVM_ADT_SCOPEDHASHTABLE_H

#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/DenseMapInfo.h"
#include "llvm/Support/AllocatorBase.h"
#include <cassert>
#include <new>

namespace llvm {

template <typename K, typename V, typename KInfo = DenseMapInfo<K>,
          typename AllocatorTy = MallocAllocator>
class ScopedHashTable;

template <typename K, typename V>
class ScopedHashTableVal {};

template <typename K, typename V, typename KInfo = DenseMapInfo<K>,
          typename AllocatorTy = MallocAllocator>
class ScopedHashTableScope {};

template <typename K, typename V, typename KInfo = DenseMapInfo<K>>
class ScopedHashTableIterator {
  ScopedHashTableVal<K, V> *Node;

public:
  ScopedHashTableIterator(ScopedHashTableVal<K, V> *node) :{}

  V &operator*() const {}
  V *operator->() const {}

  bool operator==(const ScopedHashTableIterator &RHS) const {}
  bool operator!=(const ScopedHashTableIterator &RHS) const {}

  inline ScopedHashTableIterator& operator++() {}
  ScopedHashTableIterator operator++(int) {}
};

template <typename K, typename V, typename KInfo, typename AllocatorTy>
class ScopedHashTable : detail::AllocatorHolder<AllocatorTy> {};

/// ScopedHashTableScope ctor - Install this as the current scope for the hash
/// table.
template <typename K, typename V, typename KInfo, typename Allocator>
ScopedHashTableScope<K, V, KInfo, Allocator>::
  ScopedHashTableScope(ScopedHashTable<K, V, KInfo, Allocator> &ht) :{}

template <typename K, typename V, typename KInfo, typename Allocator>
ScopedHashTableScope<K, V, KInfo, Allocator>::~ScopedHashTableScope() {}

} // end namespace llvm

#endif // LLVM_ADT_SCOPEDHASHTABLE_H