Skip to content

Instantly share code, notes, and snippets.

View mmalex's full-sized avatar
💭
making shapes

Alex Evans mmalex

💭
making shapes
View GitHub Profile
@mmalex
mmalex / range_coder.cpp
Created July 8, 2022 21:59
attempt to understand range coder by implementing the algorithm on the wikipedia page, of all places...
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <assert.h>
#include <vector>
// arithmetic coder/decoder by @mmalex based on the wikipedia page https://en.wikipedia.org/wiki/Range_coding as of July 2022
struct encdec_state {
typedef uint16_t artype;
const static int topshift = sizeof(artype)*8-8;
artype low=0,range=~artype(0);