Open3D (C++ API)  0.17.0
HashSet.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - Open3D: www.open3d.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2023 www.open3d.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
10 #include "open3d/core/Device.h"
11 #include "open3d/core/Dtype.h"
12 #include "open3d/core/Tensor.h"
15 
16 namespace open3d {
17 namespace core {
18 
19 class HashSet : public core::IsDevice {
20 public:
22  HashSet(int64_t init_capacity,
23  const Dtype& key_dtype,
24  const SizeVector& key_element_shape,
25  const Device& device,
26  const HashBackendType& backend = HashBackendType::Default);
27 
29  ~HashSet() = default;
30 
32  void Reserve(int64_t capacity);
33 
42  std::pair<Tensor, Tensor> Insert(const Tensor& input_keys);
43 
48  std::pair<Tensor, Tensor> Find(const Tensor& input_keys);
49 
53  Tensor Erase(const Tensor& input_keys);
54 
58  Tensor GetActiveIndices() const;
59 
63  void Insert(const Tensor& input_keys,
64  Tensor& output_buf_indices,
65  Tensor& output_masks);
66 
70  void Find(const Tensor& input_keys,
71  Tensor& output_buf_indices,
72  Tensor& output_masks);
73 
76  void Erase(const Tensor& input_keys, Tensor& output_masks);
77 
80  void GetActiveIndices(Tensor& output_buf_indices) const;
81 
83  void Clear();
84 
88  void Save(const std::string& file_name);
89 
91  static HashSet Load(const std::string& file_name);
92 
94  HashSet Clone() const;
95 
97  HashSet To(const Device& device, bool copy = false) const;
98 
100  int64_t Size() const;
101 
103  int64_t GetCapacity() const;
104 
106  int64_t GetBucketCount() const;
107 
109  Device GetDevice() const override;
110 
114  Tensor GetKeyTensor() const;
115 
117  std::vector<int64_t> BucketSizes() const;
118 
120  float LoadFactor() const;
121 
123  std::shared_ptr<DeviceHashBackend> GetDeviceHashBackend() const;
124 
125 private:
126  HashSet(const HashMap& internal_hashmap);
127  std::shared_ptr<HashMap> internal_;
128 };
129 
130 } // namespace core
131 } // namespace open3d
bool copy
Definition: VtkUtils.cpp:73
Definition: Device.h:18
Definition: Dtype.h:20
Definition: HashMap.h:22
Definition: HashSet.h:19
Tensor GetKeyTensor() const
Definition: HashSet.cpp:105
void Reserve(int64_t capacity)
Reserve the internal hash map with the capcity by rehashing.
Definition: HashSet.cpp:29
int64_t GetCapacity() const
Get the capacity of the hash set.
Definition: HashSet.cpp:99
Tensor GetActiveIndices() const
Definition: HashSet.cpp:49
HashSet To(const Device &device, bool copy=false) const
Convert the hash set to another device.
Definition: HashSet.cpp:92
int64_t GetBucketCount() const
Get the number of buckets of the internal hash set.
Definition: HashSet.cpp:101
~HashSet()=default
Default destructor.
std::pair< Tensor, Tensor > Insert(const Tensor &input_keys)
Definition: HashSet.cpp:31
void Clear()
Clear stored map without reallocating the buffers.
Definition: HashSet.cpp:76
int64_t Size() const
Get the size (number of active entries) of the hash set.
Definition: HashSet.cpp:97
std::vector< int64_t > BucketSizes() const
Return number of elements per bucket.
Definition: HashSet.cpp:107
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:19
std::pair< Tensor, Tensor > Find(const Tensor &input_keys)
Definition: HashSet.cpp:37
std::shared_ptr< DeviceHashBackend > GetDeviceHashBackend() const
Return the implementation of the device hash backend.
Definition: HashSet.cpp:113
float LoadFactor() const
Return size / bucket_count.
Definition: HashSet.cpp:111
void Save(const std::string &file_name)
Definition: HashSet.cpp:78
Tensor Erase(const Tensor &input_keys)
Definition: HashSet.cpp:43
HashSet Clone() const
Clone the hash set with buffers.
Definition: HashSet.cpp:87
Device GetDevice() const override
Get the device of the hash set.
Definition: HashSet.cpp:103
static HashSet Load(const std::string &file_name)
Load active keys and values from a npz file that contains 'key'.
Definition: HashSet.cpp:82
Definition: Device.h:88
Definition: SizeVector.h:69
Definition: Tensor.h:32
HashBackendType
Definition: HashMap.h:20
Definition: PinholeCameraIntrinsic.cpp:16