Skip to content

Instantly share code, notes, and snippets.

@adamse
adamse / shift_dfa.md
Created December 21, 2022 10:01 — forked from pervognsen/shift_dfa.md
Shift-based DFAs

A traditional table-based DFA implementation looks like this:

uint8_t table[NUM_STATES][256]

uint8_t run(const uint8_t *start, const uint8_t *end, uint8_t state) {
    for (const uint8_t *s = start; s != end; s++)
        state = table[state][*s];
    return state;
}
; NOTE: all just a quick sketch
; also I'm using xmm/ymm/zmm0-5 and then 16-31
; because Win64 ABI expects me to preserve ymm6-ymm15
; and I couldn't be bothered to set up a stack frame and save them :)
;
; Meant to be assembled with NASM
section .data
vone dd 1
@adamse
adamse / 175.hs
Last active August 29, 2015 14:05 — forked from profil/175.hs
module Main where
import System.Environment (getArgs, getProgName)
import System.Random
import Data.List (permutations)
-- | Randomly permutes a list
shuffle :: [a] -> StdGen -> ([a], StdGen)
shuffle xs gen = (ys !! randIndex, gen')
where