void Corpus::find_trigram(uint32_t trgm, function<void(const Trigram *trgmptr, size_t len)> cb)
{
uint32_t bucket = hash_trigram(trgm, hdr.hashtable_size);
- engine->submit_read(fd, sizeof(Trigram) * (hdr.extra_ht_slots + 2), hdr.hash_table_offset_bytes + sizeof(Trigram) * bucket, [this, trgm, bucket, cb{ move(cb) }](string s) {
+ engine->submit_read(fd, sizeof(Trigram) * (hdr.extra_ht_slots + 2), hdr.hash_table_offset_bytes + sizeof(Trigram) * bucket, [this, trgm, cb{ move(cb) }](string s) {
const Trigram *trgmptr = reinterpret_cast<const Trigram *>(s.data());
for (unsigned i = 0; i < hdr.extra_ht_slots + 1; ++i) {
if (trgmptr[i].trgm == trgm) {
if (done)
break;
}
- engine.submit_read(fd, len, trgmptr.offset, [trgmptr, len, &done, &in1, &in2, &out](string s) {
+ engine.submit_read(fd, len, trgmptr.offset, [trgmptr{trgmptr}, len{len}, &done, &in1, &in2, &out](string s) {
if (done)
return;
uint32_t trgm __attribute__((unused)) = trgmptr.trgm;
#include "turbopfor-common.h"
+#include <algorithm>
+
#include <assert.h>
#include <limits.h>
#include <stdint.h>
+#include <string.h>
template<class Docid>
void write_le(Docid val, void *out)
} else if constexpr (sizeof(Docid) == 2) {
val = htole16(val);
} else if constexpr (sizeof(Docid) == 1) {
- val = val;
+ // No change.
} else {
assert(false);
}
// delta-plus-1 is implemented, and only 32-bit docids are tested),
// but aim to be more portable and (ideally) easier-to-understand.
// In particular, they will compile on x86 without SSE4.1 or AVX support.
+// Unlike the reference code, only GCC and GCC-compatible compilers
+// (e.g. Clang) are supported.
//
// The main reference is https://michael.stapelberg.ch/posts/2019-02-05-turbopfor-analysis/,
// although some implementation details have been worked out by studying the