This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bool Trinity::updated_documents_scanner::test(const uint32_t id) noexcept | |
{ | |
if (id >= curBankRange.start()) | |
{ | |
if (id < curBankRange.stop()) | |
{ | |
return SwitchBitOps::Bitmap<uint64_t>::IsSet((uint64_t *)curBank, id - curBankRange.offset); | |
} | |
else if (skiplistBase == end) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifdef __OPTIMIZE__ | |
// Unformatelly, we can't tell if it was compiled with -O1, or higher | |
// It's not exposed to the compiled as a macro or feature | |
template<typename T1, typename T2> | |
static constexpr auto fastrange(const T1 word, const T2 p) | |
{ | |
return sizeof(T1) < sizeof(uint64_t) && sizeof(T2) < sizeof(uint64_t) ? fastrange32(word, p) : fastrange64(word, p); | |
} | |
#else | |
#define fastrange(a, b) ((a) % (b)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "llqhistogram.h" | |
#include <alloca.h> | |
#ifndef HAVE_SWITCH | |
#include <cmath> | |
#include <string.h> | |
#include <algorithm> | |
#endif | |
double const LLQHistogram::power_of_ten[256] = { | |
1, 10, 100, 1000, 10000, 100000, 1e+06, 1e+07, 1e+08, 1e+09, 1e+10, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://github.com/circonus-labs/libcircllhist | |
// https://support.circonus.com/support/solutions/articles/6000044580-architecture-of-an-analytics-and-storage-engine-for-time-series-data | |
// | |
// log-linear quantized histogram of data | |
// data-loss, not sample loss, accuracy loss. | |
// > strategically introducing time based error(stored by minute), upto 30 seconds of time error, value error that's well quantified, it's 2.5% on the upper by end by doing log-linear quantization of the values that | |
// > are coming in, so 112 becomes 110, it goes into the 110 to 120 bucket, and so we have some error in there. | |
#pragma once | |
#ifdef HAVE_SWITCH | |
#include <switch.h> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <memcachedclient.h> | |
#include <switch.h> | |
#include <tank_client.h> | |
#include <signal.h> | |
static bool running{true}; | |
static void sig_handler(int sig) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Our simple allocator; O(1) for allocations, just creates new banks when needed, deleting the allocator instance releases all memory | |
struct simple_allocator | |
: public Noncopyable | |
{ | |
enum class BackingStore : uint8_t | |
{ | |
MMAP = 1 | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This will crash clang++-3.7 | |
std::sort(list->begin(), list->end(), [](const fixup_candidate &c1, const fixup_candidate &c2) | |
{ | |
if (c2.rangeSpan < c1.rangeSpan) | |
return true; | |
else if (c2.rangeSpan == c1.rangeSpan) | |
return c2.candiate.len < c1.candidate.len; | |
else | |
return false; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Compile list of tokens based on deletions, and respecting max edit distance | |
// Original implementation would concatenate left/right string segments using memcpy() etc, but that didn't seem right | |
// The idea is, to instead partition S into 1+ segments and build hash from them, no need for memory copies etc. | |
// This is almost x8 times faster compared to that - but it's still in the 10s of microseconds range. | |
// | |
// ( for a 31 characters long string, with max edit distance = 2, it takes 24 microseconds, including the cost for computing the FNV rolling hash ) | |
#include <switch.h> | |
#include <switch_print.h> | |
#include <ansifmt.h> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Reverse iteration implementation for skip lists, that are not implemented as doubly-linked lists nodes. | |
// | |
// Based on idea from http://blog.memsql.com/the-story-behind-memsqls-skiplist-indexes/ | |
// You can use e.g [from, upto) ranges to limit the breadth; the idea is that keep track of the last node within the range | |
// for each subsequent layer you walk down, and then, for each segment, you push into a stack and iterate it in reverse | |
// This saves memory (no need for prev pointer, and according to @NikitaShamgunov: | |
// https://twitter.com/NikitaShamgunov/status/596167839796449281 " It is quite performant " | |
void Skiplist::foreach_reverse(std::function<void(const KVT k)> l) | |
{ | |
const node *ckpt[MAX_DEPTH + 1], *it = head; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static inline uint8_t RHeight(void) | |
{ | |
// Assuming probability 1/2 of an element appearing in layer i also appearing in layer i + 1 | |
// We can do the usual toss-the-coin dance, or we can just use RNG once and count the trailing zeros. | |
// Instead of using a loop to count, we can isolate the rightmost 0-bit, turn off all bits and sets that bit to 1, and then | |
// just compute count of trailing zeros instead. | |
const auto r = rand(); | |
const auto v = ~r & (r + 1); | |
const uint8_t tz = __builtin_ctz(v); |