-
Notifications
You must be signed in to change notification settings - Fork 20
Raw vectors data layer in HNSW + move to base class [MOD-7496] #523
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 8 commits
aa7eeaf
7055dd9
1690b8f
f0b8eee
c709ffb
d38e34a
7b02977
a2c9145
ff843ac
fcbbe0e
3cf06af
f4ffbbb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
#include "data_blocks_container.h" | ||
#include "VecSim/utils/serializer.h" | ||
|
||
DataBlocksContainer::DataBlocksContainer(size_t blockSize, size_t elementBytesCount, | ||
std::shared_ptr<VecSimAllocator> allocator, | ||
|
@@ -10,6 +11,8 @@ DataBlocksContainer::~DataBlocksContainer() = default; | |
|
||
size_t DataBlocksContainer::size() const { return element_count; } | ||
|
||
size_t DataBlocksContainer::capacity() const { return blocks.capacity(); } | ||
|
||
size_t DataBlocksContainer::blockSize() const { return block_size; } | ||
|
||
size_t DataBlocksContainer::elementByteCount() const { return element_bytes_count; } | ||
|
@@ -51,6 +54,51 @@ std::unique_ptr<RawDataContainer::Iterator> DataBlocksContainer::getIterator() c | |
return std::make_unique<DataBlocksContainer::Iterator>(*this); | ||
} | ||
|
||
#ifdef BUILD_TESTS | ||
void DataBlocksContainer::saveBlocks(std::ostream &output) const { | ||
// Save number of blocks | ||
unsigned int num_blocks = this->numBlocks(); | ||
Serializer::writeBinaryPOD(output, num_blocks); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should consider only saving the vectors without the metadata about the number of blocks and their sizes, so we can load them into other containers (or to different block sizes) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This also means we don't need to add serialization to the container class, keeping it on the algorithm level |
||
|
||
// Save data blocks | ||
for (size_t i = 0; i < num_blocks; i++) { | ||
auto &block = this->blocks[i]; | ||
unsigned int block_len = block.getLength(); | ||
Serializer::writeBinaryPOD(output, block_len); | ||
for (size_t j = 0; j < block_len; j++) { | ||
output.write(block.getElement(j), this->element_bytes_count); | ||
} | ||
} | ||
} | ||
|
||
void DataBlocksContainer::restoreBlocks(std::istream &input) { | ||
|
||
// Get number of blocks | ||
unsigned int num_blocks = 0; | ||
Serializer::readBinaryPOD(input, num_blocks); | ||
this->blocks.reserve(num_blocks); | ||
|
||
// Get data blocks | ||
for (size_t i = 0; i < num_blocks; i++) { | ||
this->blocks.emplace_back(this->block_size, this->element_bytes_count, this->allocator, | ||
this->alignment); | ||
unsigned int block_len = 0; | ||
Serializer::readBinaryPOD(input, block_len); | ||
for (size_t j = 0; j < block_len; j++) { | ||
auto cur_vec = this->getAllocator()->allocate_unique(this->element_bytes_count); | ||
input.read(static_cast<char *>(cur_vec.get()), | ||
(std::streamsize)this->element_bytes_count); | ||
this->blocks.back().addElement(cur_vec.get()); | ||
this->element_count++; | ||
} | ||
} | ||
} | ||
|
||
void DataBlocksContainer::shrinkToFit() { this->blocks.shrink_to_fit(); } | ||
|
||
size_t DataBlocksContainer::numBlocks() const { return this->blocks.size(); } | ||
|
||
#endif | ||
/********************************** Iterator API ************************************************/ | ||
|
||
DataBlocksContainer::Iterator::Iterator(const DataBlocksContainer &container_) | ||
|
Uh oh!
There was an error while loading. Please reload this page.