static inline gnix_ht_key_t __gnix_hash_func( gnix_hashtable_t *ht, gnix_ht_key_t key) { return fasthash64(&key, sizeof(gnix_ht_key_t), ht->ht_attr.ht_hash_seed) % ht->ht_size; }
const QIcon& CIconProvider::iconFor(const CFileSystemObject& object) { const qulonglong objectHash = hash(object); if (_iconForObject.count(objectHash) == 0) { const QIcon icon = _provider->iconFor(object); assert_r(!icon.isNull()); const auto qimage = icon.pixmap(icon.availableSizes().front()).toImage(); const qulonglong iconHash = fasthash64((const char*)qimage.constBits(), qimage.bytesPerLine() * qimage.height(), 0); if (_iconCache.size() > 300) { _iconCache.clear(); _iconForObject.clear(); } const auto iconInContainer = _iconCache.insert(std::make_pair(iconHash, icon)).first; _iconForObject[objectHash] = iconHash; return iconInContainer->second; } return _iconCache[_iconForObject[objectHash]]; }
static uint64_t FastHashJsonRecursive (uint64_t hash, TRI_json_t const* object) { if (nullptr == object) { return fasthash64(static_cast<const void*>("null"), 4, hash); } switch (object->_type) { case TRI_JSON_UNUSED: { return hash; } case TRI_JSON_NULL: { return fasthash64(static_cast<const void*>("null"), 4, hash); } case TRI_JSON_BOOLEAN: { if (object->_value._boolean) { return fasthash64(static_cast<const void*>("true"), 4, hash); } return fasthash64(static_cast<const void*>("false"), 5, hash); } case TRI_JSON_NUMBER: { return fasthash64(static_cast<const void*>(&object->_value._number), sizeof(object->_value._number), hash); } case TRI_JSON_STRING: case TRI_JSON_STRING_REFERENCE: { return fasthash64(static_cast<const void*>(object->_value._string.data), object->_value._string.length, hash); } case TRI_JSON_OBJECT: { hash = fasthash64(static_cast<const void*>("object"), 6, hash); size_t const n = TRI_LengthVector(&object->_value._objects); for (size_t i = 0; i < n; i += 2) { auto subjson = static_cast<TRI_json_t const*>(TRI_AddressVector(&object->_value._objects, i)); TRI_ASSERT(TRI_IsStringJson(subjson)); hash = FastHashJsonRecursive(hash, subjson); subjson = static_cast<TRI_json_t const*>(TRI_AddressVector(&object->_value._objects, i + 1)); hash = FastHashJsonRecursive(hash, subjson); } return hash; } case TRI_JSON_ARRAY: { hash = fasthash64(static_cast<const void*>("array"), 5, hash); size_t const n = TRI_LengthVector(&object->_value._objects); for (size_t i = 0; i < n; ++i) { auto subjson = static_cast<TRI_json_t const*>(TRI_AddressVector(&object->_value._objects, i)); hash = FastHashJsonRecursive(hash, subjson); } } } return hash; // never reached }
uint32_t fasthash32(const void *buf, size_t len, uint32_t seed) { // the following trick converts the 64-bit hashcode to Fermat // residue, which shall retain information from both the higher // and lower parts of hashcode. uint64_t h = fasthash64(buf, len, seed); return h - (h >> 32); }
inline static qulonglong hash(const CFileSystemObject& object) { const auto properties = object.properties(); const auto hashData = QByteArray::fromRawData((const char*)&properties.hash, sizeof(properties.hash)) + QByteArray::fromRawData((const char*)&properties.modificationDate, sizeof(properties.modificationDate)) + QByteArray::fromRawData((const char*)&properties.type, sizeof(properties.type)); return fasthash64(hashData.constData(), hashData.size(), 0); }
static uint64_t HashKey (TRI_hash_array_multi_t const* array, TRI_index_search_value_t const* key) { uint64_t hash = 0x0123456789abcdef; for (size_t j = 0; j < array->_numFields; ++j) { // ignore the sid for hashing hash = fasthash64(key->_values[j]._data.data, key->_values[j]._data.length, hash); } return hash; }
static uint64_t HashElement (TRI_hash_array_multi_t const* array, TRI_hash_index_element_multi_t const* element) { uint64_t hash = 0x0123456789abcdef; for (size_t j = 0; j < array->_numFields; j++) { char const* data; size_t length; TRI_InspectShapedSub(&element->_subObjects[j], element->_document, data, length); // ignore the sid for hashing // only hash the data block hash = fasthash64(data, length, hash); } return hash; }
void CFileSystemObject::refreshInfo() { _properties.exists = _fileInfo.exists(); _properties.fullPath = _fileInfo.absoluteFilePath(); if (_fileInfo.isFile()) _properties.type = File; else if (_fileInfo.isDir()) { // Normalization - very important for hash calculation and equality checking // C:/1/ must be equal to C:/1 if (!_properties.fullPath.endsWith('/')) _properties.fullPath.append('/'); _properties.type = _fileInfo.isBundle() ? Bundle : Directory; } else if (_properties.exists) { #ifdef _WIN32 qInfo() << _properties.fullPath << " is neither a file nor a dir"; #endif } else if (_properties.fullPath.endsWith('/')) _properties.type = Directory; _properties.hash = fasthash64(_properties.fullPath.constData(), _properties.fullPath.size() * sizeof(QChar), 0); if (_properties.type == File) { _properties.extension = _fileInfo.suffix(); _properties.completeBaseName = _fileInfo.completeBaseName(); } else if (_properties.type == Directory) { _properties.completeBaseName = _fileInfo.baseName(); const QString suffix = _fileInfo.completeSuffix(); if (!suffix.isEmpty()) _properties.completeBaseName = _properties.completeBaseName % '.' % suffix; // Ugly temporary bug fix for #141 if (_properties.completeBaseName.isEmpty() && _properties.fullPath.endsWith('/')) { const QFileInfo tmpInfo = QFileInfo(_properties.fullPath.left(_properties.fullPath.length() - 1)); _properties.completeBaseName = tmpInfo.baseName(); const QString sfx = tmpInfo.completeSuffix(); if (!sfx.isEmpty()) _properties.completeBaseName = _properties.completeBaseName % '.' % sfx; } } else if (_properties.type == Bundle) { _properties.extension = _fileInfo.suffix(); _properties.completeBaseName = _fileInfo.completeBaseName(); } _properties.fullName = _properties.type == Directory ? _properties.completeBaseName : _fileInfo.fileName(); _properties.isCdUp = _properties.fullName == QLatin1String(".."); // QFileInfo::canonicalPath() / QFileInfo::absolutePath are undefined for non-files _properties.parentFolder = parentForAbsolutePath(_properties.fullPath); if (!_properties.exists) return; _properties.creationDate = (time_t) _fileInfo.created().toTime_t(); _properties.modificationDate = _fileInfo.lastModified().toTime_t(); _properties.size = _properties.type == File ? _fileInfo.size() : 0; if (isDir()) _dir.setPath(fullAbsolutePath()); else _dir = QDir(); }