1// Licensed to the Apache Software Foundation (ASF) under one
2// or more contributor license agreements. See the NOTICE file
3// distributed with this work for additional information
4// regarding copyright ownership. The ASF licenses this file
5// to you under the Apache License, Version 2.0 (the
6// "License"); you may not use this file except in compliance
7// with the License. You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing,
12// software distributed under the License is distributed on an
13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14// KIND, either express or implied. See the License for the
15// specific language governing permissions and limitations
16// under the License.
17
18//-----------------------------------------------------------------------------
19// MurmurHash3 was written by Austin Appleby, and is placed in the public
20// domain. The author hereby disclaims copyright to this source code.
21
22#ifndef PARQUET_MURMURHASH3_H_
23#define PARQUET_MURMURHASH3_H_
24
25#include <cstdint>
26
27#include "parquet/hasher.h"
28#include "parquet/platform.h"
29#include "parquet/types.h"
30
31namespace parquet {
32
33/// Source:
34/// https://github.com/aappleby/smhasher/blob/master/src/MurmurHash3.cpp
35/// (Modified to adapt to coding conventions and to inherit the Hasher abstract class)
36class PARQUET_EXPORT MurmurHash3 : public Hasher {
37 public:
38 MurmurHash3() : seed_(DEFAULT_SEED) {}
39 uint64_t Hash(int32_t value) const override;
40 uint64_t Hash(int64_t value) const override;
41 uint64_t Hash(float value) const override;
42 uint64_t Hash(double value) const override;
43 uint64_t Hash(const Int96* value) const override;
44 uint64_t Hash(const ByteArray* value) const override;
45 uint64_t Hash(const FLBA* val, uint32_t len) const override;
46
47 private:
48 // Default seed for hash which comes from Bloom filter in parquet-mr, it is generated
49 // by System.nanoTime() of java.
50 static constexpr int DEFAULT_SEED = 1361930890;
51
52 uint32_t seed_;
53};
54
55} // namespace parquet
56
57#endif // PARQUET_MURMURHASH3_H_
58