Skip to content

Instantly share code, notes, and snippets.

View igorburago's full-sized avatar

Igor Burago igorburago

View GitHub Profile
@igorburago
igorburago / partsort.c
Last active October 21, 2025 16:14
Fast partial sorting of an array on a rank subinterval
// Copyright 2025 Igor Burago. Released under the ISC License.
#include <limits.h> // CHAR_BIT
#include <stddef.h> // ptrdiff_t
#include <stdint.h>
#include <string.h> // memcpy(), memmove(), memset()
// Built-in u128 is not strictly required, but it makes it easier to guarantee
// the absence of overflows during sampling in rank_partition() for all possible
// input array lengths. It also simplifies the implementation of the mcg64 RNG.
@igorburago
igorburago / xorab.c
Last active October 5, 2025 07:53
Finding all solutions of the equation x⊕(a-x)=b
// Copyright 2013 Igor Burago. Released under the ISC License.
#include <limits.h>
#include <stdio.h>
static unsigned
enum_bit(unsigned q, unsigned x, unsigned *xs) {
if (q == 0) {
*xs = x;
return 1;
@igorburago
igorburago / indentguides.vim
Last active October 5, 2025 03:29
Vim indentation guides emulation
" Copyright 2022 Igor Burago. Released under the ISC License.
" Simple emulation of indentation guides.
"
" For tab-based indentation, using the 'listchars' option works fine.
" For space-based indentation, one can either:
" • use the match highlighting feature (see ':help match-highlight'),
" as shown in ToggleMatchHighlightIndentGuides(); or
" • use the 'leadmultispace' setting of the 'listchars' option (added
" in Vim 9.0), as shown in ToggleListCharsIndentGuides().