Exemple #1
0
uint64_t VelocyPackHelper::hashByAttributes(
    VPackSlice slice, std::vector<std::string> const& attributes,
    bool docComplete, int& error, std::string const& key) {
  uint64_t hash = TRI_FnvHashBlockInitial();
  error = TRI_ERROR_NO_ERROR;
  slice = slice.resolveExternal();
  if (slice.isObject()) {
    for (auto const& attr : attributes) {
      VPackSlice sub = slice.get(attr).resolveExternal();
      if (sub.isNone()) {
        if (attr == StaticStrings::KeyString && !key.empty()) {
          VPackBuilder temporaryBuilder;
          temporaryBuilder.add(VPackValue(key));
          hash = temporaryBuilder.slice().normalizedHash(hash);
          continue;
        }
        if (!docComplete) {
          error = TRI_ERROR_CLUSTER_NOT_ALL_SHARDING_ATTRIBUTES_GIVEN;
        }
        // Null is equal to None/not present
        sub = VPackSlice::nullSlice();
      }
      hash = sub.normalizedHash(hash);
    }
  }
  return hash;
}
Exemple #2
0
uint64_t TRI_HashJsonByAttributes (TRI_json_t const* json,
                                   char const *attributes[],
                                   int nrAttributes,
                                   bool docComplete,
                                   int* error) {
  uint64_t hash;

  if (NULL != error) {
    *error = TRI_ERROR_NO_ERROR;
  }
  hash = TRI_FnvHashBlockInitial();
  if (TRI_IsArrayJson(json)) {
    int i;

    for (i = 0; i < nrAttributes; i++) {
      TRI_json_t const* subjson = TRI_LookupArrayJson(json, attributes[i]);

      if (NULL == subjson && !docComplete && NULL != error) {
        *error = TRI_ERROR_CLUSTER_NOT_ALL_SHARDING_ATTRIBUTES_GIVEN;
      }
      hash = HashJsonRecursive(hash, subjson);
    }
  }
  return hash;
}
Exemple #3
0
static uint64_t HashKeyPQIndex(TRI_associative_array_t* aa, void* key) {
  uint64_t hash;

  hash = TRI_FnvHashBlockInitial();
  hash = TRI_FnvHashBlock(hash, key, sizeof(void*));

  return  hash;
}
Exemple #4
0
static uint64_t HashKey (TRI_hash_array_t* array,
                         TRI_index_search_value_t* key) {
  uint64_t hash = TRI_FnvHashBlockInitial();
  size_t j;

  for (j = 0;  j < array->_numFields;  ++j) {

    // ignore the sid for hashing
    hash = TRI_FnvHashBlock(hash, key->_values[j]._data.data, key->_values[j]._data.length);
  }
  return hash;
}
Exemple #5
0
static uint64_t HashElementPQIndex(TRI_associative_array_t* aa, void* item) {
  PQIndexElement* element;
  uint64_t hash;
  
  element = (PQIndexElement*)(item);
  if (element == 0) {
    return 0;
  }
  
  hash = TRI_FnvHashBlockInitial();
  hash = TRI_FnvHashBlock(hash, element->data, sizeof(void*)); 
  
  return  hash;
}
Exemple #6
0
static uint64_t HashElementPQIndex(TRI_associative_array_t* aa, void* item) {
  TRI_pq_index_element_t* element;
  uint64_t hash;
  
  element = (TRI_pq_index_element_t*)(item);

  if (element == 0) {
    return 0;
  }

  hash = TRI_FnvHashBlockInitial();
  hash = TRI_FnvHashBlock(hash, (void*) element->_document, sizeof(void*)); 
  
  return  hash;
}
Exemple #7
0
static uint64_t HashElement (TRI_hash_array_t* array,
                             TRI_hash_index_element_t* element) {
  uint64_t hash = TRI_FnvHashBlockInitial();
  char* ptr;
  size_t j;

  for (j = 0;  j < array->_numFields;  j++) {

    // ignore the sid for hashing
    ptr = ((char*) element->_document->_data) + element->_subObjects[j]._offset;

    // only hash the data block
    hash = TRI_FnvHashBlock(hash, ptr, element->_subObjects[j]._length);
  }

  return hash;
}
uint64_t TRI_HashJsonByAttributes (TRI_json_t const* json,
                                   char const *attributes[],
                                   int nrAttributes,
                                   bool docComplete,
                                   int* error) {
    if (error != nullptr) {
        *error = TRI_ERROR_NO_ERROR;
    }
    uint64_t hash = TRI_FnvHashBlockInitial();
    if (TRI_IsObjectJson(json)) {
        for (int i = 0; i < nrAttributes; i++) {
            TRI_json_t const* subjson = TRI_LookupObjectJson(json, attributes[i]);

            if (subjson == nullptr && ! docComplete && error != nullptr) {
                *error = TRI_ERROR_CLUSTER_NOT_ALL_SHARDING_ATTRIBUTES_GIVEN;
            }
            hash = HashJsonRecursive(hash, subjson);
        }
    }
    return hash;
}
Exemple #9
0
uint64_t TRI_HashJson (TRI_json_t const* json) {
  return HashJsonRecursive(TRI_FnvHashBlockInitial(), json);
}