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 <string.h> | |
/* Compare no more than N characters of S1 and S2, | |
returning less than, equal to or greater than zero | |
if S1 is lexicographically less than, equal to or | |
greater than S2. */ | |
int | |
STRNCMP (const char *s1, const char *s2, size_t n) | |
{ | |
unsigned char c1 = '\0'; |
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 <algorithm> | |
#include <cmath> | |
#include <iostream> | |
#include <iterator> | |
#include <random> | |
#include <vector> | |
class AlgorithmL { | |
private: | |
std::vector<double> reservoir; |
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 <cstddef> | |
#include <cstdint> | |
#include <cuchar> | |
size_t utf8_length_from_utf32(const char32_t* buf, size_t len) { | |
// We are not BOM aware. | |
const uint32_t* p = reinterpret_cast<const uint32_t*>(buf); | |
size_t counter{0}; | |
for (size_t i = 0; i < len; i++) { | |
/** ASCII **/ |
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
use criterion::{criterion_group, criterion_main, Criterion}; | |
fn new_with_push(name: &str) -> Vec<&str> { | |
let mut v = Vec::new(); | |
v.push(name); | |
v | |
} | |
fn new_with_macro(name: &str) -> Vec<&str> { | |
vec![name] |
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
use criterion::{criterion_group, criterion_main, Criterion}; | |
pub fn to_vec1(s: &[u32]) -> Vec<u32> { | |
struct DropGuard<'a> { | |
vec: &'a mut Vec<u32>, | |
num_init: usize, | |
} | |
impl<'a> Drop for DropGuard<'a> { | |
#[inline] | |
fn drop(&mut self) { |
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
use criterion::{criterion_group, criterion_main, Criterion}; | |
fn sort_by_words1(name: &str) -> String { | |
let mut split_words: Vec<&str> = name.split('_').collect(); | |
// We are sorting primitive &strs and can use unstable sort here. | |
split_words.sort_unstable(); | |
split_words.join("_") | |
} | |
fn sort_by_words2(name: &str) -> Vec<&str> { |
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
use criterion::{criterion_group, criterion_main, Criterion}; | |
use std::str; | |
pub const MAX_BASE: usize = 64; | |
pub const ALPHANUMERIC_ONLY: usize = 62; | |
pub const CASE_INSENSITIVE: usize = 36; | |
const BASE_64: &[u8; MAX_BASE] = | |
b"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@$"; |
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
use criterion::{criterion_group, criterion_main, Criterion}; | |
use std::str; | |
pub const MAX_BASE: usize = 64; | |
pub const ALPHANUMERIC_ONLY: usize = 62; | |
pub const CASE_INSENSITIVE: usize = 36; | |
const BASE_64: &[u8; MAX_BASE] = | |
b"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@$"; |
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
pub fn binary_search_slice_new<'d, E, K>(data: &'d [E], key_fn: impl Fn(&E) -> K, key: &K) -> &'d [E] | |
where | |
K: Ord, | |
{ | |
let size = data.len(); | |
let start = data.partition_point(|x| key_fn(x) < *key); | |
// At this point `start` either points at the first entry with equal or | |
// greater key or is equal to `size` in case all elements have smaller keys | |
// Invariant: start == size || key_fn(&data[start]) >= *key | |
if start == size || key_fn(&data[start]) != *key { |
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
template <class _AlgPolicy, class _Compare, class _Iter, class _Sent, class _Tp, class _Proj> | |
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 pair<_Iter, _Iter> | |
__equal_range(_Iter __first, _Sent __last, const _Tp& __value, _Compare&& __comp, _Proj&& __proj) { | |
auto __len = _IterOps<_AlgPolicy>::distance(__first, __last); | |
_Iter __end = _IterOps<_AlgPolicy>::next(__first, __last); | |
while (__len != 0) { | |
auto __half_len = std::__half_positive(__len); | |
_Iter __mid = _IterOps<_AlgPolicy>::next(__first, __half_len); | |
if (std::__invoke(__comp, std::__invoke(__proj, *__mid), __value)) { | |
__first = ++__mid; |
NewerOlder