mirror of https://gitee.com/bigwinds/arangodb
finalized index API changes
This commit is contained in:
parent
db85c926be
commit
e29bc893b7
|
@ -59,13 +59,13 @@ struct data_container_t {
|
|||
data_container_t (int key, int value) : value(value), key(key) {};
|
||||
};
|
||||
|
||||
static uint64_t HashKey (void const* e) {
|
||||
static uint64_t HashKey (void* userData, void const* e) {
|
||||
int const* key = (int const*) e;
|
||||
|
||||
return fasthash64(key, sizeof(int), 0x12345678);
|
||||
}
|
||||
|
||||
static uint64_t HashElement (void const* e, bool byKey) {
|
||||
static uint64_t HashElement (void* userData, void const* e, bool byKey) {
|
||||
data_container_t const* element = (data_container_t const*) e;
|
||||
|
||||
if (byKey) {
|
||||
|
@ -76,21 +76,21 @@ static uint64_t HashElement (void const* e, bool byKey) {
|
|||
}
|
||||
}
|
||||
|
||||
static bool IsEqualKeyElement (void const* k, void const* r) {
|
||||
static bool IsEqualKeyElement (void* userData, void const* k, void const* r) {
|
||||
int const* key = (int const*) k;
|
||||
data_container_t const* element = (data_container_t const*) r;
|
||||
|
||||
return *key == element->key;
|
||||
}
|
||||
|
||||
static bool IsEqualElementElement (void const* l, void const* r) {
|
||||
static bool IsEqualElementElement (void* userData, void const* l, void const* r) {
|
||||
data_container_t const* left = (data_container_t const*) l;
|
||||
data_container_t const* right = (data_container_t const*) r;
|
||||
|
||||
return left->value == right->value;
|
||||
}
|
||||
|
||||
static bool IsEqualElementElementByKey (void const* l, void const* r) {
|
||||
static bool IsEqualElementElementByKey (void* userData, void const* l, void const* r) {
|
||||
data_container_t const* left = (data_container_t const*) l;
|
||||
data_container_t const* right = (data_container_t const*) r;
|
||||
|
||||
|
|
|
@ -59,13 +59,16 @@ struct data_container_t {
|
|||
data_container_t (int key, int value) : value(value), key(key) {};
|
||||
};
|
||||
|
||||
static uint64_t HashKey (void const* e) {
|
||||
static uint64_t HashKey (void* userData,
|
||||
void const* e) {
|
||||
int const* key = (int const*) e;
|
||||
|
||||
return fasthash64(key, sizeof(int), 0x12345678);
|
||||
}
|
||||
|
||||
static uint64_t HashElement (void const* e, bool byKey) {
|
||||
static uint64_t HashElement (void* userData,
|
||||
void const* e,
|
||||
bool byKey) {
|
||||
data_container_t const* element = (data_container_t const*) e;
|
||||
|
||||
if (byKey) {
|
||||
|
@ -76,21 +79,27 @@ static uint64_t HashElement (void const* e, bool byKey) {
|
|||
}
|
||||
}
|
||||
|
||||
static bool IsEqualKeyElement (void const* k, void const* r) {
|
||||
static bool IsEqualKeyElement (void* userData,
|
||||
void const* k,
|
||||
void const* r) {
|
||||
int const* key = (int const*) k;
|
||||
data_container_t const* element = (data_container_t const*) r;
|
||||
|
||||
return *key == element->key;
|
||||
}
|
||||
|
||||
static bool IsEqualElementElement (void const* l, void const* r) {
|
||||
static bool IsEqualElementElement (void* userData,
|
||||
void const* l,
|
||||
void const* r) {
|
||||
data_container_t const* left = (data_container_t const*) l;
|
||||
data_container_t const* right = (data_container_t const*) r;
|
||||
|
||||
return left->value == right->value;
|
||||
}
|
||||
|
||||
static bool IsEqualElementElementByKey (void const* l, void const* r) {
|
||||
static bool IsEqualElementElementByKey (void* userData,
|
||||
void const* l,
|
||||
void const* r) {
|
||||
data_container_t const* left = (data_container_t const*) l;
|
||||
data_container_t const* right = (data_container_t const*) r;
|
||||
|
||||
|
|
|
@ -49,7 +49,8 @@ using namespace triagens::arango;
|
|||
/// @brief hashes an edge key
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static uint64_t HashElementKey (void const* data) {
|
||||
static uint64_t HashElementKey (void* userData,
|
||||
TRI_edge_header_t const* data) {
|
||||
TRI_ASSERT_EXPENSIVE(data != nullptr);
|
||||
|
||||
TRI_edge_header_t const* h = static_cast<TRI_edge_header_t const*>(data);
|
||||
|
@ -65,7 +66,8 @@ static uint64_t HashElementKey (void const* data) {
|
|||
/// @brief hashes an edge (_from case)
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static uint64_t HashElementEdgeFrom (void const* data,
|
||||
static uint64_t HashElementEdgeFrom (void* userData,
|
||||
TRI_doc_mptr_t const* data,
|
||||
bool byKey) {
|
||||
TRI_ASSERT_EXPENSIVE(data != nullptr);
|
||||
|
||||
|
@ -105,7 +107,8 @@ static uint64_t HashElementEdgeFrom (void const* data,
|
|||
/// @brief hashes an edge (_to case)
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static uint64_t HashElementEdgeTo (void const* data,
|
||||
static uint64_t HashElementEdgeTo (void* userData,
|
||||
TRI_doc_mptr_t const* data,
|
||||
bool byKey) {
|
||||
TRI_ASSERT_EXPENSIVE(data != nullptr);
|
||||
|
||||
|
@ -145,8 +148,9 @@ static uint64_t HashElementEdgeTo (void const* data,
|
|||
/// @brief checks if key and element match (_from case)
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static bool IsEqualKeyEdgeFrom (void const* left,
|
||||
void const* right) {
|
||||
static bool IsEqualKeyEdgeFrom (void* userData,
|
||||
TRI_edge_header_t const* left,
|
||||
TRI_doc_mptr_t const* right) {
|
||||
TRI_ASSERT_EXPENSIVE(left != nullptr);
|
||||
TRI_ASSERT_EXPENSIVE(right != nullptr);
|
||||
|
||||
|
@ -181,8 +185,9 @@ static bool IsEqualKeyEdgeFrom (void const* left,
|
|||
/// @brief checks if key and element match (_to case)
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static bool IsEqualKeyEdgeTo (void const* left,
|
||||
void const* right) {
|
||||
static bool IsEqualKeyEdgeTo (void* userData,
|
||||
TRI_edge_header_t const* left,
|
||||
TRI_doc_mptr_t const* right) {
|
||||
TRI_ASSERT_EXPENSIVE(left != nullptr);
|
||||
TRI_ASSERT_EXPENSIVE(right != nullptr);
|
||||
|
||||
|
@ -218,8 +223,9 @@ static bool IsEqualKeyEdgeTo (void const* left,
|
|||
/// @brief checks for elements are equal (_from and _to case)
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static bool IsEqualElementEdge (void const* left,
|
||||
void const* right) {
|
||||
static bool IsEqualElementEdge (void* userData,
|
||||
TRI_doc_mptr_t const* left,
|
||||
TRI_doc_mptr_t const* right) {
|
||||
return left == right;
|
||||
}
|
||||
|
||||
|
@ -227,8 +233,9 @@ static bool IsEqualElementEdge (void const* left,
|
|||
/// @brief checks for elements are equal (_from case)
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static bool IsEqualElementEdgeFromByKey (void const* left,
|
||||
void const* right) {
|
||||
static bool IsEqualElementEdgeFromByKey (void* userData,
|
||||
TRI_doc_mptr_t const* left,
|
||||
TRI_doc_mptr_t const* right) {
|
||||
TRI_ASSERT_EXPENSIVE(left != nullptr);
|
||||
TRI_ASSERT_EXPENSIVE(right != nullptr);
|
||||
|
||||
|
@ -281,8 +288,9 @@ static bool IsEqualElementEdgeFromByKey (void const* left,
|
|||
/// @brief checks for elements are equal (_to case)
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static bool IsEqualElementEdgeToByKey (void const* left,
|
||||
void const* right) {
|
||||
static bool IsEqualElementEdgeToByKey (void* userData,
|
||||
TRI_doc_mptr_t const* left,
|
||||
TRI_doc_mptr_t const* right) {
|
||||
TRI_ASSERT_EXPENSIVE(left != nullptr);
|
||||
TRI_ASSERT_EXPENSIVE(right != nullptr);
|
||||
|
||||
|
|
|
@ -54,7 +54,8 @@ static void FreeElement(TRI_index_element_t* element) {
|
|||
/// @brief determines if two elements are equal
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static bool IsEqualElementElement (TRI_index_element_t const* left,
|
||||
static bool IsEqualElementElement (void* userData,
|
||||
TRI_index_element_t const* left,
|
||||
TRI_index_element_t const* right) {
|
||||
return left->document() == right->document();
|
||||
}
|
||||
|
@ -63,7 +64,8 @@ static bool IsEqualElementElement (TRI_index_element_t const* left,
|
|||
/// @brief given a key generates a hash integer
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static uint64_t HashKey (TRI_hash_index_search_value_t const* key) {
|
||||
static uint64_t HashKey (void* userData,
|
||||
TRI_hash_index_search_value_t const* key) {
|
||||
uint64_t hash = 0x0123456789abcdef;
|
||||
|
||||
for (size_t j = 0; j < key->_length; ++j) {
|
||||
|
@ -78,7 +80,8 @@ static uint64_t HashKey (TRI_hash_index_search_value_t const* key) {
|
|||
/// @brief determines if a key corresponds to an element
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static bool IsEqualKeyElement (TRI_hash_index_search_value_t const* left,
|
||||
static bool IsEqualKeyElement (void* userData,
|
||||
TRI_hash_index_search_value_t const* left,
|
||||
TRI_index_element_t const* right) {
|
||||
TRI_ASSERT_EXPENSIVE(right->document() != nullptr);
|
||||
|
||||
|
@ -108,10 +111,11 @@ static bool IsEqualKeyElement (TRI_hash_index_search_value_t const* left,
|
|||
return true;
|
||||
}
|
||||
|
||||
static bool IsEqualKeyElementHash (TRI_hash_index_search_value_t const* left,
|
||||
static bool IsEqualKeyElementHash (void* userData,
|
||||
TRI_hash_index_search_value_t const* left,
|
||||
uint64_t const hash, // Has been computed but is not used here
|
||||
TRI_index_element_t const* right) {
|
||||
return IsEqualKeyElement(left, right);
|
||||
return IsEqualKeyElement(userData, left, right);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
|
|
|
@ -268,7 +268,8 @@ namespace triagens {
|
|||
: _numFields(n) {
|
||||
}
|
||||
|
||||
uint64_t operator() (TRI_index_element_t const* element,
|
||||
uint64_t operator() (void* userData,
|
||||
TRI_index_element_t const* element,
|
||||
bool byKey = true) {
|
||||
uint64_t hash = 0x0123456789abcdef;
|
||||
|
||||
|
@ -306,7 +307,8 @@ namespace triagens {
|
|||
: _numFields(n) {
|
||||
}
|
||||
|
||||
bool operator() (TRI_index_element_t const* left,
|
||||
bool operator() (void* userData,
|
||||
TRI_index_element_t const* left,
|
||||
TRI_index_element_t const* right) {
|
||||
TRI_ASSERT_EXPENSIVE(left->document() != nullptr);
|
||||
TRI_ASSERT_EXPENSIVE(right->document() != nullptr);
|
||||
|
|
|
@ -44,11 +44,13 @@ using namespace triagens::arango;
|
|||
// --SECTION-- private functions
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
static inline uint64_t HashKey (char const* key) {
|
||||
static inline uint64_t HashKey (void* userData,
|
||||
char const* key) {
|
||||
return TRI_FnvHashString(key);
|
||||
}
|
||||
|
||||
static inline uint64_t HashElement (TRI_doc_mptr_t const* element) {
|
||||
static inline uint64_t HashElement (void* userData,
|
||||
TRI_doc_mptr_t const* element) {
|
||||
return element->_hash;
|
||||
}
|
||||
|
||||
|
@ -56,7 +58,8 @@ static inline uint64_t HashElement (TRI_doc_mptr_t const* element) {
|
|||
/// @brief determines if a key corresponds to an element
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static bool IsEqualKeyElement (char const* key,
|
||||
static bool IsEqualKeyElement (void* userData,
|
||||
char const* key,
|
||||
uint64_t const hash,
|
||||
TRI_doc_mptr_t const* element) {
|
||||
|
||||
|
@ -68,7 +71,8 @@ static bool IsEqualKeyElement (char const* key,
|
|||
/// @brief determines if two elements are equal
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static bool IsEqualElementElement (TRI_doc_mptr_t const* left,
|
||||
static bool IsEqualElementElement (void* userData,
|
||||
TRI_doc_mptr_t const* left,
|
||||
TRI_doc_mptr_t const* right) {
|
||||
return left->_hash == right->_hash
|
||||
&& strcmp(TRI_EXTRACT_MARKER_KEY(left), TRI_EXTRACT_MARKER_KEY(right)) == 0;
|
||||
|
@ -317,12 +321,12 @@ int PrimaryIndex::resize (triagens::arango::Transaction* trx,
|
|||
return _primaryIndex->resize(trx, targetSize);
|
||||
}
|
||||
|
||||
uint64_t PrimaryIndex::calculateHash (triagens::arango::Transaction*,
|
||||
uint64_t PrimaryIndex::calculateHash (triagens::arango::Transaction* trx,
|
||||
char const* key) {
|
||||
return HashKey(key);
|
||||
return HashKey(trx, key);
|
||||
}
|
||||
|
||||
uint64_t PrimaryIndex::calculateHash (triagens::arango::Transaction*,
|
||||
uint64_t PrimaryIndex::calculateHash (triagens::arango::Transaction* trx,
|
||||
char const* key,
|
||||
size_t length) {
|
||||
return TRI_FnvHashPointer(static_cast<void const*>(key), length);
|
||||
|
|
|
@ -145,12 +145,14 @@ namespace triagens {
|
|||
public:
|
||||
static IndexType const INVALID_INDEX = ((IndexType)0)-1;
|
||||
|
||||
typedef std::function<uint64_t(Key const*)> HashKeyFuncType;
|
||||
typedef std::function<uint64_t(Element const*, bool)> HashElementFuncType;
|
||||
typedef std::function<bool(Key const*,
|
||||
typedef std::function<uint64_t(UserData*, Key const*)> HashKeyFuncType;
|
||||
typedef std::function<uint64_t(UserData*, Element const*, bool)> HashElementFuncType;
|
||||
typedef std::function<bool(UserData*,
|
||||
Key const*,
|
||||
Element const*)>
|
||||
IsEqualKeyElementFuncType;
|
||||
typedef std::function<bool(Element const*,
|
||||
typedef std::function<bool(UserData*,
|
||||
Element const*,
|
||||
Element const*)>
|
||||
IsEqualElementElementFuncType;
|
||||
typedef std::function<void(Element*)>
|
||||
|
@ -376,7 +378,7 @@ namespace triagens {
|
|||
#endif
|
||||
|
||||
// compute the hash by the key only first
|
||||
uint64_t hashByKey = _hashElement(element, true);
|
||||
uint64_t hashByKey = _hashElement(userData, element, true);
|
||||
Bucket& b = _buckets[hashByKey & _bucketsMask];
|
||||
|
||||
auto result = doInsert(userData, element, hashByKey, b, overwrite, checkEquality);
|
||||
|
@ -425,7 +427,7 @@ namespace triagens {
|
|||
std::unordered_map<uint64_t, DocumentsPerBucket> partitions;
|
||||
|
||||
for (size_t i = lower; i < upper; ++i) {
|
||||
uint64_t hashByKey = _hashElement(elements[i], true);
|
||||
uint64_t hashByKey = _hashElement(userData, elements[i], true);
|
||||
auto bucketId = hashByKey & _bucketsMask;
|
||||
|
||||
auto it = partitions.find(bucketId);
|
||||
|
@ -609,7 +611,7 @@ namespace triagens {
|
|||
while (b._table[i].ptr != nullptr &&
|
||||
(b._table[i].prev != INVALID_INDEX ||
|
||||
(useHashCache && b._table[i].readHashCache() != hashByKey) ||
|
||||
! _isEqualElementElementByKey(element, b._table[i].ptr))
|
||||
! _isEqualElementElementByKey(userData, element, b._table[i].ptr))
|
||||
) {
|
||||
i = incr(b, i);
|
||||
#ifdef TRI_INTERNAL_STATS
|
||||
|
@ -638,7 +640,7 @@ namespace triagens {
|
|||
// list of which we want to make element a member. Perhaps an
|
||||
// equal element is right here:
|
||||
if (checkEquality &&
|
||||
_isEqualElementElement(element, b._table[i].ptr)) {
|
||||
_isEqualElementElement(userData, element, b._table[i].ptr)) {
|
||||
old = b._table[i].ptr;
|
||||
if (overwrite) {
|
||||
TRI_ASSERT(! useHashCache ||
|
||||
|
@ -833,7 +835,7 @@ namespace triagens {
|
|||
(new std::vector<Element*>());
|
||||
|
||||
// compute the hash
|
||||
uint64_t hashByKey = _hashKey(key);
|
||||
uint64_t hashByKey = _hashKey(userData, key);
|
||||
Bucket const& b = _buckets[hashByKey & _bucketsMask];
|
||||
IndexType hashIndex = hashToIndex(hashByKey);
|
||||
IndexType i = hashIndex % b._nrAlloc;
|
||||
|
@ -847,7 +849,7 @@ namespace triagens {
|
|||
while (b._table[i].ptr != nullptr &&
|
||||
(b._table[i].prev != INVALID_INDEX ||
|
||||
(useHashCache && b._table[i].readHashCache() != hashByKey) ||
|
||||
! _isEqualKeyElement(key, b._table[i].ptr))
|
||||
! _isEqualKeyElement(userData, key, b._table[i].ptr))
|
||||
) {
|
||||
i = incr(b, i);
|
||||
#ifdef TRI_INTERNAL_STATS
|
||||
|
@ -882,7 +884,7 @@ namespace triagens {
|
|||
(new std::vector<Element*>());
|
||||
|
||||
// compute the hash
|
||||
uint64_t hashByKey = _hashElement(element, true);
|
||||
uint64_t hashByKey = _hashElement(userData, element, true);
|
||||
Bucket const& b = _buckets[hashByKey & _bucketsMask];
|
||||
IndexType hashIndex = hashToIndex(hashByKey);
|
||||
IndexType i = hashIndex % b._nrAlloc;
|
||||
|
@ -896,7 +898,7 @@ namespace triagens {
|
|||
while (b._table[i].ptr != nullptr &&
|
||||
(b._table[i].prev != INVALID_INDEX ||
|
||||
(useHashCache && b._table[i].readHashCache() != hashByKey) ||
|
||||
! _isEqualElementElementByKey(element, b._table[i].ptr))
|
||||
! _isEqualElementElementByKey(userData, element, b._table[i].ptr))
|
||||
) {
|
||||
i = incr(b, i);
|
||||
#ifdef TRI_INTERNAL_STATS
|
||||
|
@ -931,7 +933,7 @@ namespace triagens {
|
|||
std::unique_ptr<std::vector<Element*>> result
|
||||
(new std::vector<Element*>());
|
||||
|
||||
uint64_t hashByKey = _hashElement(element, true);
|
||||
uint64_t hashByKey = _hashElement(userData, element, true);
|
||||
Bucket const& b = _buckets[hashByKey & _bucketsMask];
|
||||
uint64_t hashByElm;
|
||||
IndexType i = findElementPlace(userData, b, element, true, hashByElm);
|
||||
|
@ -947,7 +949,7 @@ namespace triagens {
|
|||
while (b._table[i].ptr != nullptr &&
|
||||
(b._table[i].prev != INVALID_INDEX ||
|
||||
(useHashCache && b._table[i].readHashCache() != hashByKey) ||
|
||||
! _isEqualElementElementByKey(element, b._table[i].ptr))) {
|
||||
! _isEqualElementElementByKey(userData, element, b._table[i].ptr))) {
|
||||
i = incr(b, i);
|
||||
#ifdef TRI_INTERNAL_STATS
|
||||
_nrProbes++;
|
||||
|
@ -1029,7 +1031,7 @@ namespace triagens {
|
|||
if (useHashCache) {
|
||||
// We need to exchange the hashCache value by that of the key:
|
||||
b->_table[i].writeHashCache(
|
||||
_hashElement(b->_table[i].ptr, true));
|
||||
_hashElement(userData, b->_table[i].ptr, true));
|
||||
}
|
||||
#ifdef TRI_CHECK_MULTI_POINTER_HASH
|
||||
check(userData, false, false);
|
||||
|
@ -1189,7 +1191,7 @@ namespace triagens {
|
|||
hashByKey = oldTable[j].readHashCache();
|
||||
}
|
||||
else {
|
||||
hashByKey = _hashElement(oldTable[j].ptr, true);
|
||||
hashByKey = _hashElement(userData, oldTable[j].ptr, true);
|
||||
}
|
||||
IndexType insertPosition = insertFirst(userData, b, oldTable[j].ptr, hashByKey);
|
||||
// Now walk to the end of the list:
|
||||
|
@ -1204,7 +1206,7 @@ namespace triagens {
|
|||
hashByElm = oldTable[k].readHashCache();
|
||||
}
|
||||
else {
|
||||
hashByElm = _hashElement(oldTable[k].ptr, false);
|
||||
hashByElm = _hashElement(userData, oldTable[k].ptr, false);
|
||||
}
|
||||
insertFurther(userData, b, oldTable[k].ptr, hashByKey, hashByElm, insertPosition);
|
||||
k = oldTable[k].prev;
|
||||
|
@ -1277,7 +1279,7 @@ namespace triagens {
|
|||
IndexType hashIndex;
|
||||
if (b._table[i].prev == INVALID_INDEX) {
|
||||
// We are the first in a linked list.
|
||||
uint64_t hashByKey = _hashElement(b._table[i].ptr, true);
|
||||
uint64_t hashByKey = _hashElement(userData, b._table[i].ptr, true);
|
||||
hashIndex = hashToIndex(hashByKey);
|
||||
j = hashIndex % b._nrAlloc;
|
||||
if (useHashCache && b._table[i].readHashCache() != hashByKey) {
|
||||
|
@ -1286,7 +1288,8 @@ namespace triagens {
|
|||
for (k = j; k != i; ) {
|
||||
if (b._table[k].ptr == nullptr ||
|
||||
(b._table[k].prev == INVALID_INDEX &&
|
||||
_isEqualElementElementByKey(b._table[i].ptr,
|
||||
_isEqualElementElementByKey(userData,
|
||||
b._table[i].ptr,
|
||||
b._table[k].ptr))) {
|
||||
ok = false;
|
||||
std::cout << "Alarm pos bykey: " << i << std::endl;
|
||||
|
@ -1296,7 +1299,7 @@ namespace triagens {
|
|||
}
|
||||
else {
|
||||
// We are not the first in a linked list.
|
||||
uint64_t hashByElm = _hashElement(b._table[i].ptr, false);
|
||||
uint64_t hashByElm = _hashElement(userData, b._table[i].ptr, false);
|
||||
hashIndex = hashToIndex(hashByElm);
|
||||
j = hashIndex % b._nrAlloc;
|
||||
if (useHashCache && b._table[i].readHashCache() != hashByElm) {
|
||||
|
@ -1304,7 +1307,8 @@ namespace triagens {
|
|||
}
|
||||
for (k = j; k != i; ) {
|
||||
if (b._table[k].ptr == nullptr ||
|
||||
_isEqualElementElement(b._table[i].ptr,
|
||||
_isEqualElementElement(userData,
|
||||
b._table[i].ptr,
|
||||
b._table[k].ptr)) {
|
||||
ok = false;
|
||||
std::cout << "Alarm unique: " << k << ", "
|
||||
|
@ -1343,14 +1347,14 @@ namespace triagens {
|
|||
// pointer into the table, which is either empty or points to
|
||||
// an entry that compares equal to element.
|
||||
|
||||
hashByElm = _hashElement(element, false);
|
||||
hashByElm = _hashElement(userData, element, false);
|
||||
IndexType hashindex = hashToIndex(hashByElm);
|
||||
IndexType i = hashindex % b._nrAlloc;
|
||||
|
||||
while (b._table[i].ptr != nullptr &&
|
||||
(! checkEquality ||
|
||||
(useHashCache && b._table[i].readHashCache() != hashByElm) ||
|
||||
! _isEqualElementElement(element, b._table[i].ptr))) {
|
||||
! _isEqualElementElement(userData, element, b._table[i].ptr))) {
|
||||
i = incr(b, i);
|
||||
#ifdef TRI_INTERNAL_STATS
|
||||
_nrProbes++;
|
||||
|
@ -1369,7 +1373,7 @@ namespace triagens {
|
|||
// This performs a complete lookup for an element. It returns a slot
|
||||
// number. This slot is either empty or contains an element that
|
||||
// compares equal to element.
|
||||
uint64_t hashByKey = _hashElement(element, true);
|
||||
uint64_t hashByKey = _hashElement(userData, element, true);
|
||||
Bucket const& b = _buckets[hashByKey & _bucketsMask];
|
||||
buck = const_cast<Bucket*>(&b);
|
||||
IndexType hashIndex = hashToIndex(hashByKey);
|
||||
|
@ -1380,7 +1384,7 @@ namespace triagens {
|
|||
while (b._table[i].ptr != nullptr &&
|
||||
(b._table[i].prev != INVALID_INDEX ||
|
||||
(useHashCache && b._table[i].readHashCache() != hashByKey) ||
|
||||
! _isEqualElementElementByKey(element, b._table[i].ptr))) {
|
||||
! _isEqualElementElementByKey(userData, element, b._table[i].ptr))) {
|
||||
i = incr(b, i);
|
||||
#ifdef TRI_INTERNAL_STATS
|
||||
_nrProbes++;
|
||||
|
@ -1389,7 +1393,7 @@ namespace triagens {
|
|||
|
||||
if (b._table[i].ptr != nullptr) {
|
||||
// It might be right here!
|
||||
if (_isEqualElementElement(element, b._table[i].ptr)) {
|
||||
if (_isEqualElementElement(userData, element, b._table[i].ptr)) {
|
||||
return i;
|
||||
}
|
||||
|
||||
|
@ -1463,7 +1467,8 @@ namespace triagens {
|
|||
// Find out where this element ought to be:
|
||||
// If it is the start of one of the linked lists, we need to hash
|
||||
// by key, otherwise, we hash by the full identity of the element:
|
||||
uint64_t hash = _hashElement(b._table[j].ptr,
|
||||
uint64_t hash = _hashElement(userData,
|
||||
b._table[j].ptr,
|
||||
b._table[j].prev == INVALID_INDEX);
|
||||
IndexType hashIndex = hashToIndex(hash);
|
||||
IndexType k = hashIndex % b._nrAlloc;
|
||||
|
|
|
@ -87,11 +87,11 @@ namespace triagens {
|
|||
|
||||
public:
|
||||
|
||||
typedef std::function<uint64_t(Key const*)> HashKeyFuncType;
|
||||
typedef std::function<uint64_t(Element const*)> HashElementFuncType;
|
||||
typedef std::function<bool(Key const*, uint64_t hash, Element const*)>
|
||||
typedef std::function<uint64_t(UserData*, Key const*)> HashKeyFuncType;
|
||||
typedef std::function<uint64_t(UserData*, Element const*)> HashElementFuncType;
|
||||
typedef std::function<bool(UserData*, Key const*, uint64_t hash, Element const*)>
|
||||
IsEqualKeyElementFuncType;
|
||||
typedef std::function<bool(Element const*, Element const*)>
|
||||
typedef std::function<bool(UserData*, Element const*, Element const*)>
|
||||
IsEqualElementElementFuncType;
|
||||
|
||||
typedef std::function<void(Element*)> CallbackElementFuncType;
|
||||
|
@ -269,7 +269,7 @@ namespace triagens {
|
|||
|
||||
if (element != nullptr) {
|
||||
uint64_t i, k;
|
||||
i = k = _hashElement(element) % n;
|
||||
i = k = _hashElement(userData, element) % n;
|
||||
|
||||
for (; i < n && b._table[i] != nullptr; ++i);
|
||||
if (i == n) {
|
||||
|
@ -350,10 +350,10 @@ namespace triagens {
|
|||
uint64_t k = i;
|
||||
|
||||
for (; i < n && b._table[i] != nullptr &&
|
||||
! _isEqualElementElementByKey(element, b._table[i]); ++i);
|
||||
! _isEqualElementElementByKey(userData, element, b._table[i]); ++i);
|
||||
if (i == n) {
|
||||
for (i = 0; i < k && b._table[i] != nullptr &&
|
||||
! _isEqualElementElementByKey(element, b._table[i]); ++i);
|
||||
! _isEqualElementElementByKey(userData, element, b._table[i]); ++i);
|
||||
}
|
||||
|
||||
Element* arrayElement = b._table[i];
|
||||
|
@ -455,7 +455,7 @@ namespace triagens {
|
|||
|
||||
Element* find (UserData* userData,
|
||||
Element const* element) const {
|
||||
uint64_t i = _hashElement(element);
|
||||
uint64_t i = _hashElement(userData, element);
|
||||
Bucket const& b = _buckets[i & _bucketsMask];
|
||||
|
||||
uint64_t const n = b._nrAlloc;
|
||||
|
@ -463,10 +463,10 @@ namespace triagens {
|
|||
uint64_t k = i;
|
||||
|
||||
for (; i < n && b._table[i] != nullptr &&
|
||||
! _isEqualElementElementByKey(element, b._table[i]); ++i);
|
||||
! _isEqualElementElementByKey(userData, element, b._table[i]); ++i);
|
||||
if (i == n) {
|
||||
for (i = 0; i < k && b._table[i] != nullptr &&
|
||||
! _isEqualElementElementByKey(element, b._table[i]); ++i);
|
||||
! _isEqualElementElementByKey(userData, element, b._table[i]); ++i);
|
||||
}
|
||||
|
||||
// ...........................................................................
|
||||
|
@ -483,7 +483,7 @@ namespace triagens {
|
|||
|
||||
Element* findByKey (UserData* userData,
|
||||
Key const* key) const {
|
||||
uint64_t hash = _hashKey(key);
|
||||
uint64_t hash = _hashKey(userData, key);
|
||||
uint64_t i = hash;
|
||||
uint64_t bucketId = i & _bucketsMask;
|
||||
Bucket const& b = _buckets[bucketId];
|
||||
|
@ -493,10 +493,10 @@ namespace triagens {
|
|||
uint64_t k = i;
|
||||
|
||||
for (; i < n && b._table[i] != nullptr &&
|
||||
! _isEqualKeyElement(key, hash, b._table[i]); ++i);
|
||||
! _isEqualKeyElement(userData, key, hash, b._table[i]); ++i);
|
||||
if (i == n) {
|
||||
for (i = 0; i < k && b._table[i] != nullptr &&
|
||||
! _isEqualKeyElement(key, hash, b._table[i]); ++i);
|
||||
! _isEqualKeyElement(userData, key, hash, b._table[i]); ++i);
|
||||
}
|
||||
|
||||
// ...........................................................................
|
||||
|
@ -517,7 +517,7 @@ namespace triagens {
|
|||
Key const* key,
|
||||
BucketPosition& position,
|
||||
uint64_t& hash) const {
|
||||
hash = _hashKey(key);
|
||||
hash = _hashKey(userData, key);
|
||||
uint64_t i = hash;
|
||||
uint64_t bucketId = i & _bucketsMask;
|
||||
Bucket const& b = _buckets[bucketId];
|
||||
|
@ -527,10 +527,10 @@ namespace triagens {
|
|||
uint64_t k = i;
|
||||
|
||||
for (; i < n && b._table[i] != nullptr &&
|
||||
! _isEqualKeyElement(key, hash, b._table[i]); ++i);
|
||||
! _isEqualKeyElement(userData, key, hash, b._table[i]); ++i);
|
||||
if (i == n) {
|
||||
for (i = 0; i < k && b._table[i] != nullptr &&
|
||||
! _isEqualKeyElement(key, hash, b._table[i]); ++i);
|
||||
! _isEqualKeyElement(userData, key, hash, b._table[i]); ++i);
|
||||
}
|
||||
|
||||
// if requested, pass the position of the found element back
|
||||
|
@ -552,7 +552,7 @@ namespace triagens {
|
|||
|
||||
int insert (UserData* userData,
|
||||
Element* element) {
|
||||
uint64_t hash = _hashElement(element);
|
||||
uint64_t hash = _hashElement(userData, element);
|
||||
Bucket& b = _buckets[hash & _bucketsMask];
|
||||
|
||||
if (! checkResize(userData, b, 0)) {
|
||||
|
@ -622,7 +622,7 @@ namespace triagens {
|
|||
std::unordered_map<uint64_t, DocumentsPerBucket> partitions;
|
||||
|
||||
for (size_t i = lower; i < upper; ++i) {
|
||||
uint64_t hash = _hashElement(elements[i]);
|
||||
uint64_t hash = _hashElement(userData, elements[i]);
|
||||
auto bucketId = hash & _bucketsMask;
|
||||
|
||||
auto it = partitions.find(bucketId);
|
||||
|
@ -771,7 +771,7 @@ namespace triagens {
|
|||
uint64_t k = TRI_IncModU64(i, n);
|
||||
|
||||
while (b._table[k] != nullptr) {
|
||||
uint64_t j = _hashElement(b._table[k]) % n;
|
||||
uint64_t j = _hashElement(userData, b._table[k]) % n;
|
||||
|
||||
if ((i < k && ! (i < j && j <= k)) || (k < i && ! (i < j || j <= k))) {
|
||||
b._table[i] = b._table[k];
|
||||
|
@ -796,7 +796,7 @@ namespace triagens {
|
|||
|
||||
Element* removeByKey (UserData* userData,
|
||||
Key const* key) {
|
||||
uint64_t hash = _hashKey(key);
|
||||
uint64_t hash = _hashKey(userData, key);
|
||||
uint64_t i = hash;
|
||||
Bucket& b = _buckets[i & _bucketsMask];
|
||||
|
||||
|
@ -805,10 +805,10 @@ namespace triagens {
|
|||
uint64_t k = i;
|
||||
|
||||
for (; i < n && b._table[i] != nullptr &&
|
||||
! _isEqualKeyElement(key, hash, b._table[i]); ++i);
|
||||
! _isEqualKeyElement(userData, key, hash, b._table[i]); ++i);
|
||||
if (i == n) {
|
||||
for (i = 0; i < k && b._table[i] != nullptr &&
|
||||
! _isEqualKeyElement(key, hash, b._table[i]); ++i);
|
||||
! _isEqualKeyElement(userData, key, hash, b._table[i]); ++i);
|
||||
}
|
||||
|
||||
Element* old = b._table[i];
|
||||
|
@ -826,7 +826,7 @@ namespace triagens {
|
|||
|
||||
Element* remove (UserData* userData,
|
||||
Element const* element) {
|
||||
uint64_t i = _hashElement(element);
|
||||
uint64_t i = _hashElement(userData, element);
|
||||
Bucket& b = _buckets[i & _bucketsMask];
|
||||
|
||||
uint64_t const n = b._nrAlloc;
|
||||
|
@ -834,10 +834,10 @@ namespace triagens {
|
|||
uint64_t k = i;
|
||||
|
||||
for (; i < n && b._table[i] != nullptr &&
|
||||
! _isEqualElementElement(element, b._table[i]); ++i);
|
||||
! _isEqualElementElement(userData, element, b._table[i]); ++i);
|
||||
if (i == n) {
|
||||
for (i = 0; i < k && b._table[i] != nullptr &&
|
||||
! _isEqualElementElement(element, b._table[i]); ++i);
|
||||
! _isEqualElementElement(userData, element, b._table[i]); ++i);
|
||||
}
|
||||
|
||||
Element* old = b._table[i];
|
||||
|
|
Loading…
Reference in New Issue