Skip to content

Commit

Permalink
Added ability to not use BloomFilter to completely brute force things.
Browse files Browse the repository at this point in the history
  • Loading branch information
eljefe6a committed Jan 16, 2013
1 parent 7f0b5dc commit 77f87a1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
14 changes: 12 additions & 2 deletions src/BoggleDriver.java
Expand Up @@ -40,14 +40,23 @@ public class BoggleDriver extends Configured implements Tool {
public static final String ROLL_PARAM = "roll"; public static final String ROLL_PARAM = "roll";


/** The parameter name for the roll version */ /** The parameter name for the roll version */
public static final String ROLL_VERSION = "rollversion"; public static final String ROLL_VERSION_PARAM = "rollversion";

/** The parameter name for the roll version */
public static final int ROLL_VERSION_DEFAULT = BoggleRoll.NEW_VERSION;


/** The parameter name for the minimum word size to output */ /** The parameter name for the minimum word size to output */
public static final String MAX_ITERATIONS_PARAM = "maxiterations"; public static final String MAX_ITERATIONS_PARAM = "maxiterations";


/** The default value for the minimum word size to output */ /** The default value for the minimum word size to output */
public static final int MAX_ITERATIONS_DEFAULT = 15; public static final int MAX_ITERATIONS_DEFAULT = 15;


/** The parameter name to use a BloomFilter */
public static final String ENABLE_BLOOM_PARAM = "bloom";

/** The default value for using the BloomFilter */
public static final boolean ENABLE_BLOOM_DEFAULT = true;

@Override @Override
public int run(String[] args) throws Exception { public int run(String[] args) throws Exception {
if (args.length != 4) { if (args.length != 4) {
Expand Down Expand Up @@ -84,8 +93,9 @@ public int run(String[] args) throws Exception {


configuration.set(BLOOM_PARAM, bloomPath); configuration.set(BLOOM_PARAM, bloomPath);
configuration.set(DICTIONARY_PARAM, dictionary); configuration.set(DICTIONARY_PARAM, dictionary);
configuration.setBooleanIfUnset(ENABLE_BLOOM_PARAM, ENABLE_BLOOM_DEFAULT);


BoggleRoll roll = BoggleRoll.createRoll(configuration.getInt(ROLL_VERSION, 1000)); BoggleRoll roll = BoggleRoll.createRoll(configuration.getInt(ROLL_VERSION_PARAM, ROLL_VERSION_DEFAULT));
configuration.set(ROLL_PARAM, roll.serialize()); configuration.set(ROLL_PARAM, roll.serialize());


int iteration = traverseGraph(input, configuration, fileSystem, roll); int iteration = traverseGraph(input, configuration, fileSystem, roll);
Expand Down
15 changes: 12 additions & 3 deletions src/BoggleMapper.java
Expand Up @@ -29,8 +29,11 @@ public void setup(Context context) throws IOException {
// Load the Bloom Filter // Load the Bloom Filter
FileSystem fileSystem = FileSystem.get(configuration); FileSystem fileSystem = FileSystem.get(configuration);


bloomFilter = new BloomFilter(UserDictBloom.VECTOR_SIZE, UserDictBloom.NBHASH, UserDictBloom.HASH_TYPE); if (configuration.getBoolean(BoggleDriver.ENABLE_BLOOM_PARAM, BoggleDriver.ENABLE_BLOOM_DEFAULT)) {
bloomFilter.readFields(fileSystem.open(new Path(configuration.get(BoggleDriver.BLOOM_PARAM)))); // Only allow BloomFilter usage if it's turned on
bloomFilter = new BloomFilter(UserDictBloom.VECTOR_SIZE, UserDictBloom.NBHASH, UserDictBloom.HASH_TYPE);
bloomFilter.readFields(fileSystem.open(new Path(configuration.get(BoggleDriver.BLOOM_PARAM))));
}
} }


@Override @Override
Expand Down Expand Up @@ -66,6 +69,8 @@ private void processNonFinalNode(Context context, String charsSoFar, RollGraphWr
// Emit the characters around the last node in the Boggle Roll // Emit the characters around the last node in the Boggle Roll
Node node = rollGraph.nodes.get(rollGraph.nodes.size() - 1); Node node = rollGraph.nodes.get(rollGraph.nodes.size() - 1);


boolean proceed;

for (int row = node.row - 1; row < node.row + 2; row++) { for (int row = node.row - 1; row < node.row + 2; row++) {
if (row < 0 || row >= roll.rollSize) { if (row < 0 || row >= roll.rollSize) {
// Check if row is outside the bounds and skip if so // Check if row is outside the bounds and skip if so
Expand All @@ -85,7 +90,11 @@ private void processNonFinalNode(Context context, String charsSoFar, RollGraphWr
// Node not found, see if it passes the membership test // Node not found, see if it passes the membership test
String newWord = charsSoFar + roll.rollCharacters[row][col]; String newWord = charsSoFar + roll.rollCharacters[row][col];


if (bloomFilter.membershipTest(new Key(newWord.getBytes()))) { // If Bloom is null (user set Bloom to not be used, just emit)
// If Bloom is not null, do a membership test and emit
proceed = bloomFilter == null ? true : bloomFilter.membershipTest(new Key(newWord.getBytes()));

if (proceed) {
// It might exist, create new object, add new node, and emit // It might exist, create new object, add new node, and emit
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
ArrayList<Node> nextNodeList = (ArrayList<Node>) rollGraph.nodes.clone(); ArrayList<Node> nextNodeList = (ArrayList<Node>) rollGraph.nodes.clone();
Expand Down

0 comments on commit 77f87a1

Please sign in to comment.