Open3D (C++ API)  0.16.1
HashSet.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-2021 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#pragma once
28
29#include "open3d/core/Device.h"
30#include "open3d/core/Dtype.h"
31#include "open3d/core/Tensor.h"
34
35namespace open3d {
36namespace core {
37
38class HashSet : public core::IsDevice {
39public:
41 HashSet(int64_t init_capacity,
42 const Dtype& key_dtype,
43 const SizeVector& key_element_shape,
44 const Device& device,
46
48 ~HashSet() = default;
49
51 void Reserve(int64_t capacity);
52
61 std::pair<Tensor, Tensor> Insert(const Tensor& input_keys);
62
67 std::pair<Tensor, Tensor> Find(const Tensor& input_keys);
68
72 Tensor Erase(const Tensor& input_keys);
73
78
82 void Insert(const Tensor& input_keys,
83 Tensor& output_buf_indices,
84 Tensor& output_masks);
85
89 void Find(const Tensor& input_keys,
90 Tensor& output_buf_indices,
91 Tensor& output_masks);
92
95 void Erase(const Tensor& input_keys, Tensor& output_masks);
96
99 void GetActiveIndices(Tensor& output_buf_indices) const;
100
102 void Clear();
103
107 void Save(const std::string& file_name);
108
110 static HashSet Load(const std::string& file_name);
111
113 HashSet Clone() const;
114
116 HashSet To(const Device& device, bool copy = false) const;
117
119 int64_t Size() const;
120
122 int64_t GetCapacity() const;
123
125 int64_t GetBucketCount() const;
126
128 Device GetDevice() const override;
129
133 Tensor GetKeyTensor() const;
134
136 std::vector<int64_t> BucketSizes() const;
137
139 float LoadFactor() const;
140
142 std::shared_ptr<DeviceHashBackend> GetDeviceHashBackend() const;
143
144private:
145 HashSet(const HashMap& internal_hashmap);
146 std::shared_ptr<HashMap> internal_;
147};
148
149} // namespace core
150} // namespace open3d
bool copy
Definition: VtkUtils.cpp:89
Definition: Device.h:37
Definition: Dtype.h:39
Definition: HashMap.h:41
Definition: HashSet.h:38
Tensor GetKeyTensor() const
Definition: HashSet.cpp:124
void Reserve(int64_t capacity)
Reserve the internal hash map with the capcity by rehashing.
Definition: HashSet.cpp:48
int64_t GetCapacity() const
Get the capacity of the hash set.
Definition: HashSet.cpp:118
Tensor GetActiveIndices() const
Definition: HashSet.cpp:68
HashSet To(const Device &device, bool copy=false) const
Convert the hash set to another device.
Definition: HashSet.cpp:111
int64_t GetBucketCount() const
Get the number of buckets of the internal hash set.
Definition: HashSet.cpp:120
~HashSet()=default
Default destructor.
std::pair< Tensor, Tensor > Insert(const Tensor &input_keys)
Definition: HashSet.cpp:50
void Clear()
Clear stored map without reallocating the buffers.
Definition: HashSet.cpp:95
int64_t Size() const
Get the size (number of active entries) of the hash set.
Definition: HashSet.cpp:116
std::vector< int64_t > BucketSizes() const
Return number of elements per bucket.
Definition: HashSet.cpp:126
HashSet(int64_t init_capacity, const Dtype &key_dtype, const SizeVector &key_element_shape, const Device &device, const HashBackendType &backend=HashBackendType::Default)
Initialize a hash set given a key dtype and element shape.
Definition: HashSet.cpp:38
std::pair< Tensor, Tensor > Find(const Tensor &input_keys)
Definition: HashSet.cpp:56
std::shared_ptr< DeviceHashBackend > GetDeviceHashBackend() const
Return the implementation of the device hash backend.
Definition: HashSet.cpp:132
float LoadFactor() const
Return size / bucket_count.
Definition: HashSet.cpp:130
void Save(const std::string &file_name)
Definition: HashSet.cpp:97
Tensor Erase(const Tensor &input_keys)
Definition: HashSet.cpp:62
HashSet Clone() const
Clone the hash set with buffers.
Definition: HashSet.cpp:106
Device GetDevice() const override
Get the device of the hash set.
Definition: HashSet.cpp:122
static HashSet Load(const std::string &file_name)
Load active keys and values from a npz file that contains 'key'.
Definition: HashSet.cpp:101
Definition: Device.h:107
Definition: SizeVector.h:88
Definition: Tensor.h:51
HashBackendType
Definition: HashMap.h:39
Definition: PinholeCameraIntrinsic.cpp:35