forked from OpenAtomFoundation/pika
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpika_data_distribution.h
40 lines (33 loc) · 1.2 KB
/
pika_data_distribution.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Copyright (c) 2015-present, Qihoo, Inc. All rights reserved.
// This source code is licensed under the BSD-style license found in the
// LICENSE file in the root directory of this source tree. An additional grant
// of patent rights can be found in the PATENTS file in the same directory.
#ifndef PIKA_DATA_DISTRIBUTION_H_
#define PIKA_DATA_DISTRIBUTION_H_
#include "slash/include/slash_status.h"
// polynomial reserved Crc32 magic num
const uint32_t IEEE_POLY = 0xedb88320;
class PikaDataDistribution {
public:
virtual ~PikaDataDistribution() = default;
// Initialization
virtual void Init() = 0;
// key map to partition id
virtual uint32_t Distribute(const std::string& str, uint32_t partition_num) = 0;
};
class HashModulo : public PikaDataDistribution {
public:
virtual ~HashModulo() = default;
virtual void Init();
virtual uint32_t Distribute(const std::string& str, uint32_t partition_num);
};
class Crc32 : public PikaDataDistribution {
public:
virtual void Init();
virtual uint32_t Distribute(const std::string& str, uint32_t partition_num);
private:
void Crc32TableInit(uint32_t poly);
uint32_t Crc32Update(uint32_t crc, const char* buf, int len);
uint32_t crc32tab[256];
};
#endif