This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.awt.BasicStroke; | |
import java.awt.Color; | |
import java.awt.Font; | |
import java.awt.Graphics2D; | |
import java.awt.RenderingHints; | |
import java.awt.geom.Arc2D; | |
import java.awt.geom.Ellipse2D; | |
import java.awt.geom.Line2D; | |
import java.awt.image.BufferedImage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// generates a binary De Bruijn sequence over words of length n | |
private BitVector generateDeBruijn(int n) { | |
// Check arguments | |
if (n < 0) throw new IllegalArgumentException("n is negative"); | |
if (n > 31) throw new IllegalArgumentException("n exceeds 31"); | |
// There are 2^n words in the entire sequence | |
int length = 1 << n; | |
// Create a set that records which words we have already seen | |
Set<Integer> memory = new BitVector(length).asSet(); | |
// Store the sequence with an extra n bits |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// INTRODUCTION | |
/** | |
* A BitVector is a fixed-length sequence of bits. It's an extremely | |
* powerful class because of the huge number of ways that it allows the | |
* bits to be accessed and modified. Algorithms that rely heavily on bit | |
* manipulation can improve their performance by reducing the frequency | |
* with which bit data needs to be moved between different data | |
* structures; they can rely on BitVector for all the bit manipulations | |
* they require. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* This introduction assumes familiarity with the general concept of | |
* Bloom filters. If you don't have this try reading: | |
* | |
* http://en.wikipedia.org/wiki/Bloom_filter | |
*/ | |
// HASHING | |
/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.awt.Container; | |
import java.awt.Insets; | |
import java.awt.event.ActionEvent; | |
import java.awt.event.ActionListener; | |
import java.awt.image.BufferedImage; | |
import java.io.File; | |
import java.io.IOException; | |
import javax.imageio.ImageIO; | |
import javax.swing.ImageIcon; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SIMPLE PERMUTATIONS | |
/** | |
* Let's start off by creating the simplest permutation: the identity | |
* permutation, in this case over 5 elements. | |
*/ | |
Permutation identity = Permutation.identity(5); | |
/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.tomgibara.android.util; | |
import java.util.HashSet; | |
import java.util.LinkedHashMap; | |
import java.util.Map; | |
import java.util.WeakHashMap; | |
import java.util.concurrent.Callable; | |
import java.util.concurrent.Future; | |
import java.util.concurrent.FutureTask; | |
import java.util.concurrent.PriorityBlockingQueue; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// example analytics | |
GoogleAnalyticsTracker gat = GoogleAnalyticsTracker.getInstance(); | |
gat.start(/* your analytics parameters */); | |
// example config | |
Tracker tracker = new Tracker(gat); | |
tracker.setAsynchronous(true); | |
tracker.disable(Tracker.Category.NET); | |
//example usage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.tomgibara.android.util; | |
import java.util.ArrayList; | |
import java.util.Arrays; | |
import java.util.EnumSet; | |
import android.os.AsyncTask; | |
import android.os.SystemClock; | |
import com.google.android.apps.analytics.GoogleAnalyticsTracker; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.tomgibara.android.util; | |
/** | |
* <p> | |
* Writes ints into char array without generating any objects. This is typically | |
* useful in instances where numbers must be rendered within a game-loop or | |
* animation. Instances of this class are not safe for multithreaded use. | |
* </p> | |
* | |
* <p> |
NewerOlder