Loading [MathJax]/extensions/TeX/AMSsymbols.js
Open3D (C++ API)  0.14.1
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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/Dtype.h"
30 #include "open3d/core/Tensor.h"
33 
34 namespace open3d {
35 namespace core {
36 
37 class HashSet {
38 public:
40  HashSet(int64_t init_capacity,
41  const Dtype& key_dtype,
42  const SizeVector& key_element_shape,
43  const Device& device,
44  const HashBackendType& backend = HashBackendType::Default);
45 
47  ~HashSet() = default;
48 
50  void Reserve(int64_t capacity);
51 
60  std::pair<Tensor, Tensor> Insert(const Tensor& input_keys);
61 
66  std::pair<Tensor, Tensor> Find(const Tensor& input_keys);
67 
71  Tensor Erase(const Tensor& input_keys);
72 
76  Tensor GetActiveIndices() const;
77 
81  void Insert(const Tensor& input_keys,
82  Tensor& output_buf_indices,
83  Tensor& output_masks);
84 
88  void Find(const Tensor& input_keys,
89  Tensor& output_buf_indices,
90  Tensor& output_masks);
91 
94  void Erase(const Tensor& input_keys, Tensor& output_masks);
95 
98  void GetActiveIndices(Tensor& output_buf_indices) const;
99 
101  void Clear();
102 
106  void Save(const std::string& file_name);
107 
109  static HashSet Load(const std::string& file_name);
110 
112  HashSet Clone() const;
113 
115  HashSet To(const Device& device, bool copy = false) const;
116 
118  int64_t Size() const;
119 
121  int64_t GetCapacity() const;
122 
124  int64_t GetBucketCount() const;
125 
127  Device GetDevice() const;
128 
132  Tensor GetKeyTensor() const;
133 
135  std::vector<int64_t> BucketSizes() const;
136 
138  float LoadFactor() const;
139 
141  std::shared_ptr<DeviceHashBackend> GetDeviceHashBackend() const;
142 
143 private:
144  HashSet(const HashMap& internal_hashmap);
145  std::shared_ptr<HashMap> internal_;
146 };
147 
148 } // namespace core
149 } // namespace open3d
int64_t GetCapacity() const
Get the capacity of the hash set.
Definition: HashSet.cpp:118
HashSet To(const Device &device, bool copy=false) const
Convert the hash set to another device.
Definition: HashSet.cpp:111
std::vector< int64_t > BucketSizes() const
Return number of elements per bucket.
Definition: HashSet.cpp:126
void Save(const std::string &file_name)
Definition: HashSet.cpp:97
HashBackendType
Definition: HashMap.h:38
Definition: Dtype.h:39
void Reserve(int64_t capacity)
Reserve the internal hash map with the capcity by rehashing.
Definition: HashSet.cpp:48
Tensor Erase(const Tensor &input_keys)
Definition: HashSet.cpp:62
std::pair< Tensor, Tensor > Find(const Tensor &input_keys)
Definition: HashSet.cpp:56
Definition: SizeVector.h:79
std::pair< Tensor, Tensor > Insert(const Tensor &input_keys)
Definition: HashSet.cpp:50
int64_t GetBucketCount() const
Get the number of buckets of the internal hash set.
Definition: HashSet.cpp:120
int64_t Size() const
Get the size (number of active entries) of the hash set.
Definition: HashSet.cpp:116
float LoadFactor() const
Return size / bucket_count.
Definition: HashSet.cpp:130
Tensor GetActiveIndices() const
Definition: HashSet.cpp:68
Definition: HashSet.h:37
~HashSet()=default
Default destructor.
Definition: Device.h:39
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
Definition: HashMap.h:40
static HashSet Load(const std::string &file_name)
Load active keys and values from a npz file that contains &#39;key&#39;.
Definition: HashSet.cpp:101
Definition: PinholeCameraIntrinsic.cpp:35
Definition: Tensor.h:50
Tensor GetKeyTensor() const
Definition: HashSet.cpp:124
Device GetDevice() const
Get the device of the hash set.
Definition: HashSet.cpp:122
void Clear()
Clear stored map without reallocating the buffers.
Definition: HashSet.cpp:95
HashSet Clone() const
Clone the hash set with buffers.
Definition: HashSet.cpp:106
std::shared_ptr< DeviceHashBackend > GetDeviceHashBackend() const
Return the implementation of the device hash backend.
Definition: HashSet.cpp:132