ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
HashSet.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
11 #include "cloudViewer/core/Dtype.h"
15 
16 namespace cloudViewer {
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 cloudViewer
cloudViewer
Generic file read and write utility for python interface.
Definition: CloudViewerConfig.cpp:12
cloudViewer::core::HashSet::GetActiveIndices
Tensor GetActiveIndices() const
Definition: HashSet.cpp:50
Device.h
cloudViewer::core::make_pair
CLOUDVIEWER_HOST_DEVICE Pair< First, Second > make_pair(const First &_first, const Second &_second)
Definition: SlabTraits.h:49
copy
bool copy
Definition: VtkUtils.cpp:74
cloudViewer::t::io::ReadHashMap
core::HashMap ReadHashMap(const std::string &file_name)
Definition: HashMapIO.cpp:48
cloudViewer::core::HashSet::Reserve
void Reserve(int64_t capacity)
Reserve the internal hash map with the capcity by rehashing.
Definition: HashSet.cpp:30
cloudViewer::core::HashMap
Definition: HashMap.h:23
cloudViewer::core::HashSet::Erase
Tensor Erase(const Tensor &input_keys)
Definition: HashSet.cpp:44
cloudViewer::core::Tensor
Definition: Tensor.h:32
cloudViewer::core::Dtype
Definition: Dtype.h:21
cloudViewer::core::HashSet::LoadFactor
float LoadFactor() const
Return size / bucket_count.
Definition: HashSet.cpp:112
cloudViewer::core::HashSet::Clear
void Clear()
Clear stored map without reallocating the buffers.
Definition: HashSet.cpp:77
cloudViewer::core::HashSet::~HashSet
~HashSet()=default
Default destructor.
cloudViewer::core::HashSet::GetCapacity
int64_t GetCapacity() const
Get the capacity of the hash set.
Definition: HashSet.cpp:100
cloudViewer::core::HashSet::Size
int64_t Size() const
Get the size (number of active entries) of the hash set.
Definition: HashSet.cpp:98
cloudViewer::core::HashSet::Load
static HashSet Load(const std::string &file_name)
Load active keys and values from a npz file that contains 'key'.
Definition: HashSet.cpp:83
cloudViewer::core::HashSet::Find
std::pair< Tensor, Tensor > Find(const Tensor &input_keys)
Definition: HashSet.cpp:38
HashBackendBuffer.h
cloudViewer::core::HashSet::GetBucketCount
int64_t GetBucketCount() const
Get the number of buckets of the internal hash set.
Definition: HashSet.cpp:102
cloudViewer::core::HashSet::GetDevice
Device GetDevice() const override
Get the device of the hash set.
Definition: HashSet.cpp:104
cloudViewer::core::Device
Definition: Device.h:18
cloudViewer::core::HashSet::Clone
HashSet Clone() const
Clone the hash set with buffers.
Definition: HashSet.cpp:88
cloudViewer::core::HashSet
Definition: HashSet.h:19
core
cloudViewer::core::HashSet::HashSet
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:20
cloudViewer::core::HashSet::Insert
std::pair< Tensor, Tensor > Insert(const Tensor &input_keys)
Definition: HashSet.cpp:32
cloudViewer::core::SizeVector
Definition: SizeVector.h:70
HashMap.h
HashSet.h
cloudViewer::core::HashBackendType::Default
@ Default
cloudViewer::core::HashSet::To
HashSet To(const Device &device, bool copy=false) const
Convert the hash set to another device.
Definition: HashSet.cpp:93
cloudViewer::core::HashBackendType
HashBackendType
Definition: HashMap.h:21
cloudViewer::core::HashSet::Save
void Save(const std::string &file_name)
Definition: HashSet.cpp:79
cloudViewer::core::HashSet::GetKeyTensor
Tensor GetKeyTensor() const
Definition: HashSet.cpp:106
Tensor.h
cloudViewer::core::IsDevice
Definition: Device.h:88
cloudViewer::t::io::WriteHashMap
void WriteHashMap(const std::string &file_name, const core::HashMap &hashmap)
Definition: HashMapIO.cpp:17
HashMapIO.h
cloudViewer::core::HashSet::BucketSizes
std::vector< int64_t > BucketSizes() const
Return number of elements per bucket.
Definition: HashSet.cpp:108
Dtype.h
cloudViewer::core::HashSet::GetDeviceHashBackend
std::shared_ptr< DeviceHashBackend > GetDeviceHashBackend() const
Return the implementation of the device hash backend.
Definition: HashSet.cpp:114
DeviceHashBackend.h