21 const Dtype& key_dtype,
25 internal_ = std::make_shared<HashMap>(
26 init_capacity, key_dtype, key_element_shape, std::vector<Dtype>{},
27 std::vector<SizeVector>{}, device, backend);
33 Tensor output_buf_indices, output_masks;
34 Insert(input_keys, output_buf_indices, output_masks);
39 Tensor output_buf_indices, output_masks;
40 Find(input_keys, output_buf_indices, output_masks);
46 Erase(input_keys, output_masks);
53 return output_buf_indices;
57 Tensor& output_buf_indices,
59 internal_->Insert(input_keys, std::vector<Tensor>{}, output_buf_indices,
64 Tensor& output_buf_indices,
66 internal_->Find(input_keys, output_buf_indices, output_masks);
70 internal_->Erase(input_keys, output_masks);
74 internal_->GetActiveIndices(output_buf_indices);
90 return HashSet(internal_cloned);
94 HashMap internal_converted = internal_->To(device,
copy);
95 return HashSet(internal_converted);
109 return internal_->BucketSizes();
115 return internal_->GetDeviceHashBackend();
119 internal_ = std::make_shared<HashMap>(internal_hashmap);
void Save(const std::string &file_name)
std::pair< Tensor, Tensor > Find(const Tensor &input_keys)
int64_t Size() const
Get the size (number of active entries) of the hash set.
void Clear()
Clear stored map without reallocating the buffers.
Tensor GetKeyTensor() const
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.
static HashSet Load(const std::string &file_name)
Load active keys and values from a npz file that contains 'key'.
void Reserve(int64_t capacity)
Reserve the internal hash map with the capcity by rehashing.
int64_t GetBucketCount() const
Get the number of buckets of the internal hash set.
std::shared_ptr< DeviceHashBackend > GetDeviceHashBackend() const
Return the implementation of the device hash backend.
int64_t GetCapacity() const
Get the capacity of the hash set.
Tensor GetActiveIndices() const
float LoadFactor() const
Return size / bucket_count.
std::pair< Tensor, Tensor > Insert(const Tensor &input_keys)
HashSet To(const Device &device, bool copy=false) const
Convert the hash set to another device.
HashSet Clone() const
Clone the hash set with buffers.
std::vector< int64_t > BucketSizes() const
Return number of elements per bucket.
Tensor Erase(const Tensor &input_keys)
Device GetDevice() const override
Get the device of the hash set.
Helper functions for the ml ops.
CLOUDVIEWER_HOST_DEVICE Pair< First, Second > make_pair(const First &_first, const Second &_second)
core::HashMap ReadHashMap(const std::string &file_name)
void WriteHashMap(const std::string &file_name, const core::HashMap &hashmap)
Generic file read and write utility for python interface.