duckhandy/include/duckhandy/tiger_bt.hpp

61 lines
1.9 KiB
C++

/* Copyright 2016-2021, Michele Santullo
* This file is part of "duckhandy".
*
* "duckhandy" 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 of the License, or
* (at your option) any later version.
*
* "duckhandy" 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 "duckhandy". If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef id1E6CCE44307549A9B6C9E4E5923AC002
#define id1E6CCE44307549A9B6C9E4E5923AC002
#include "lengthof.h"
#include <cstdint>
#include <ciso646>
#include <climits>
namespace dhandy::bt {
struct TigerHash {
consteval TigerHash ( uint64_t parA, uint64_t parB, uint64_t parC ) :
a(parA), b(parB), c(parC)
{
}
consteval TigerHash ( uint64_t parAP, uint64_t parA, uint64_t parBP, uint64_t parB, uint64_t parCP, uint64_t parC ) :
a(0 == parAP ? parA : (0 == parBP ? parB : (0 == parCP ? parC : throw 0))),
b(1 == parAP ? parA : (1 == parBP ? parB : (1 == parCP ? parC : throw 0))),
c(2 == parAP ? parA : (2 == parBP ? parB : (2 == parCP ? parC : throw 0)))
{
}
consteval TigerHash ( const TigerHash& ) = default;
consteval uint64_t operator[] ( uint64_t parIndex ) const {
return (parIndex == 0 ? a :
(parIndex == 1 ? b :
(parIndex == 2 ? c : throw 0)
)
);
}
uint64_t a;
uint64_t b;
uint64_t c;
};
inline const constexpr char TigerPaddingV1 = 0x01;
inline const constexpr char TigerPaddingV2 = 0x80;
[[gnu::const]]
consteval TigerHash tiger ( const char* parStr, uint64_t parLen, char parPad );
} //namespace dhandy::bt
#include "tiger_bt.inl"
#endif