org.apache.hadoop.util.hash.MurmurHash Java Examples

The following examples show how to use org.apache.hadoop.util.hash.MurmurHash. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: QueryParser.java    From accumulo-recipes with Apache License 2.0 5 votes vote down vote up
public void execute(String query) throws ParseException {
    reset();
    query = query.replaceAll("\\s+AND\\s+", " and ");
    query = query.replaceAll("\\s+OR\\s+", " or ");
    query = query.replaceAll("\\s+NOT\\s+", " not ");

    // Check to see if its in the cache
    Hash hash = MurmurHash.getInstance();
    this.hashVal = hash.hash(query.getBytes(), SEED);
    CacheEntry entry = null;
    synchronized (cache) {
        entry = (CacheEntry) cache.get(hashVal);
    }
    if (entry != null) {
        this.negatedTerms = entry.getNegatedTerms();
        this.andTerms = entry.getAndTerms();
        this.orTerms = entry.getOrTerms();
        this.literals = entry.getLiterals();
        this.terms = entry.getTerms();
        this.rootNode = entry.getRootNode();
        this.tree = entry.getTree();
    } else {
        Parser p = new Parser(new StringReader(";"));
        rootNode = p.parse(new StringReader(query), null);
        rootNode.childrenAccept(this, null);
        TreeBuilder builder = new TreeBuilder(rootNode);
        tree = builder.getRootNode();
        entry = new CacheEntry(this.negatedTerms, this.andTerms, this.orTerms, this.literals, this.terms, rootNode, tree);
        synchronized (cache) {
            cache.put(hashVal, entry);
        }
    }

}