2007-10-09 23:38:09 +02:00
|
|
|
//===--- ImmutableMap.h - Immutable (functional) map interface --*- C++ -*-===//
|
|
|
|
//
|
2019-01-19 09:50:56 +01:00
|
|
|
// 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
|
2007-10-09 23:38:09 +02:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines the ImmutableMap class.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2013-01-10 01:45:19 +01:00
|
|
|
#ifndef LLVM_ADT_IMMUTABLEMAP_H
|
|
|
|
#define LLVM_ADT_IMMUTABLEMAP_H
|
2007-10-09 23:38:09 +02:00
|
|
|
|
2016-12-07 23:06:02 +01:00
|
|
|
#include "llvm/ADT/FoldingSet.h"
|
2007-10-09 23:38:09 +02:00
|
|
|
#include "llvm/ADT/ImmutableSet.h"
|
2016-12-07 23:06:02 +01:00
|
|
|
#include "llvm/Support/Allocator.h"
|
|
|
|
#include <utility>
|
2007-10-09 23:38:09 +02:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
2009-02-20 23:20:18 +01:00
|
|
|
/// ImutKeyValueInfo -Traits class used by ImmutableMap. While both the first
|
|
|
|
/// and second elements in a pair are used to generate profile information,
|
2007-10-09 23:38:09 +02:00
|
|
|
/// only the first element (the key) is used by isEqual and isLess.
|
|
|
|
template <typename T, typename S>
|
|
|
|
struct ImutKeyValueInfo {
|
2017-06-14 23:42:24 +02:00
|
|
|
using value_type = const std::pair<T,S>;
|
|
|
|
using value_type_ref = const value_type&;
|
|
|
|
using key_type = const T;
|
|
|
|
using key_type_ref = const T&;
|
|
|
|
using data_type = const S;
|
|
|
|
using data_type_ref = const S&;
|
2009-01-09 20:25:42 +01:00
|
|
|
|
2007-10-09 23:38:09 +02:00
|
|
|
static inline key_type_ref KeyOfValue(value_type_ref V) {
|
|
|
|
return V.first;
|
|
|
|
}
|
2009-01-09 20:25:42 +01:00
|
|
|
|
2008-01-17 18:36:49 +01:00
|
|
|
static inline data_type_ref DataOfValue(value_type_ref V) {
|
|
|
|
return V.second;
|
2007-10-09 23:38:09 +02:00
|
|
|
}
|
2009-01-09 20:25:42 +01:00
|
|
|
|
2008-01-17 18:36:49 +01:00
|
|
|
static inline bool isEqual(key_type_ref L, key_type_ref R) {
|
|
|
|
return ImutContainerInfo<T>::isEqual(L,R);
|
2009-01-09 20:25:42 +01:00
|
|
|
}
|
2007-10-09 23:38:09 +02:00
|
|
|
static inline bool isLess(key_type_ref L, key_type_ref R) {
|
|
|
|
return ImutContainerInfo<T>::isLess(L,R);
|
|
|
|
}
|
2009-01-09 20:25:42 +01:00
|
|
|
|
2008-01-17 18:36:49 +01:00
|
|
|
static inline bool isDataEqual(data_type_ref L, data_type_ref R) {
|
|
|
|
return ImutContainerInfo<S>::isEqual(L,R);
|
|
|
|
}
|
2009-01-09 20:25:42 +01:00
|
|
|
|
2007-10-09 23:38:09 +02:00
|
|
|
static inline void Profile(FoldingSetNodeID& ID, value_type_ref V) {
|
|
|
|
ImutContainerInfo<T>::Profile(ID, V.first);
|
|
|
|
ImutContainerInfo<S>::Profile(ID, V.second);
|
|
|
|
}
|
2009-01-09 20:25:42 +01:00
|
|
|
};
|
2007-10-09 23:38:09 +02:00
|
|
|
|
2009-01-09 20:25:42 +01:00
|
|
|
template <typename KeyT, typename ValT,
|
2016-12-07 23:06:02 +01:00
|
|
|
typename ValInfo = ImutKeyValueInfo<KeyT,ValT>>
|
2007-10-09 23:38:09 +02:00
|
|
|
class ImmutableMap {
|
2008-01-08 22:05:59 +01:00
|
|
|
public:
|
2017-06-14 23:42:24 +02:00
|
|
|
using value_type = typename ValInfo::value_type;
|
|
|
|
using value_type_ref = typename ValInfo::value_type_ref;
|
|
|
|
using key_type = typename ValInfo::key_type;
|
|
|
|
using key_type_ref = typename ValInfo::key_type_ref;
|
|
|
|
using data_type = typename ValInfo::data_type;
|
|
|
|
using data_type_ref = typename ValInfo::data_type_ref;
|
|
|
|
using TreeTy = ImutAVLTree<ValInfo>;
|
2009-01-09 20:25:42 +01:00
|
|
|
|
2010-02-01 11:43:31 +01:00
|
|
|
protected:
|
2020-05-21 19:10:22 +02:00
|
|
|
IntrusiveRefCntPtr<TreeTy> Root;
|
2009-01-09 20:25:42 +01:00
|
|
|
|
2007-10-09 23:38:09 +02:00
|
|
|
public:
|
2008-01-08 22:05:59 +01:00
|
|
|
/// Constructs a map from a pointer to a tree root. In general one
|
|
|
|
/// should use a Factory object to create maps instead of directly
|
|
|
|
/// invoking the constructor, but there are cases where make this
|
|
|
|
/// constructor public is useful.
|
2020-05-21 19:10:22 +02:00
|
|
|
explicit ImmutableMap(const TreeTy *R) : Root(const_cast<TreeTy *>(R)) {}
|
2015-09-29 20:02:48 +02:00
|
|
|
|
2007-10-09 23:38:09 +02:00
|
|
|
class Factory {
|
|
|
|
typename TreeTy::Factory F;
|
2012-12-06 20:41:30 +01:00
|
|
|
const bool Canonicalize;
|
2009-01-09 20:25:42 +01:00
|
|
|
|
2007-10-09 23:38:09 +02:00
|
|
|
public:
|
2015-08-10 06:22:36 +02:00
|
|
|
Factory(bool canonicalize = true) : Canonicalize(canonicalize) {}
|
2015-08-10 06:22:09 +02:00
|
|
|
|
2015-08-10 06:22:36 +02:00
|
|
|
Factory(BumpPtrAllocator &Alloc, bool canonicalize = true)
|
|
|
|
: F(Alloc), Canonicalize(canonicalize) {}
|
2009-01-09 20:25:42 +01:00
|
|
|
|
2016-12-07 23:06:02 +01:00
|
|
|
Factory(const Factory &) = delete;
|
|
|
|
Factory &operator=(const Factory &) = delete;
|
|
|
|
|
2010-11-24 01:54:28 +01:00
|
|
|
ImmutableMap getEmptyMap() { return ImmutableMap(F.getEmptyTree()); }
|
2009-01-09 20:25:42 +01:00
|
|
|
|
2018-05-31 19:32:29 +02:00
|
|
|
LLVM_NODISCARD ImmutableMap add(ImmutableMap Old, key_type_ref K,
|
|
|
|
data_type_ref D) {
|
2020-05-21 19:10:22 +02:00
|
|
|
TreeTy *T = F.add(Old.Root.get(), std::pair<key_type, data_type>(K, D));
|
2010-11-24 01:54:28 +01:00
|
|
|
return ImmutableMap(Canonicalize ? F.getCanonicalTree(T): T);
|
2007-10-09 23:38:09 +02:00
|
|
|
}
|
2009-01-09 20:25:42 +01:00
|
|
|
|
2018-05-31 19:32:29 +02:00
|
|
|
LLVM_NODISCARD ImmutableMap remove(ImmutableMap Old, key_type_ref K) {
|
2020-05-21 19:10:22 +02:00
|
|
|
TreeTy *T = F.remove(Old.Root.get(), K);
|
2010-11-24 01:54:28 +01:00
|
|
|
return ImmutableMap(Canonicalize ? F.getCanonicalTree(T): T);
|
2009-01-09 20:25:42 +01:00
|
|
|
}
|
|
|
|
|
2011-09-23 21:10:26 +02:00
|
|
|
typename TreeTy::Factory *getTreeFactory() const {
|
|
|
|
return const_cast<typename TreeTy::Factory *>(&F);
|
|
|
|
}
|
2007-10-09 23:38:09 +02:00
|
|
|
};
|
2009-01-09 20:25:42 +01:00
|
|
|
|
2007-10-09 23:38:09 +02:00
|
|
|
bool contains(key_type_ref K) const {
|
|
|
|
return Root ? Root->contains(K) : false;
|
|
|
|
}
|
2008-01-16 00:53:53 +01:00
|
|
|
|
2010-11-30 21:26:45 +01:00
|
|
|
bool operator==(const ImmutableMap &RHS) const {
|
2020-05-21 19:10:22 +02:00
|
|
|
return Root && RHS.Root ? Root->isEqual(*RHS.Root.get()) : Root == RHS.Root;
|
2007-10-09 23:38:09 +02:00
|
|
|
}
|
2009-01-09 20:25:42 +01:00
|
|
|
|
2010-11-30 21:26:45 +01:00
|
|
|
bool operator!=(const ImmutableMap &RHS) const {
|
2020-05-21 19:10:22 +02:00
|
|
|
return Root && RHS.Root ? Root->isNotEqual(*RHS.Root.get())
|
|
|
|
: Root != RHS.Root;
|
2007-10-09 23:38:09 +02:00
|
|
|
}
|
2009-01-09 20:25:42 +01:00
|
|
|
|
2011-02-19 02:59:21 +01:00
|
|
|
TreeTy *getRoot() const {
|
2010-11-30 21:26:45 +01:00
|
|
|
if (Root) { Root->retain(); }
|
2020-05-21 19:10:22 +02:00
|
|
|
return Root.get();
|
2010-11-30 21:26:45 +01:00
|
|
|
}
|
2009-01-09 20:25:42 +01:00
|
|
|
|
2020-05-21 19:10:22 +02:00
|
|
|
TreeTy *getRootWithoutRetain() const { return Root.get(); }
|
2015-08-10 06:22:09 +02:00
|
|
|
|
2011-02-19 02:59:21 +01:00
|
|
|
void manualRetain() {
|
|
|
|
if (Root) Root->retain();
|
|
|
|
}
|
2015-08-10 06:22:09 +02:00
|
|
|
|
2011-02-19 02:59:21 +01:00
|
|
|
void manualRelease() {
|
|
|
|
if (Root) Root->release();
|
|
|
|
}
|
|
|
|
|
2007-10-09 23:38:09 +02:00
|
|
|
bool isEmpty() const { return !Root; }
|
|
|
|
|
2009-01-09 20:25:42 +01:00
|
|
|
//===--------------------------------------------------===//
|
2007-10-09 23:38:09 +02:00
|
|
|
// Foreach - A limited form of map iteration.
|
|
|
|
//===--------------------------------------------------===//
|
|
|
|
|
|
|
|
private:
|
|
|
|
template <typename Callback>
|
|
|
|
struct CBWrapper {
|
|
|
|
Callback C;
|
2017-06-14 23:42:24 +02:00
|
|
|
|
2009-01-09 20:25:42 +01:00
|
|
|
void operator()(value_type_ref V) { C(V.first,V.second); }
|
|
|
|
};
|
|
|
|
|
2007-10-09 23:38:09 +02:00
|
|
|
template <typename Callback>
|
|
|
|
struct CBWrapperRef {
|
|
|
|
Callback &C;
|
2017-06-14 23:42:24 +02:00
|
|
|
|
2007-10-09 23:38:09 +02:00
|
|
|
CBWrapperRef(Callback& c) : C(c) {}
|
2009-01-09 20:25:42 +01:00
|
|
|
|
|
|
|
void operator()(value_type_ref V) { C(V.first,V.second); }
|
2007-10-09 23:38:09 +02:00
|
|
|
};
|
2009-01-09 20:25:42 +01:00
|
|
|
|
|
|
|
public:
|
2007-10-09 23:38:09 +02:00
|
|
|
template <typename Callback>
|
2009-01-09 20:25:42 +01:00
|
|
|
void foreach(Callback& C) {
|
|
|
|
if (Root) {
|
2007-10-09 23:38:09 +02:00
|
|
|
CBWrapperRef<Callback> CB(C);
|
|
|
|
Root->foreach(CB);
|
|
|
|
}
|
|
|
|
}
|
2009-01-09 20:25:42 +01:00
|
|
|
|
2007-10-09 23:38:09 +02:00
|
|
|
template <typename Callback>
|
2009-01-09 20:25:42 +01:00
|
|
|
void foreach() {
|
2007-10-09 23:38:09 +02:00
|
|
|
if (Root) {
|
|
|
|
CBWrapper<Callback> CB;
|
|
|
|
Root->foreach(CB);
|
|
|
|
}
|
|
|
|
}
|
2009-01-09 20:25:42 +01:00
|
|
|
|
|
|
|
//===--------------------------------------------------===//
|
2007-10-09 23:38:09 +02:00
|
|
|
// For testing.
|
2009-01-09 20:25:42 +01:00
|
|
|
//===--------------------------------------------------===//
|
|
|
|
|
2007-10-09 23:38:09 +02:00
|
|
|
void verify() const { if (Root) Root->verify(); }
|
2009-01-09 20:25:42 +01:00
|
|
|
|
|
|
|
//===--------------------------------------------------===//
|
2008-01-02 22:31:48 +01:00
|
|
|
// Iterators.
|
2009-01-09 20:25:42 +01:00
|
|
|
//===--------------------------------------------------===//
|
|
|
|
|
2015-03-15 14:26:03 +01:00
|
|
|
class iterator : public ImutAVLValueIterator<ImmutableMap> {
|
2016-12-07 23:06:02 +01:00
|
|
|
friend class ImmutableMap;
|
|
|
|
|
2015-03-15 14:26:03 +01:00
|
|
|
iterator() = default;
|
|
|
|
explicit iterator(TreeTy *Tree) : iterator::ImutAVLValueIterator(Tree) {}
|
2008-01-02 22:31:48 +01:00
|
|
|
|
|
|
|
public:
|
2015-03-15 14:26:03 +01:00
|
|
|
key_type_ref getKey() const { return (*this)->first; }
|
|
|
|
data_type_ref getData() const { return (*this)->second; }
|
2008-01-02 22:31:48 +01:00
|
|
|
};
|
2009-01-09 20:25:42 +01:00
|
|
|
|
2020-05-21 19:10:22 +02:00
|
|
|
iterator begin() const { return iterator(Root.get()); }
|
2009-01-09 20:25:42 +01:00
|
|
|
iterator end() const { return iterator(); }
|
|
|
|
|
2008-07-07 18:20:55 +02:00
|
|
|
data_type* lookup(key_type_ref K) const {
|
2008-01-16 00:53:53 +01:00
|
|
|
if (Root) {
|
|
|
|
TreeTy* T = Root->find(K);
|
2008-07-07 18:20:55 +02:00
|
|
|
if (T) return &T->getValue().second;
|
2008-01-16 00:53:53 +01:00
|
|
|
}
|
2009-01-09 20:25:42 +01:00
|
|
|
|
2014-04-24 08:44:33 +02:00
|
|
|
return nullptr;
|
2008-01-16 00:53:53 +01:00
|
|
|
}
|
2015-08-10 06:22:09 +02:00
|
|
|
|
2009-02-23 18:27:18 +01:00
|
|
|
/// getMaxElement - Returns the <key,value> pair in the ImmutableMap for
|
|
|
|
/// which key is the highest in the ordering of keys in the map. This
|
|
|
|
/// method returns NULL if the map is empty.
|
|
|
|
value_type* getMaxElement() const {
|
2014-04-24 08:44:33 +02:00
|
|
|
return Root ? &(Root->getMaxElement()->getValue()) : nullptr;
|
2009-02-23 18:27:18 +01:00
|
|
|
}
|
2009-01-09 20:25:42 +01:00
|
|
|
|
|
|
|
//===--------------------------------------------------===//
|
2008-01-02 22:31:48 +01:00
|
|
|
// Utility methods.
|
2009-01-09 20:25:42 +01:00
|
|
|
//===--------------------------------------------------===//
|
|
|
|
|
2010-01-22 01:28:27 +01:00
|
|
|
unsigned getHeight() const { return Root ? Root->getHeight() : 0; }
|
2008-01-02 22:31:48 +01:00
|
|
|
|
2008-02-04 22:17:02 +01:00
|
|
|
static inline void Profile(FoldingSetNodeID& ID, const ImmutableMap& M) {
|
2020-05-21 19:10:22 +02:00
|
|
|
ID.AddPointer(M.Root.get());
|
2008-01-02 22:31:48 +01:00
|
|
|
}
|
2009-01-09 20:25:42 +01:00
|
|
|
|
2008-01-02 22:31:48 +01:00
|
|
|
inline void Profile(FoldingSetNodeID& ID) const {
|
2008-01-02 23:18:33 +01:00
|
|
|
return Profile(ID,*this);
|
2009-01-09 20:25:42 +01:00
|
|
|
}
|
2007-10-09 23:38:09 +02:00
|
|
|
};
|
2009-01-09 20:25:42 +01:00
|
|
|
|
2011-09-17 01:01:25 +02:00
|
|
|
// NOTE: This will possibly become the new implementation of ImmutableMap some day.
|
|
|
|
template <typename KeyT, typename ValT,
|
2016-12-07 23:06:02 +01:00
|
|
|
typename ValInfo = ImutKeyValueInfo<KeyT,ValT>>
|
2011-09-17 01:01:25 +02:00
|
|
|
class ImmutableMapRef {
|
|
|
|
public:
|
2017-06-14 23:42:24 +02:00
|
|
|
using value_type = typename ValInfo::value_type;
|
|
|
|
using value_type_ref = typename ValInfo::value_type_ref;
|
|
|
|
using key_type = typename ValInfo::key_type;
|
|
|
|
using key_type_ref = typename ValInfo::key_type_ref;
|
|
|
|
using data_type = typename ValInfo::data_type;
|
|
|
|
using data_type_ref = typename ValInfo::data_type_ref;
|
|
|
|
using TreeTy = ImutAVLTree<ValInfo>;
|
|
|
|
using FactoryTy = typename TreeTy::Factory;
|
2015-08-10 06:22:09 +02:00
|
|
|
|
2011-09-17 01:01:25 +02:00
|
|
|
protected:
|
2020-05-21 19:10:22 +02:00
|
|
|
IntrusiveRefCntPtr<TreeTy> Root;
|
2011-09-17 01:01:25 +02:00
|
|
|
FactoryTy *Factory;
|
2015-08-10 06:22:09 +02:00
|
|
|
|
2011-09-17 01:01:25 +02:00
|
|
|
public:
|
|
|
|
/// Constructs a map from a pointer to a tree root. In general one
|
|
|
|
/// should use a Factory object to create maps instead of directly
|
|
|
|
/// invoking the constructor, but there are cases where make this
|
|
|
|
/// constructor public is useful.
|
2020-05-21 19:10:22 +02:00
|
|
|
ImmutableMapRef(const TreeTy *R, FactoryTy *F)
|
|
|
|
: Root(const_cast<TreeTy *>(R)), Factory(F) {}
|
2012-12-07 03:03:00 +01:00
|
|
|
|
2020-05-21 19:10:22 +02:00
|
|
|
ImmutableMapRef(const ImmutableMap<KeyT, ValT> &X,
|
|
|
|
typename ImmutableMap<KeyT, ValT>::Factory &F)
|
|
|
|
: Root(X.getRootWithoutRetain()), Factory(F.getTreeFactory()) {}
|
2011-09-17 01:01:25 +02:00
|
|
|
|
|
|
|
static inline ImmutableMapRef getEmptyMap(FactoryTy *F) {
|
|
|
|
return ImmutableMapRef(0, F);
|
|
|
|
}
|
|
|
|
|
2012-12-07 03:03:00 +01:00
|
|
|
void manualRetain() {
|
|
|
|
if (Root) Root->retain();
|
|
|
|
}
|
|
|
|
|
|
|
|
void manualRelease() {
|
|
|
|
if (Root) Root->release();
|
|
|
|
}
|
|
|
|
|
2012-12-07 20:44:12 +01:00
|
|
|
ImmutableMapRef add(key_type_ref K, data_type_ref D) const {
|
2020-05-21 19:10:22 +02:00
|
|
|
TreeTy *NewT =
|
|
|
|
Factory->add(Root.get(), std::pair<key_type, data_type>(K, D));
|
2011-09-17 01:01:25 +02:00
|
|
|
return ImmutableMapRef(NewT, Factory);
|
|
|
|
}
|
|
|
|
|
2012-12-07 20:44:12 +01:00
|
|
|
ImmutableMapRef remove(key_type_ref K) const {
|
2020-05-21 19:10:22 +02:00
|
|
|
TreeTy *NewT = Factory->remove(Root.get(), K);
|
2011-09-17 01:01:25 +02:00
|
|
|
return ImmutableMapRef(NewT, Factory);
|
|
|
|
}
|
2015-08-10 06:22:09 +02:00
|
|
|
|
2011-09-17 01:01:25 +02:00
|
|
|
bool contains(key_type_ref K) const {
|
|
|
|
return Root ? Root->contains(K) : false;
|
|
|
|
}
|
2015-08-10 06:22:09 +02:00
|
|
|
|
2011-09-17 01:01:25 +02:00
|
|
|
ImmutableMap<KeyT, ValT> asImmutableMap() const {
|
2020-05-21 19:10:22 +02:00
|
|
|
return ImmutableMap<KeyT, ValT>(Factory->getCanonicalTree(Root.get()));
|
2011-09-17 01:01:25 +02:00
|
|
|
}
|
2015-08-10 06:22:09 +02:00
|
|
|
|
2011-09-17 01:01:25 +02:00
|
|
|
bool operator==(const ImmutableMapRef &RHS) const {
|
2020-05-21 19:10:22 +02:00
|
|
|
return Root && RHS.Root ? Root->isEqual(*RHS.Root.get()) : Root == RHS.Root;
|
2011-09-17 01:01:25 +02:00
|
|
|
}
|
2015-08-10 06:22:09 +02:00
|
|
|
|
2011-09-17 01:01:25 +02:00
|
|
|
bool operator!=(const ImmutableMapRef &RHS) const {
|
2020-05-21 19:10:22 +02:00
|
|
|
return Root && RHS.Root ? Root->isNotEqual(*RHS.Root.get())
|
|
|
|
: Root != RHS.Root;
|
2011-09-17 01:01:25 +02:00
|
|
|
}
|
2015-08-10 06:22:09 +02:00
|
|
|
|
2011-09-17 01:01:25 +02:00
|
|
|
bool isEmpty() const { return !Root; }
|
2015-08-10 06:22:09 +02:00
|
|
|
|
2011-09-17 01:01:25 +02:00
|
|
|
//===--------------------------------------------------===//
|
|
|
|
// For testing.
|
|
|
|
//===--------------------------------------------------===//
|
2015-08-10 06:22:09 +02:00
|
|
|
|
2015-08-10 06:22:36 +02:00
|
|
|
void verify() const {
|
|
|
|
if (Root)
|
|
|
|
Root->verify();
|
|
|
|
}
|
2015-08-10 06:22:09 +02:00
|
|
|
|
2011-09-17 01:01:25 +02:00
|
|
|
//===--------------------------------------------------===//
|
|
|
|
// Iterators.
|
|
|
|
//===--------------------------------------------------===//
|
2015-03-15 14:26:03 +01:00
|
|
|
|
|
|
|
class iterator : public ImutAVLValueIterator<ImmutableMapRef> {
|
2016-12-07 23:06:02 +01:00
|
|
|
friend class ImmutableMapRef;
|
|
|
|
|
2015-03-15 14:26:03 +01:00
|
|
|
iterator() = default;
|
|
|
|
explicit iterator(TreeTy *Tree) : iterator::ImutAVLValueIterator(Tree) {}
|
|
|
|
|
2011-09-17 01:01:25 +02:00
|
|
|
public:
|
2015-03-15 14:26:03 +01:00
|
|
|
key_type_ref getKey() const { return (*this)->first; }
|
|
|
|
data_type_ref getData() const { return (*this)->second; }
|
2011-09-17 01:01:25 +02:00
|
|
|
};
|
2015-03-15 14:26:03 +01:00
|
|
|
|
2020-05-21 19:10:22 +02:00
|
|
|
iterator begin() const { return iterator(Root.get()); }
|
2011-09-17 01:01:25 +02:00
|
|
|
iterator end() const { return iterator(); }
|
2015-08-10 06:22:09 +02:00
|
|
|
|
2015-08-10 06:22:36 +02:00
|
|
|
data_type *lookup(key_type_ref K) const {
|
2011-09-17 01:01:25 +02:00
|
|
|
if (Root) {
|
|
|
|
TreeTy* T = Root->find(K);
|
|
|
|
if (T) return &T->getValue().second;
|
|
|
|
}
|
2015-08-10 06:22:09 +02:00
|
|
|
|
2015-09-29 20:02:48 +02:00
|
|
|
return nullptr;
|
2011-09-17 01:01:25 +02:00
|
|
|
}
|
2015-08-10 06:22:09 +02:00
|
|
|
|
2011-09-17 01:01:25 +02:00
|
|
|
/// getMaxElement - Returns the <key,value> pair in the ImmutableMap for
|
|
|
|
/// which key is the highest in the ordering of keys in the map. This
|
|
|
|
/// method returns NULL if the map is empty.
|
|
|
|
value_type* getMaxElement() const {
|
|
|
|
return Root ? &(Root->getMaxElement()->getValue()) : 0;
|
|
|
|
}
|
2015-08-10 06:22:09 +02:00
|
|
|
|
2011-09-17 01:01:25 +02:00
|
|
|
//===--------------------------------------------------===//
|
|
|
|
// Utility methods.
|
|
|
|
//===--------------------------------------------------===//
|
2015-08-10 06:22:09 +02:00
|
|
|
|
2011-09-17 01:01:25 +02:00
|
|
|
unsigned getHeight() const { return Root ? Root->getHeight() : 0; }
|
2015-08-10 06:22:09 +02:00
|
|
|
|
2015-08-10 06:22:36 +02:00
|
|
|
static inline void Profile(FoldingSetNodeID &ID, const ImmutableMapRef &M) {
|
2020-10-15 15:07:48 +02:00
|
|
|
ID.AddPointer(M.Root.get());
|
2011-09-17 01:01:25 +02:00
|
|
|
}
|
2015-08-10 06:22:09 +02:00
|
|
|
|
2015-08-10 06:22:36 +02:00
|
|
|
inline void Profile(FoldingSetNodeID &ID) const { return Profile(ID, *this); }
|
2011-09-17 01:01:25 +02:00
|
|
|
};
|
2015-08-10 06:22:09 +02:00
|
|
|
|
2007-10-09 23:38:09 +02:00
|
|
|
} // end namespace llvm
|
|
|
|
|
2015-09-29 20:02:48 +02:00
|
|
|
#endif // LLVM_ADT_IMMUTABLEMAP_H
|