/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* This file is part of the program and library */
/* PaPILO --- Parallel Presolve for Integer and Linear Optimization */
/* */
/* Copyright (C) 2020-2022 Konrad-Zuse-Zentrum */
/* fuer Informationstechnik Berlin */
/* */
/* This program is free software: you can redistribute it and/or modify */
/* it under the terms of the GNU Lesser General Public License as published */
/* by the Free Software Foundation, either version 3 of the License, or */
/* (at your option) any later version. */
/* */
/* This program 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 Lesser General Public License for more details. */
/* */
/* You should have received a copy of the GNU Lesser General Public License */
/* along with this program. If not, see . */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#ifndef _PAPILO_MISC_HASH_HPP_
#define _PAPILO_MISC_HASH_HPP_
#include "papilo/Config.hpp"
#ifndef PAPILO_USE_STANDARD_HASHMAP
#include "papilo/external/ska/bytell_hash_map.hpp"
#else
#include
#include
#endif
#include
#include
namespace papilo
{
template
struct HashHelpers;
template
struct HashHelpers
{
static uint32_t
fibonacci_muliplier()
{
return uint32_t( 0x9e3779b9 );
}
static uint32_t
rotate_left( uint32_t x, int n )
{
return ( x << n ) | ( x >> ( 32 - n ) );
}
};
template
struct HashHelpers
{
static uint64_t
fibonacci_muliplier()
{
return uint64_t( 0x9e3779b97f4a7c15 );
}
static uint64_t
rotate_left( uint64_t x, int n )
{
return ( x << n ) | ( x >> ( 64 - n ) );
}
};
template ::type>
struct Hasher;
// only add specialization for unsigned result types
template
struct Hasher
{
T state;
Hasher( T init = 0 ) : state( init ) {}
template ::value, int>::type = 0>
void
addValue( U val )
{
state = ( HashHelpers::rotate_left( state, 5 ) ^ T( val ) ) *
HashHelpers::fibonacci_muliplier();
}
T
getHash() const
{
return state;
}
};
#ifndef PAPILO_USE_STANDARD_HASHMAP
template ,
typename E = std::equal_to>
using HashMap =
ska::bytell_hash_map>>;
template , typename E = std::equal_to>
using HashSet = ska::bytell_hash_set>;
#else
template ,
typename E = std::equal_to>
using HashMap =
std::unordered_map>>;
template , typename E = std::equal_to>
using HashSet = std::unordered_set>;
#endif
} // namespace papilo
#endif