• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #ifndef ADDRESS_HANDLER_H
16 #define ADDRESS_HANDLER_H
17 #include "logging.h"
18 
19 struct Bitpool {
20     std::atomic<uint64_t> slot;
21 };
22 
23 class AddressHandler {
24 public:
25     AddressHandler(uint64_t poolSize);
26     virtual ~AddressHandler();
27 
SetSuccessor(std::shared_ptr<AddressHandler> successor)28     void SetSuccessor(std::shared_ptr<AddressHandler> successor)
29     {
30         successor_ = std::move(successor);
31     }
32 
33     virtual void AddAllocAddr(uint64_t addr) = 0;
34     virtual bool CheckAddr(uint64_t addr) = 0;
35 
36 protected:
37     std::shared_ptr<AddressHandler> successor_ = nullptr;
38     Bitpool* addressChecker_ = nullptr;
39     uint64_t bitPoolSize_ = 0;
40 };
41 
42 class LowAddrHandler : public AddressHandler {
43 public:
44     LowAddrHandler();
45     void AddAllocAddr(uint64_t addr) override;
46     bool CheckAddr(uint64_t addr) override;
47     //MurmurHash
48     uint32_t HashFunc(uint32_t addrKey);
49 };
50 
51 class MidAddrHandler : public AddressHandler {
52 public:
53     MidAddrHandler();
54     void AddAllocAddr(uint64_t addr) override;
55     bool CheckAddr(uint64_t addr) override;
56     //Fnv1aHash
57     uint32_t HashFunc(uint32_t addrKey);
58 };
59 
60 class WholeAddrHandler : public AddressHandler {
61 public:
62     WholeAddrHandler();
63     void AddAllocAddr(uint64_t addr) override;
64     bool CheckAddr(uint64_t addr) override;
65     //SplitMix64
66     uint64_t HashFunc(uint64_t addrKey);
67 };
68 #endif