Permalink
Browse files

Added ability to not use BloomFilter to completely brute force things.

  • Loading branch information...
eljefe6a committed Jan 16, 2013
1 parent 7f0b5dc commit 77f87a15eb13d47cd7e7b7217c7d3c8896a4cfea
Showing with 24 additions and 5 deletions.
  1. +12 −2 src/BoggleDriver.java
  2. +12 −3 src/BoggleMapper.java
View
@@ -40,14 +40,23 @@
public static final String ROLL_PARAM = "roll";
/** 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 */
public static final String MAX_ITERATIONS_PARAM = "maxiterations";
/** The default value for the minimum word size to output */
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
public int run(String[] args) throws Exception {
if (args.length != 4) {
@@ -84,8 +93,9 @@ public int run(String[] args) throws Exception {
configuration.set(BLOOM_PARAM, bloomPath);
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());
int iteration = traverseGraph(input, configuration, fileSystem, roll);
View
@@ -29,8 +29,11 @@ public void setup(Context context) throws IOException {
// Load the Bloom Filter
FileSystem fileSystem = FileSystem.get(configuration);
- bloomFilter = new BloomFilter(UserDictBloom.VECTOR_SIZE, UserDictBloom.NBHASH, UserDictBloom.HASH_TYPE);
- bloomFilter.readFields(fileSystem.open(new Path(configuration.get(BoggleDriver.BLOOM_PARAM))));
+ if (configuration.getBoolean(BoggleDriver.ENABLE_BLOOM_PARAM, BoggleDriver.ENABLE_BLOOM_DEFAULT)) {
+ // 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
@@ -66,6 +69,8 @@ private void processNonFinalNode(Context context, String charsSoFar, RollGraphWr
// Emit the characters around the last node in the Boggle Roll
Node node = rollGraph.nodes.get(rollGraph.nodes.size() - 1);
+ boolean proceed;
+
for (int row = node.row - 1; row < node.row + 2; row++) {
if (row < 0 || row >= roll.rollSize) {
// Check if row is outside the bounds and skip if so
@@ -85,7 +90,11 @@ private void processNonFinalNode(Context context, String charsSoFar, RollGraphWr
// Node not found, see if it passes the membership test
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
@SuppressWarnings("unchecked")
ArrayList<Node> nextNodeList = (ArrayList<Node>) rollGraph.nodes.clone();

0 comments on commit 77f87a1

Please sign in to comment.