Example #1
0
int * BloomFilter::keys(string item){
  int * keys = new int[3]; 
  string item1 = item;
  reverse(item1.begin(), item1.end());
  keys[0] = ABS(djbHash(item) % size);
  keys[1] = ABS(djbHash(item1) % size);
  keys[2] = ABS(djbHash(item + item1) % size);
  return keys;
};
Example #2
0
static unsigned int constructObject(char *parentName, char *object, jsonProperty *properties, char **next) {
    char *firstName;
    char *lastName;
    char *first;
    char *last;
    unsigned char type;
    unsigned int hash;
    int parentNameLength = (parentName ? strlen(parentName): 0);
    unsigned int result = readNextName(object, &firstName, &lastName, &hash);
    while (result == PARSE_OK) {
        readNextValue(lastName, &first, &last, &type);
        
        if (!parentName) {
            if (type == JSON_OBJECT) {
                int nameLength = lastName - firstName;
                char newParent[nameLength + 1];
                strncpy(newParent, firstName, nameLength);
                newParent[nameLength] = '\0';
                return constructObject(newParent, first, properties, next);
            }
        } else {
            int nameLength = lastName - firstName;
            int fullNameLength = nameLength + parentNameLength + 1; 
            char fullName[fullNameLength + 1];
            strncpy(fullName, firstName, nameLength);
            fullName[nameLength] = '.';
            strncpy(&fullName[nameLength + 1], parentName, parentNameLength);
            fullName[fullNameLength] = '\0';
            hash = djbHash(fullName, fullNameLength);
            if (type == JSON_OBJECT) {
                return constructObject(fullName, first, properties, next);
            }
        }

        int i = 0;
        jsonProperty *property = &properties[hash & HASH_MASK];
        while (property->hash != 0){
            ++i;
            if (i == MAX_CONFLICTS) {
                return ERR_EVENT_MAX_CONFLICTS;
            }

            property = &properties[(hash & HASH_MASK) + (i * MAX_BUCKET_LENGTH)];
        }
        
        property->hash = hash;
        property->firstValue = first;
        property->lastValue = last;
        property->type = type;
        *next = last;
        result = readNextName(last, &firstName, &lastName, &hash);
    }
 
    return (result == PARSE_END ? RULES_OK: result);
}