Skip to content
Open
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
17 changes: 8 additions & 9 deletions include/pisa/mappable/mappable_vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@

#include <algorithm>
#include <vector>

#include "boost/function.hpp"
#include "boost/lambda/bind.hpp"
#include "boost/lambda/construct.hpp"
#include "boost/range.hpp"
#include "boost/utility.hpp"

#include "util/intrinsics.hpp"

namespace pisa { namespace mapper {
Expand All @@ -19,7 +15,7 @@ namespace pisa { namespace mapper {
class sizeof_visitor;
} // namespace detail

using deleter_t = boost::function<void()>;
using deleter_t = std::function<void()>;

template <typename T> // T must be a POD
class mappable_vector {
Expand All @@ -38,15 +34,16 @@ namespace pisa { namespace mapper {
explicit mappable_vector(Range const& from) : m_data(0), m_size(0) {
size_t size = boost::size(from);
T* data = new T[size];
m_deleter = boost::lambda::bind(boost::lambda::delete_array(), data);

m_deleter = [&data]() {
delete[] data;
};
std::copy(boost::begin(from), boost::end(from), data);
m_data = data;
m_size = size;
}

~mappable_vector() {
if (not m_deleter.empty()) {
if (m_deleter) {
m_deleter();
}
}
Expand All @@ -66,7 +63,9 @@ namespace pisa { namespace mapper {
if (m_size > 0) {
auto* new_vec = new std::vector<T>;
new_vec->swap(vec);
m_deleter = boost::lambda::bind(boost::lambda::delete_ptr(), new_vec);
m_deleter = [&new_vec]() {
delete new_vec;
};
m_data = &(*new_vec)[0];
}
}
Expand Down
3 changes: 2 additions & 1 deletion include/pisa/wand_data_raw.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class wand_data_raw {
);
block_docid.insert(block_docid.end(), t.first.begin(), t.first.end());
max_term_weight.push_back(*(std::max_element(t.second.begin(), t.second.end())));
blocks_start.push_back(t.first.size() + blocks_start.back());
blocks_start.push_back(t.first.size());

total_elements += seq.docs.size();
total_blocks += t.first.size();
Expand All @@ -72,6 +72,7 @@ class wand_data_raw {

void build(wand_data_raw& wdata) {
wdata.m_block_max_term_weight.steal(block_max_term_weight);
std::partial_sum(blocks_start.cbegin(), blocks_start.cend(), blocks_start.begin());
wdata.m_blocks_start.steal(blocks_start);
wdata.m_block_docid.steal(block_docid);
spdlog::info(
Expand Down
46 changes: 45 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,51 @@ include(Catch)
add_library(testlib in_memory_index.cpp)
target_link_libraries(testlib pisa)

file(GLOB TEST_SOURCES test_*.cpp)
#file(GLOB TEST_SOURCES test_*.cpp)
file(GLOB TEST_SOURCES
test_algorithm.cpp
test_bit_vector.cpp
test_block_codecs.cpp
test_block_freq_index.cpp
test_block_posting_list.cpp
test_bmw_queries.cpp
test_compact_elias_fano.cpp
test_compact_ranked_bitvector.cpp
test_compress.cpp
test_cow_string.cpp
test_cursors.cpp
test_forward_index.cpp
test_forward_index_builder.cpp
test_freq_index.cpp
test_html.cpp
test_indexed_sequence.cpp
test_intersection.cpp
test_invert.cpp
test_linear_quantizer.cpp
test_mapper.cpp
test_memory.cpp
test_memory_source.cpp
test_partition_fwd_index.cpp
test_partitioned_sequence.cpp
test_payload_vector.cpp
test_positive_sequence.cpp
test_ranked_queries.cpp
test_recursive_graph_bisection.cpp
test_sample_inverted_index.cpp
test_scorer.cpp
test_sequence_collection.cpp
test_stream_builder.cpp
test_strict_elias_fano.cpp
test_taily_stats.cpp
test_text_analyzer.cpp
test_token_filter.cpp
test_token_stream.cpp
test_tokenizer.cpp
test_topk_queue.cpp
test_trec_topic_reader.cpp
test_uniform_partitioned_sequence.cpp
test_wand_data.cpp
)
foreach(TEST_SRC ${TEST_SOURCES})
get_filename_component (TEST_SRC_NAME ${TEST_SRC} NAME_WE)
add_executable(${TEST_SRC_NAME} ${TEST_SRC})
Expand Down
2 changes: 1 addition & 1 deletion test/test_linear_quantizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ TEST_CASE("LinearQuantizer", "[scoring][unit]") {
CAPTURE(max);
pisa::LinearQuantizer quantizer(max, bits);
REQUIRE(quantizer(0) == 1);
REQUIRE(quantizer(max) == (1 << bits) - 1);
REQUIRE(quantizer(max) == (1ULL << bits) - 1);
}
}