/* A hash map traits.
Copyright (C) 2015-2024 Free Software Foundation, Inc.
This file is part of GCC.
GCC is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 3, or (at your option) any later
version.
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3. If not see
. */
#ifndef HASH_MAP_TRAITS_H
#define HASH_MAP_TRAITS_H
/* Bacause mem-stats.h uses default hashmap traits, we have to
put the class to this separate header file. */
#include "hash-traits.h"
/* Implement hash_map traits for a key with hash traits H. Empty and
deleted map entries are represented as empty and deleted keys. */
template
struct simple_hashmap_traits
{
typedef typename H::value_type key_type;
static const bool maybe_mx = true;
static inline hashval_t hash (const key_type &);
static inline bool equal_keys (const key_type &, const key_type &);
template static inline void remove (T &);
static const bool empty_zero_p = H::empty_zero_p;
template static inline bool is_empty (const T &);
template static inline bool is_deleted (const T &);
template static inline void mark_empty (T &);
template static inline void mark_deleted (T &);
};
template
inline hashval_t
simple_hashmap_traits ::hash (const key_type &h)
{
return H::hash (h);
}
template
inline bool
simple_hashmap_traits ::equal_keys (const key_type &k1,
const key_type &k2)
{
return H::equal (k1, k2);
}
template
template
inline void
simple_hashmap_traits ::remove (T &entry)
{
H::remove (entry.m_key);
entry.m_value.~Value ();
}
template
template
inline bool
simple_hashmap_traits ::is_empty (const T &entry)
{
return H::is_empty (entry.m_key);
}
template
template
inline bool
simple_hashmap_traits ::is_deleted (const T &entry)
{
return H::is_deleted (entry.m_key);
}
template
template
inline void
simple_hashmap_traits ::mark_empty (T &entry)
{
H::mark_empty (entry.m_key);
}
template
template
inline void
simple_hashmap_traits ::mark_deleted (T &entry)
{
H::mark_deleted (entry.m_key);
}
template
struct simple_cache_map_traits: public simple_hashmap_traits
{
static const bool maybe_mx = false;
};
/* Implement traits for a hash_map with keys of type Key and values of
type Value for cases in which the key cannot represent empty and
deleted slots. Instead record empty and deleted entries in Value. */
template
struct unbounded_hashmap_traits
{
typedef typename Key::value_type key_type;
static hashval_t hash (const typename Key::value_type &);
static bool equal_keys (const typename Key::value_type &,
const typename Key::compare_type &);
template static inline void remove (T &);
static const bool empty_zero_p = default_hash_traits ::empty_zero_p;
template static inline bool is_empty (const T &);
template static inline bool is_deleted (const T &);
template static inline void mark_empty (T &);
template static inline void mark_deleted (T &);
};
template
inline hashval_t
unbounded_hashmap_traits
::hash (const typename Key::value_type &key)
{
return Key::hash (key);
}
template
inline bool
unbounded_hashmap_traits
::equal_keys (const typename Key::value_type &x,
const typename Key::compare_type &y)
{
return Key::equal (x, y);
}
template
template
inline void
unbounded_hashmap_traits ::remove (T &entry)
{
default_hash_traits ::remove (entry.m_value);
}
template
template
inline bool
unbounded_hashmap_traits ::is_empty (const T &entry)
{
return default_hash_traits ::is_empty (entry.m_value);
}
template
template
inline bool
unbounded_hashmap_traits ::is_deleted (const T &entry)
{
return default_hash_traits ::is_deleted (entry.m_value);
}
template
template
inline void
unbounded_hashmap_traits ::mark_empty (T &entry)
{
default_hash_traits ::mark_empty (entry.m_value);
}
template
template
inline void
unbounded_hashmap_traits ::mark_deleted (T &entry)
{
default_hash_traits ::mark_deleted (entry.m_value);
}
/* Implement traits for a hash_map from integer type Key to Value in
cases where Key has no spare values for recording empty and deleted
slots. */
template
using unbounded_int_hashmap_traits
= unbounded_hashmap_traits , Value>;
#endif // HASH_MAP_TRAITS_H