modify bitset from deque to vector (#1696)

Signed-off-by: shengjun.li <shengjun.li@zilliz.com>
pull/1707/head
shengjun.li 2020-03-19 16:16:14 +08:00 committed by GitHub
parent fdd51400d2
commit 72ad100a90
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 8 deletions

View File

@ -19,12 +19,7 @@
namespace faiss {
ConcurrentBitset::ConcurrentBitset(id_type_t size) : size_(size) {
id_type_t bytes_count = (size >> 3) + 1;
// bitset_.resize(bytes_count, 0);
for (auto i = 0; i < bytes_count; ++i) {
bitset_.emplace_back(0);
}
ConcurrentBitset::ConcurrentBitset(id_type_t size) : size_(size), bitset_((size + 7) >> 3) {
}
bool
@ -42,4 +37,14 @@ ConcurrentBitset::clear(id_type_t id) {
bitset_[id >> 3].fetch_and(~(0x1 << (id & 0x7)));
}
ConcurrentBitset::id_type_t
ConcurrentBitset::size() {
return size_;
}
const unsigned char*
ConcurrentBitset::bitset() {
return reinterpret_cast<const unsigned char*>(bitset_.data());
}
} // namespace faiss

View File

@ -19,7 +19,7 @@
#include <atomic>
#include <memory>
#include <deque>
#include <vector>
namespace faiss {
@ -42,9 +42,16 @@ class ConcurrentBitset {
void
clear(id_type_t id);
id_type_t
size();
const unsigned char*
bitset();
private:
std::deque<std::atomic<unsigned char>> bitset_;
id_type_t size_;
std::vector<std::atomic<unsigned char>> bitset_;
};
using ConcurrentBitsetPtr = std::shared_ptr<ConcurrentBitset>;