OmniSciDB  c1a53651b2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HashTable.h
Go to the documentation of this file.
1 /*
2  * Copyright 2022 HEAVY.AI, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 enum class HashType : int { OneToOne, OneToMany, ManyToMany };
20 
22  std::vector<int64_t> key;
23  std::set<int32_t> payload;
24 
25  bool operator<(const DecodedJoinHashBufferEntry& other) const {
26  return std::tie(key, payload) < std::tie(other.key, other.payload);
27  }
28 
29  bool operator==(const DecodedJoinHashBufferEntry& other) const {
30  return key == other.key && payload == other.payload;
31  }
32 };
33 
34 using DecodedJoinHashBufferSet = std::set<DecodedJoinHashBufferEntry>;
35 
36 class HashTable {
37  public:
38  virtual ~HashTable() {}
39 
40  virtual size_t getHashTableBufferSize(const ExecutorDeviceType device_type) const = 0;
41 
42  virtual int8_t* getCpuBuffer() = 0;
43  virtual int8_t* getGpuBuffer() const = 0;
44  virtual HashType getLayout() const = 0;
45 
46  virtual size_t getEntryCount() const = 0;
47  virtual size_t getEmittedKeysCount() const = 0;
48 
51  size_t key_component_count, // number of key parts
52  size_t key_component_width, // width of a key part
53  size_t entry_count, // number of hashable entries
54  const int8_t* ptr1, // hash entries
55  const int8_t* ptr2, // offsets
56  const int8_t* ptr3, // counts
57  const int8_t* ptr4, // payloads (rowids)
58  size_t buffer_size);
59 
61  static std::string toString(
62  const std::string& type, // perfect, keyed, or geo
63  const std::string& layout_type, // one-to-one, one-to-many, many-to-many
64  size_t key_component_count, // number of key parts
65  size_t key_component_width, // width of a key part
66  size_t entry_count, // number of hashable entries
67  const int8_t* ptr1, // hash entries
68  const int8_t* ptr2, // offsets
69  const int8_t* ptr3, // counts
70  const int8_t* ptr4, // payloads (rowids)
71  size_t buffer_size,
72  bool raw = false);
73 };
ExecutorDeviceType
virtual int8_t * getCpuBuffer()=0
virtual ~HashTable()
Definition: HashTable.h:38
Definition: HashTable.h:21
virtual size_t getEntryCount() const =0
virtual int8_t * getGpuBuffer() const =0
virtual size_t getHashTableBufferSize(const ExecutorDeviceType device_type) const =0
virtual HashType getLayout() const =0
virtual size_t getEmittedKeysCount() const =0
std::set< DecodedJoinHashBufferEntry > DecodedJoinHashBufferSet
Definition: HashTable.h:34
static std::string toString(const std::string &type, const std::string &layout_type, size_t key_component_count, size_t key_component_width, size_t entry_count, const int8_t *ptr1, const int8_t *ptr2, const int8_t *ptr3, const int8_t *ptr4, size_t buffer_size, bool raw=false)
Decode hash table into a human-readable string.
Definition: HashTable.cpp:226
bool operator==(const DecodedJoinHashBufferEntry &other) const
Definition: HashTable.h:29
std::set< int32_t > payload
Definition: HashTable.h:23
static DecodedJoinHashBufferSet toSet(size_t key_component_count, size_t key_component_width, size_t entry_count, const int8_t *ptr1, const int8_t *ptr2, const int8_t *ptr3, const int8_t *ptr4, size_t buffer_size)
Decode hash table into a std::set for easy inspection and validation.
Definition: HashTable.cpp:139
std::vector< int64_t > key
Definition: HashTable.h:22
HashType
Definition: HashTable.h:19
bool operator<(const DecodedJoinHashBufferEntry &other) const
Definition: HashTable.h:25