Skip to content

Instantly share code, notes, and snippets.

View cls's full-sized avatar

Connor Lane Smith cls

View GitHub Profile
@cls
cls / intern.c
Last active August 29, 2015 14:23
Interning strings with a prefix tree
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
const char *
intern(const char *s)
{
union tree {
const char *str;
@cls
cls / CovariantIterator.java
Last active August 29, 2015 14:17
Adaptor for covariant iterators in Java
import java.util.Iterator;
public class CovariantIterator<T extends U, U> implements Iterator<U>
{
private Iterator<T> iter;
public CovariantIterator(Iterator<T> it)
{
this.iter = it;
}
@cls
cls / roman.c
Last active August 29, 2015 14:16
Roman numeral parser
#include <stdio.h>
enum { I, V, X, L, C, D, M, StackSize };
const int values[] = { 1, 5, 10, 50, 100, 500, 1000 };
int
unroman(const char *s)
{
int stack[StackSize];