Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build/
14 changes: 11 additions & 3 deletions bitvector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace bowen
if (n > std::numeric_limits<std::size_t>::max() / sizeof(T)) {
throw std::bad_alloc();
}

void *ptr = _mm_malloc(n * sizeof(T), ALIGN_SIZE);
if (!ptr) {
throw std::bad_alloc();
Expand Down Expand Up @@ -358,15 +358,23 @@ namespace bowen
{
reserve(m_capacity ? m_capacity * WORD_BITS * 2 : WORD_BITS);
}
(*this)[m_size++] = value;

size_t word_index = m_size >> WORD_SHIFT;
BitType mask = static_cast<BitType>(1)
<< (m_size & (WORD_BITS - 1));
if (value)
m_data[word_index] |= mask;
else
m_data[word_index] &= ~mask;
++m_size;
}

void reserve(size_t new_capacity)
{
if (new_capacity > m_capacity * WORD_BITS)
{
size_t new_word_count = num_words(new_capacity);

BitType *new_data = m_allocator.allocate(new_word_count);
std::copy(m_data, m_data + m_capacity, new_data);
deallocate_memory();
Expand Down