use of com.google.common.hash.BloomFilter in project XRTB by benmfaul.
the class TestBloom method testBloom.
/**
* Test a valid bid response.
* @throws Exception on networking errors.
*/
@Test
public void testBloom() throws Exception {
new Bloom("$test", "data/c1x_cookies.csv");
BloomFilter b = (BloomFilter) LookingGlass.get("$test");
assertNotNull(b);
boolean p = b.mightContain("842AAB10FBA04247B3A9CE00C9172350");
BufferedReader br = new BufferedReader(new FileReader("data/c1x_cookies.csv"));
String line = null;
int nP = 0;
int k = 0;
while ((line = br.readLine()) != null) {
p = b.mightContain(line);
if (p)
nP++;
k++;
}
assertTrue(k == nP);
}
use of com.google.common.hash.BloomFilter in project XRTB by benmfaul.
the class Node method testInternal.
/**
* Internal version of test() when recursion is required (NOT_* form)
*
* @param value.
* Object. Converts the value of the bid request field (Jackson)
* to the appropriate Java object.
* @return boolean. Returns true if the operation succeeded.
* @throws Exception
* if the value is not recognized or is not compatible with
* this.value.
*/
public boolean testInternal(Object value) throws Exception {
if (value == null || value instanceof MissingNode == true) {
// request.
if (!(operator == EXISTS || operator == NOT_EXISTS)) {
if (notPresentOk)
return true;
return false;
}
}
Number nvalue = null;
String svalue = null;
// Set qvalue = null;
Set qval = null;
if (value instanceof String)
svalue = (String) value;
if (value instanceof IntNode) {
IntNode n = (IntNode) value;
nvalue = n.numberValue();
} else if (value instanceof TextNode) {
TextNode tn = (TextNode) value;
svalue = tn.textValue();
} else if (value instanceof ArrayNode) {
List list = traverse((ArrayNode) value);
qvalue = new TreeSet(list);
} else if (value instanceof ObjectNode) {
ObjectNode n = (ObjectNode) value;
mvalue = iterateObject(n);
} else if (value instanceof Double) {
// (Node) value;
DoubleNode n = new DoubleNode((Double) value);
nvalue = n.numberValue();
} else if (value instanceof DoubleNode) {
DoubleNode n = (DoubleNode) value;
n.asDouble();
// (Node) value;
DoubleNode nn = new DoubleNode(n.asDouble());
nvalue = nn.numberValue();
} else if (value instanceof Integer) {
// (Node) value;
IntNode n = new IntNode((Integer) value);
nvalue = n.numberValue();
} else if (value instanceof Collection) {
qvalue = new TreeSet();
qvalue.addAll((Collection) value);
}
switch(operator) {
case QUERY:
return true;
case EQUALS:
return processEquals(ival, nvalue, sval, svalue, qval, qvalue);
case NOT_EQUALS:
return !processEquals(ival, nvalue, sval, svalue, qval, qvalue);
case STRINGIN:
if (lval != null) {
boolean member = false;
for (int i = 0; i < lval.size(); i++) {
Object test = lval.get(i);
if (test instanceof String) {
String testS = (String) test;
member |= processStringin(ival, nvalue, testS, svalue, qval, qvalue);
}
}
return member;
}
return processStringin(ival, nvalue, sval, svalue, qval, qvalue);
case NOT_STRINGIN:
if (lval != null) {
boolean member = false;
for (int i = 0; i < lval.size(); i++) {
Object test = lval.get(i);
if (test instanceof String) {
String testS = (String) test;
member |= processStringin(ival, nvalue, testS, svalue, qval, qvalue);
}
}
return !member;
}
return !processStringin(ival, nvalue, sval, svalue, qval, qvalue);
case REGEX:
case NOT_REGEX:
boolean member = true;
if (svalue != null) {
member = processRegex(ival, nvalue, sval, svalue, qval, qvalue);
}
if (operator == NOT_REGEX)
return !member;
else
return member;
case MEMBER:
case NOT_MEMBER:
if (sval != null && (sval.startsWith("@") || sval.startsWith("$"))) {
Object x = LookingGlass.get(sval);
boolean t = false;
if (x instanceof NavMap) {
NavMap nm = (NavMap) x;
t = nm.contains(svalue);
} else if (x instanceof BloomFilter) {
BloomFilter b = (BloomFilter) x;
t = b.mightContain(svalue);
} else if (x instanceof Set) {
Set set = (Set) x;
t = set.contains(svalue);
}
if (operator == NOT_MEMBER)
return !t;
else
return t;
}
if (qvalue == null) {
if (lval != null)
qvalue = new HashSet(lval);
else {
qvalue = new HashSet();
if (svalue == null)
qvalue.addAll((Collection) value);
else
qvalue.add(svalue);
}
}
if (nvalue == null && svalue == null) {
if (this.value instanceof String)
svalue = (String) this.value;
else {
try {
nvalue = (Integer) this.value;
} catch (Exception error) {
return false;
//System.out.println("QVALUE: " + qvalue);
//System.out.println("THIS VALUE: " + this.value);
//System.out.println("VALUE: " + value);
}
}
}
boolean test = false;
test = processMember(nvalue, svalue, qvalue);
if (operator == MEMBER)
return test;
else
return !test;
case INTERSECTS:
case NOT_INTERSECTS:
if (qvalue == null) {
if (lval != null)
qvalue = new TreeSet(lval);
}
if (qval == null) {
if (svalue != null) {
qval = new TreeSet();
qval.add(svalue);
} else {
if (nvalue != null) {
qval = new TreeSet();
qval.add(nvalue);
} else if (lval != null) {
qval = new TreeSet(lval);
}
}
} else {
if (svalue != null) {
qval.add(svalue);
} else {
if (nvalue != null) {
qval.add(nvalue.intValue());
}
}
}
if (qval == null)
qval = new TreeSet(lval);
boolean xxx = processIntersects(qval, qvalue);
if (operator == INTERSECTS)
return xxx;
return !xxx;
case INRANGE:
return computeInRange(mvalue, lval);
case NOT_INRANGE:
return !computeInRange(mvalue, lval);
case DOMAIN:
return computeInDomain(nvalue, lval);
case NOT_DOMAIN:
return !computeInDomain(nvalue, lval);
case LESS_THAN:
case LESS_THAN_EQUALS:
case GREATER_THAN:
case GREATER_THAN_EQUALS:
return processLTE(operator, ival, nvalue, sval, svalue, qval, qvalue);
case EXISTS:
case NOT_EXISTS:
boolean rc = false;
if (value == null)
rc = false;
else
rc = value instanceof ObjectNode;
if (operator == EXISTS)
return rc;
return !rc;
default:
return false;
}
}
Aggregations