Open3D (C++ API)  0.11.0
Hashmap.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - Open3D: www.open3d.org -
3 // ----------------------------------------------------------------------------
4 // The MIT License (MIT)
5 //
6 // Copyright (c) 2018 www.open3d.org
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to deal
10 // in the Software without restriction, including without limitation the rights
11 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 // copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 //
15 // The above copyright notice and this permission notice shall be included in
16 // all copies or substantial portions of the Software.
17 //
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 // IN THE SOFTWARE.
25 // ----------------------------------------------------------------------------
26 
27 #include "open3d/core/Dtype.h"
28 #include "open3d/core/Tensor.h"
31 
32 namespace open3d {
33 namespace core {
34 
35 class Hashmap {
36 public:
37  static constexpr uint32_t kDefaultElemsPerBucket = 4;
38 
39  // Default constructor for common users.
40  Hashmap(size_t init_capacity,
41  Dtype dtype_key,
42  Dtype dtype_val,
43  const Device& device);
44 
45  ~Hashmap(){};
46 
52  void Rehash(size_t buckets);
53 
57  void Insert(const void* input_keys,
58  const void* input_values,
59  iterator_t* output_iterators,
60  bool* output_masks,
61  size_t count);
62 
65  void Insert(const Tensor& input_keys,
66  const Tensor& input_values,
67  Tensor& output_iterators,
68  Tensor& output_masks);
69 
73  void Activate(const void* input_keys,
74  iterator_t* output_iterators,
75  bool* output_masks,
76  size_t count);
77 
81  void Activate(const Tensor& input_keys,
82  Tensor& output_iterators,
83  Tensor& output_masks);
84 
88  void Find(const void* input_keys,
89  iterator_t* output_iterators,
90  bool* output_masks,
91  size_t count);
92 
95  void Find(const Tensor& input_keys,
96  Tensor& output_iterators,
97  Tensor& output_masks);
98 
102  void Erase(const void* input_keys, bool* output_masks, size_t count);
103 
106  void Erase(const Tensor& input_keys, Tensor& output_masks);
107 
109  size_t GetIterators(iterator_t* output_iterators);
110 
114  void UnpackIterators(const iterator_t* input_iterators,
115  const bool* input_masks,
116  void* output_keys,
117  void* output_values,
118  size_t count);
119 
123  void AssignIterators(iterator_t* input_iterators,
124  const bool* input_masks,
125  const void* input_values,
126  size_t count);
127 
128  size_t Size() const;
129 
132  std::vector<size_t> BucketSizes() const;
133 
135  float LoadFactor() const;
136 
137  void AssertKeyDtype(const Dtype& dtype_key) const;
138  void AssertValueDtype(const Dtype& dtype_val) const;
139 
140  Dtype GetKeyDtype() const { return dtype_key_; }
141  Dtype GetValueDtype() const { return dtype_val_; }
142 
143  Device GetDevice() const { return device_hashmap_->GetDevice(); }
144 
145 private:
146  std::shared_ptr<DefaultDeviceHashmap> device_hashmap_;
147 
148  Dtype dtype_key_ = Dtype::Undefined;
149  Dtype dtype_val_ = Dtype::Undefined;
150 };
151 
152 } // namespace core
153 } // namespace open3d
size_t Size() const
Definition: Hashmap.cpp:219
void Rehash(size_t buckets)
Definition: Hashmap.cpp:55
const char const char value recording_handle imu_sample recording_handle uint8_t size_t data_size k4a_record_configuration_t config target_format k4a_capture_t capture_handle k4a_imu_sample_t imu_sample playback_handle k4a_logging_message_cb_t void min_level device_handle k4a_imu_sample_t timeout_in_ms capture_handle capture_handle capture_handle image_handle temperature_c k4a_image_t image_handle uint8_t image_handle image_handle image_handle image_handle uint32_t
Definition: K4aPlugin.cpp:554
Definition: Dtype.h:39
Device GetDevice() const
Definition: Hashmap.h:143
void UnpackIterators(const iterator_t *input_iterators, const bool *input_masks, void *output_keys, void *output_values, size_t count)
Definition: Hashmap.cpp:202
void Erase(const void *input_keys, bool *output_masks, size_t count)
Definition: Hashmap.cpp:174
Hashmap(size_t init_capacity, Dtype dtype_key, Dtype dtype_val, const Device &device)
Definition: Hashmap.cpp:45
Definition: Device.h:39
Definition: Traits.h:51
void AssertKeyDtype(const Dtype &dtype_key) const
Definition: Hashmap.cpp:227
static const Dtype Undefined
Definition: Dtype.h:41
int count
Definition: FilePCD.cpp:61
~Hashmap()
Definition: Hashmap.h:45
void AssertValueDtype(const Dtype &dtype_val) const
Definition: Hashmap.cpp:235
Dtype GetKeyDtype() const
Definition: Hashmap.h:140
Definition: PinholeCameraIntrinsic.cpp:35
Definition: Tensor.h:48
Dtype GetValueDtype() const
Definition: Hashmap.h:141
void Insert(const void *input_keys, const void *input_values, iterator_t *output_iterators, bool *output_masks, size_t count)
Definition: Hashmap.cpp:59
Definition: Hashmap.h:35
float LoadFactor() const
Return size / bucket_count.
Definition: Hashmap.cpp:225
void AssignIterators(iterator_t *input_iterators, const bool *input_masks, const void *input_values, size_t count)
Definition: Hashmap.cpp:211
std::vector< size_t > BucketSizes() const
Definition: Hashmap.cpp:221
void Find(const void *input_keys, iterator_t *output_iterators, bool *output_masks, size_t count)
Definition: Hashmap.cpp:140
size_t GetIterators(iterator_t *output_iterators)
Parallel collect all iterators in the hash table.
Definition: Hashmap.cpp:198
void Activate(const void *input_keys, iterator_t *output_iterators, bool *output_masks, size_t count)
Definition: Hashmap.cpp:106
static constexpr uint32_t kDefaultElemsPerBucket
Definition: Hashmap.h:37