Loading...
Searching...
No Matches
fnv_1.h
Go to the documentation of this file.
/******************************************************************************
The MIT License(MIT)
Embedded Template Library.
https://github.com/ETLCPP/etl
https://www.etlcpp.com
Copyright(c) 2014 John Wellbelove
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files(the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions :
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
******************************************************************************/
#ifndef ETL_FNV_1_INCLUDED
#define ETL_FNV_1_INCLUDED
#include "platform.h"
#include "frame_check_sequence.h"
#include "ihash.h"
#include "type_traits.h"
#include <stdint.h>
#if defined(ETL_COMPILER_KEIL)
#pragma diag_suppress 1300
#endif
namespace etl
{
#if ETL_USING_64BIT_TYPES
//***************************************************************************
//***************************************************************************
struct fnv_1_policy_64
{
typedef uint64_t value_type;
uint64_t initial() const
{
return OFFSET_BASIS;
}
uint64_t add(uint64_t hash, uint8_t value) const
{
hash *= PRIME;
hash ^= value;
return hash;
}
uint64_t final(uint64_t hash) const
{
return hash;
}
static ETL_CONSTANT uint64_t OFFSET_BASIS = 0xCBF29CE484222325ull;
static ETL_CONSTANT uint64_t PRIME = 0x00000100000001b3ull;
};
//***************************************************************************
//***************************************************************************
class fnv_1_64 : public etl::frame_check_sequence<fnv_1_policy_64>
{
public:
//*************************************************************************
//*************************************************************************
fnv_1_64()
{
this->reset();
}
//*************************************************************************
//*************************************************************************
template <typename TIterator>
fnv_1_64(TIterator begin, const TIterator end)
{
this->reset();
this->add(begin, end);
}
};
//***************************************************************************
//***************************************************************************
struct fnv_1a_policy_64
{
typedef uint64_t value_type;
uint64_t initial() const
{
return OFFSET_BASIS;
}
uint64_t add(uint64_t hash, uint8_t value) const
{
hash ^= value;
hash *= PRIME;
return hash;
}
uint64_t final(uint64_t hash) const
{
return hash;
}
static ETL_CONSTANT uint64_t OFFSET_BASIS = 0xCBF29CE484222325ull;
static ETL_CONSTANT uint64_t PRIME = 0x00000100000001b3ull;
};
//***************************************************************************
//***************************************************************************
class fnv_1a_64 : public etl::frame_check_sequence<fnv_1a_policy_64>
{
public:
//*************************************************************************
//*************************************************************************
fnv_1a_64()
{
this->reset();
}
//*************************************************************************
//*************************************************************************
template <typename TIterator>
fnv_1a_64(TIterator begin, const TIterator end)
{
this->reset();
this->add(begin, end);
}
};
#endif
//***************************************************************************
//***************************************************************************
struct fnv_1_policy_32
{
typedef uint32_t value_type;
uint32_t initial() const
{
return OFFSET_BASIS;
}
uint32_t add(uint32_t hash, uint8_t value) const
{
hash *= PRIME;
hash ^= value;
return hash;
}
uint32_t final(uint32_t hash) const
{
return hash;
}
static ETL_CONSTANT uint32_t OFFSET_BASIS = 0x811C9DC5UL;
static ETL_CONSTANT uint32_t PRIME = 0x01000193UL;
};
//***************************************************************************
//***************************************************************************
class fnv_1_32 : public etl::frame_check_sequence<fnv_1_policy_32>
{
public:
//*************************************************************************
//*************************************************************************
fnv_1_32()
{
this->reset();
}
//*************************************************************************
//*************************************************************************
template <typename TIterator>
fnv_1_32(TIterator begin, const TIterator end)
{
this->reset();
this->add(begin, end);
}
};
//***************************************************************************
//***************************************************************************
struct fnv_1a_policy_32
{
typedef uint32_t value_type;
uint32_t initial() const
{
return OFFSET_BASIS;
}
uint32_t add(uint32_t hash, uint8_t value) const
{
hash ^= value;
hash *= PRIME;
return hash;
}
uint32_t final(uint32_t hash) const
{
return hash;
}
static ETL_CONSTANT uint32_t OFFSET_BASIS = 0x811C9DC5UL;
static ETL_CONSTANT uint32_t PRIME = 0x01000193UL;
};
//***************************************************************************
//***************************************************************************
class fnv_1a_32 : public etl::frame_check_sequence<fnv_1a_policy_32>
{
public:
//*************************************************************************
//*************************************************************************
fnv_1a_32()
{
this->reset();
}
//*************************************************************************
//*************************************************************************
template <typename TIterator>
fnv_1a_32(TIterator begin, const TIterator end)
{
this->reset();
this->add(begin, end);
}
};
} // namespace etl
#endif
etl::fnv_1_32::fnv_1_32
fnv_1_32(TIterator begin, const TIterator end)
Definition fnv_1.h:219
etl::fnv_1_32::fnv_1_32
fnv_1_32()
Default constructor.
Definition fnv_1.h:208
etl::fnv_1_64::fnv_1_64
fnv_1_64(TIterator begin, const TIterator end)
Definition fnv_1.h:102
etl::fnv_1_64::fnv_1_64
fnv_1_64()
Default constructor.
Definition fnv_1.h:91
etl::fnv_1a_32::fnv_1a_32
fnv_1a_32()
Default constructor.
Definition fnv_1.h:266
etl::fnv_1a_32::fnv_1a_32
fnv_1a_32(TIterator begin, const TIterator end)
Definition fnv_1.h:277
etl::fnv_1a_64::fnv_1a_64
fnv_1a_64()
Default constructor.
Definition fnv_1.h:149
etl::fnv_1a_64::fnv_1a_64
fnv_1a_64(TIterator begin, const TIterator end)
Definition fnv_1.h:160
frame_check_sequence.h
etl::frame_check_sequence< fnv_1_policy_64 >::add
ETL_CONSTEXPR14 void add(TIterator begin, const TIterator end)
Definition frame_check_sequence.h:145
etl::frame_check_sequence< fnv_1_policy_64 >::reset
ETL_CONSTEXPR14 void reset()
Definition frame_check_sequence.h:134
etl::frame_check_sequence
Definition frame_check_sequence.h:98
ihash.h
etl
Definition absolute.h:40
etl::end
TContainer::iterator end(TContainer &container)
Definition iterator.h:1166
etl::begin
TContainer::iterator begin(TContainer &container)
Definition iterator.h:1136
platform.h
etl::fnv_1_policy_32
Definition fnv_1.h:173
etl::fnv_1_policy_64
Definition fnv_1.h:56
etl::fnv_1a_policy_32
Definition fnv_1.h:231
etl::fnv_1a_policy_64
Definition fnv_1.h:114
type_traits.h