Skip to content

Instantly share code, notes, and snippets.

@igorburago
igorburago / partsort.c
Last active June 2, 2024 11:37
Fast partial sorting of an array on a subinterval
/* Copyright 2024 Igor Burago. Distributed under the ISC License terms. */
#include <math.h> /* for partition_floyd_rivest() */
#include <stddef.h> /* ptrdiff_t */
#include <stdint.h>
#include <string.h> /* memcpy(), memset() */
/* Built-in u128 is not strictly required, but it makes mcg64 simpler and faster. */
typedef __uint128_t uint128_t;
@igorburago
igorburago / xorab.c
Last active May 28, 2024 04:24
Finding all solutions of the equation x⊕(a-x)=b
/* Copyright 2013 Igor Burago. Distributed under the ISC License terms. */
#include <limits.h>
#include <stdio.h>
typedef unsigned uint;
uint
enum_bit(uint q, uint x, uint *xs) {
if (q == 0) {
@igorburago
igorburago / indentguides.vim
Last active May 28, 2024 04:29
Vim indentation guides emulation
" Copyright 2022 Igor Burago. Distributed under the ISC License terms.
" 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().