This file contains hidden or 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
std::size_t random_for_random(const std::pair<std::size_t, std::size_t>& base_range, | |
const std::function<std::size_t(void)>& base_function, | |
const std::pair<std::size_t, std::size_t>& target_range) | |
{ | |
// The number of values in the base range | |
const std::size_t base_size = base_range.second - base_range.first + 1; | |
// The number of values in the target range | |
const std::size_t target_size = target_range.second - target_range.first + 1; | |
This file contains hidden or 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
void include(const v8::FunctionCallbackInfo<v8::Value>& file) | |
{ | |
auto isolate = file.GetIsolate(); | |
if (file.Length() != 1) | |
{ | |
auto message = v8::String::NewFromUtf8(isolate, | |
"Invalid number " | |
"of arguments!"); | |
v8::Exception::SyntaxError(message); |
This file contains hidden or 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
template<typename Container> | |
class LongestSubsequence | |
{ | |
public: | |
using size_t = unsigned int; | |
using cache_t = std::unordered_map<size_t, size_t>; | |
LongestSubsequence(const Container& container) |
This file contains hidden or 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
template<typename Key, typename Value> | |
class Dictionary | |
{ | |
public: | |
using size_t = std::size_t; | |
using pre_hash_t = std::function<size_t(const Key&)>; | |
static const size_t minimum_capacity = 20; |
This file contains hidden or 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
class Lookup | |
{ | |
public: | |
using size_t = std::size_t; | |
Lookup(const std::string& words) | |
{ | |
reset(words); | |
} |
This file contains hidden or 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
template<typename Iterator> | |
Iterator partition(Iterator begin, Iterator end) | |
{ | |
auto pivot = begin++; | |
if (pivot == end || begin == end) return pivot; | |
for (--end; begin != end; ++begin) | |
{ | |
while (begin != end && *begin < *pivot) ++begin; |
This file contains hidden or 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
template<typename Iterator> | |
Iterator part(Iterator begin, Iterator end) | |
{ | |
auto pivot = begin++; | |
if (pivot == begin || begin == end) return pivot; | |
for (--end; begin != end; ++begin) | |
{ | |
while (begin != end && *begin < *pivot) ++begin; |
This file contains hidden or 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
template<typename T, std::size_t N> | |
class NLargestHeap | |
{ | |
public: | |
using size_t = std::size_t; | |
static const size_t minimum_capacity = 10; | |
NLargestHeap(std::initializer_list<T> list, |
This file contains hidden or 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
template<typename Iterator> | |
class LongestOfOthers | |
{ | |
public: | |
using T = typename std::iterator_traits<Iterator>::value_type; | |
Iterator operator()(Iterator begin, Iterator end) | |
{ | |
if (begin == end) return end; |
This file contains hidden or 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
template<typename T> | |
class MedianKeeper | |
{ | |
public: | |
double insert(const T& value) | |
{ | |
if (is_empty() || value > _median) | |
{ | |
_right.push(value); |