Skip to content

Instantly share code, notes, and snippets.

View ClickerMonkey's full-sized avatar
💭
VPLs, ORMs, and Bag End

Philip Diffenderfer ClickerMonkey

💭
VPLs, ORMs, and Bag End
View GitHub Profile
@ClickerMonkey
ClickerMonkey / LinkedList.java
Created November 18, 2013 20:11
Doubly linked-list where nodes can remove themselves instantly from their list. A node can only be in one list. O(1) adding and removal.
public class LinkedList<T> implements Iterable<T>
{
public LinkedNode<T> head = new LinkedNode<T>( this );
private int size = 0;
public final LinkedNode<T> add( T value )
{
return new LinkedNode<T>( value ).prepend( head );
}
@ClickerMonkey
ClickerMonkey / Prime.java
Created November 18, 2013 20:04
A prime number utility for generating X number of primes, determining whether a given number is prime, and computing the prime factorization for a number. This class caches primes to very quickly check whether a number is a prime.
public class Prime
{
/* BEGIN TEST */
public static void main( String[] args )
{
Prime p = new Prime( 100000 );
// Load 100,000 primes into cache
long t0 = System.nanoTime();
@ClickerMonkey
ClickerMonkey / Blend.java
Created November 18, 2013 19:58
Software graphics library with blending, textures, and simple primitives.
public abstract class Blend
{
public static final Blend Alpha = new Blend()
{
public int blend( int o, int n )
{
return Color.mixRGB( o, n, Color.alpha( n ), Color.alpha( o ) );
}
};
@ClickerMonkey
ClickerMonkey / Reflect.java
Created November 18, 2013 19:51
Custom object serialization with compression (requires Compress.java) to and from ByteBuffers.
public interface Reflect<T>
{
public T get(ByteBuffer in);
public void getAndSet(ByteBuffer in, Object obj, Field field) throws IllegalAccessException;
public void put(ByteBuffer out, T v);
public int sizeOf(T v);
@ClickerMonkey
ClickerMonkey / Compress.java
Created November 18, 2013 19:46
Compressed put/get operations on a ByteBuffer for byte, char, short, int, long, Byte, Character, Short, Integer, and Long.
import java.nio.ByteBuffer;
public class Compress
{
public static final int BYTE_MORE = 0x80;
public static final int BYTE_SIGN = 0x40;
public static final int BYTE_NULL = 0x20;