Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@

# CMakeLists.txt
#
# Copyright 2015-2019 J. Andrew Rogers
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

cmake_minimum_required(VERSION 3.1)

project(MetroHash VERSION 1.0.0 LANGUAGES CXX)


add_library(metrohash STATIC "")

target_include_directories(metrohash PUBLIC inc)

target_sources(metrohash PRIVATE inc/metrohash/MetroHash.h
inc/metrohash/MetroHash64.h
inc/metrohash/MetroHash128.h
inc/metrohash/MetroHash128crc.h
src/MetroHash64.cpp
src/MetroHash128.cpp
src/MetroHash128crc.cpp
src/Platform.h
src/TestVector.h)


set_target_properties(metrohash PROPERTIES CXX_STANDARD 98
CXX_STANDARD_REQUIRED ON
CXX_EXTENSIONS OFF)


if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")

# [GCC] x86 Options
# https://gcc.gnu.org/onlinedocs/gcc-8.1.0/gcc/x86-Options.html
target_compile_options(metrohash PRIVATE
-msse4.2) # Enable the use of SSE4.2 instructions.

# [GCC] Options to Request or Suppress Warnings
# https://gcc.gnu.org/onlinedocs/gcc-8.1.0/gcc/Warning-Options.html
target_compile_options(metrohash PRIVATE
-Wall
-Wextra
-Wpedantic
-Werror)

elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")

# [MSVC] Minimum CPU Architecture
# https://docs.microsoft.com/en-us/cpp/build/reference/arch-x86
# https://docs.microsoft.com/en-us/cpp/build/reference/arch-x64
# For x64 CPUs SSE4.2 instructions are enabled by default.

# [MSVC] Warning Level
# https://docs.microsoft.com/en-us/cpp/build/reference/compiler-option-warning-level
target_compile_options(metrohash PRIVATE
/W4 # Enable warning level 4.
/WX) # Treat warnings as errors.

else()
message(FATAL_ERROR "Compiler ${CMAKE_CXX_COMPILER_ID} is not supported!")
endif()


if(NOT CMAKE_SIZEOF_VOID_P EQUAL 8)

message(FATAL_ERROR "MetroHash supports only 64-bit builds!")

endif()
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ The project has been re-licensed under Apache License v2.0. The purpose of this

Two new 64-bit and 128-bit algorithms add the ability to construct hashes incrementally. In addition to supporting incremental construction, the algorithms are slightly superior to the prior versions.

A big change is that these new algorithms are implemented as C++ classes that support both incremental and stateless hashing. These classes also have a static method for verifying the implementation against the test vectors built into the classes. Implementations are now fully contained by their respective headers e.g. "metrohash128.h".
A big change is that these new algorithms are implemented as C++ classes that support both incremental and stateless hashing. These classes also have a static method for verifying the implementation against the test vectors built into the classes. Implementations are now fully contained by their respective headers e.g. "metrohash/MetroHash128.h".

*Note: an incremental version of the 128-bit CRC version is on its way but is not included in this push.*

Expand Down
6 changes: 3 additions & 3 deletions src/metrohash.h → inc/metrohash/MetroHash.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
#ifndef METROHASH_METROHASH_H
#define METROHASH_METROHASH_H

#include "metrohash64.h"
#include "metrohash128.h"
#include "metrohash128crc.h"
#include <metrohash/MetroHash64.h>
#include <metrohash/MetroHash128.h>
#include <metrohash/MetroHash128crc.h>

#endif // #ifndef METROHASH_METROHASH_H
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions src/metrohash128.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
// limitations under the License.

#include <string.h>
#include "platform.h"
#include "metrohash128.h"
#include "Platform.h"
#include <metrohash/MetroHash128.h>

const char * MetroHash128::test_string = "012345678901234567890123456789012345678901234567890123456789012";

Expand Down
5 changes: 3 additions & 2 deletions src/metrohash128crc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
// limitations under the License.


// SSE4.2 -> https://software.intel.com/sites/landingpage/IntrinsicsGuide/#text=_mm_crc32_u64
#include <nmmintrin.h>
#include <string.h>
#include "metrohash.h"
#include "platform.h"
#include <metrohash/MetroHash128crc.h>
#include "Platform.h"


void metrohash128crc_1(const uint8_t * key, uint64_t len, uint32_t seed, uint8_t * out)
Expand Down
4 changes: 2 additions & 2 deletions src/metrohash64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "platform.h"
#include "metrohash64.h"
#include "Platform.h"
#include <metrohash/MetroHash64.h>

#include <cstring>

Expand Down
2 changes: 1 addition & 1 deletion src/testvector.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#ifndef METROHASH_TESTVECTOR_H
#define METROHASH_TESTVECTOR_H

#include "metrohash.h"
#include <metrohash/MetroHash.h>


typedef void (*HashFunction) (const uint8_t * key, uint64_t len, uint32_t seed, uint8_t * hash);
Expand Down