#ifndef V8_COMPILER_PERSISTENT_MAP_H_
#define V8_COMPILER_PERSISTENT_MAP_H_
#include <array>
#include <tuple>
#include "src/base/functional.h"
#include "src/zone/zone-containers.h"
namespace v8 {
namespace internal {
namespace compiler {
template <class T>
struct may_be_unequal { … };
template <class Key, class Value, class Hasher = base::hash<Key>>
class PersistentMap {
public:
using key_type = Key;
using mapped_type = Value;
using value_type = std::pair<Key, Value>;
private:
static constexpr size_t kHashBits = 32;
enum Bit : int { kLeft = 0, kRight = 1 };
class HashValue;
struct KeyValue : std::pair<Key, Value> {
const Key& key() const { return this->first; }
const Value& value() const { return this->second; }
using std::pair<Key, Value>::pair;
};
struct FocusedTree;
friend struct may_be_unequal<PersistentMap<Key, Value, Hasher>>;
public:
size_t last_depth() const { … }
const Value& Get(const Key& key) const { … }
void Set(Key key, Value value);
template <class F>
void Modify(Key key, F f);
bool operator==(const PersistentMap& other) const { … }
bool operator!=(const PersistentMap& other) const { … }
class iterator;
iterator begin() const { … }
iterator end() const { … }
class double_iterator;
struct ZipIterable {
PersistentMap a;
PersistentMap b;
double_iterator begin() { return double_iterator(a.begin(), b.begin()); }
double_iterator end() { return double_iterator(a.end(), b.end()); }
};
ZipIterable Zip(const PersistentMap& other) const { … }
explicit PersistentMap(Zone* zone, Value def_value = Value())
: … { … }
private:
const FocusedTree* FindHash(HashValue hash) const;
const FocusedTree* FindHash(HashValue hash,
std::array<const FocusedTree*, kHashBits>* path,
int* length) const;
const Value& GetFocusedValue(const FocusedTree* tree, const Key& key) const;
static const FocusedTree* GetChild(const FocusedTree* tree, int level,
Bit bit);
static const FocusedTree* FindLeftmost(
const FocusedTree* start, int* level,
std::array<const FocusedTree*, kHashBits>* path);
PersistentMap(const FocusedTree* tree, Zone* zone, Value def_value)
: … { … }
const FocusedTree* tree_;
Value def_value_;
Zone* zone_;
};
may_be_unequal<PersistentMap<Key, Value, Hasher>>;
template <class Key, class Value, class Hasher>
struct PersistentMap<Key, Value, Hasher>::FocusedTree { … };
template <class Key, class Value, class Hasher>
class PersistentMap<Key, Value, Hasher>::HashValue { … };
template <class Key, class Value, class Hasher>
class PersistentMap<Key, Value, Hasher>::iterator { … };
template <class Key, class Value, class Hasher>
class PersistentMap<Key, Value, Hasher>::double_iterator { … };
template <class Key, class Value, class Hasher>
void PersistentMap<Key, Value, Hasher>::Set(Key key, Value new_value) { … }
template <class Key, class Value, class Hasher>
template <class F>
void PersistentMap<Key, Value, Hasher>::Modify(Key key, F f) { … }
template <class Key, class Value, class Hasher>
const typename PersistentMap<Key, Value, Hasher>::FocusedTree*
PersistentMap<Key, Value, Hasher>::FindHash(HashValue hash) const { … }
template <class Key, class Value, class Hasher>
const typename PersistentMap<Key, Value, Hasher>::FocusedTree*
PersistentMap<Key, Value, Hasher>::FindHash(
HashValue hash, std::array<const FocusedTree*, kHashBits>* path,
int* length) const { … }
template <class Key, class Value, class Hasher>
const Value& PersistentMap<Key, Value, Hasher>::GetFocusedValue(
const FocusedTree* tree, const Key& key) const { … }
template <class Key, class Value, class Hasher>
const typename PersistentMap<Key, Value, Hasher>::FocusedTree*
PersistentMap<Key, Value, Hasher>::GetChild(const FocusedTree* tree, int level,
Bit bit) { … }
template <class Key, class Value, class Hasher>
const typename PersistentMap<Key, Value, Hasher>::FocusedTree*
PersistentMap<Key, Value, Hasher>::FindLeftmost(
const FocusedTree* start, int* level,
std::array<const FocusedTree*, kHashBits>* path) { … }
template <class Key, class Value, class Hasher>
std::ostream& operator<<(std::ostream& os,
const PersistentMap<Key, Value, Hasher>& map) { … }
}
}
}
#endif