99
1010#pragma once
1111
12+ #define XXH_INLINE_ALL
13+
14+ #include < 3rd_party/xxhash/xxhash.h>
1215#include < aggregator/field.hpp>
16+ #include < common/common.hpp>
1317
1418#include < cstddef>
19+ #include < functional>
1520#include < memory>
1621#include < vector>
1722
@@ -28,6 +33,10 @@ class View {
2833 /* *
2934 * @brief The ordering/sorting direction
3035 */
36+ using KeyHashFnType = std::function<uint64_t (const uint8_t *)>;
37+ using KeyEqualsFnType = std::function<bool (const uint8_t *, const uint8_t *)>;
38+ using RecOrdFnType = std::function<bool (const uint8_t *, const uint8_t *)>;
39+
3140 enum class OrderDirection {
3241 Ascending,
3342 Descending
@@ -399,6 +408,45 @@ class View {
399408 */
400409 bool is_fixed_size () const { return m_is_fixed_size; }
401410
411+ uint64_t key_hash (const uint8_t *key) const
412+ {
413+ return XXH3_64bits (key, key_size (key));
414+ }
415+
416+ bool key_equals (const uint8_t *key1, const uint8_t *key2) const
417+ {
418+ std::size_t key1_size = key_size (key1);
419+ std::size_t key2_size = key_size (key2);
420+ return key1_size == key2_size && std::memcmp (key1, key2, key1_size) == 0 ;
421+ }
422+
423+ KeyHashFnType key_hasher () const
424+ {
425+ return [this ](const uint8_t *key) { return key_hash (key); };
426+ }
427+
428+ KeyEqualsFnType key_equaler () const
429+ {
430+ return [this ](const uint8_t *key1, const uint8_t *key2) { return key_equals (key1, key2); };
431+ }
432+
433+ RecOrdFnType rec_orderer () const
434+ {
435+ return [this ](const uint8_t *rec1, const uint8_t *rec2) {
436+ return compare (rec1, rec2) == CmpResult::Lt;
437+ };
438+ }
439+
440+ RecOrdFnType rec_reverse_orderer () const
441+ {
442+ return [this ](const uint8_t *rec1, const uint8_t *rec2) {
443+ return compare (rec1, rec2) == CmpResult::Gt;
444+ };
445+ }
446+
447+ CmpResult
448+ compare (const uint8_t *rec1, const uint8_t *rec2) const ;
449+
402450private:
403451 View () = default ;
404452
0 commit comments