forked from Mirrors/privacore-open-source-search-engine
Some helper functions
This commit is contained in:
26
types.cpp
Normal file
26
types.cpp
Normal file
@ -0,0 +1,26 @@
|
||||
//
|
||||
// Copyright (C) 2017 Privacore ApS - https://www.privacore.com
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// License TL;DR: If you change this file, you must publish your changes.
|
||||
//
|
||||
|
||||
#include "types.h"
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const u_int96_t& key) {
|
||||
const char *keyStr = KEYSTR((const void*)&key, sizeof(key));
|
||||
os.write(keyStr, strlen(keyStr));
|
||||
return os;
|
||||
}
|
11
types.h
11
types.h
@ -4,6 +4,8 @@
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include "Sanity.h"
|
||||
#include <functional>
|
||||
#include <ostream>
|
||||
//#include "collnum_t.h"
|
||||
|
||||
|
||||
@ -718,5 +720,14 @@ static inline const char *KEYMAX() {
|
||||
return (const char *)s_foo;
|
||||
}
|
||||
|
||||
struct KeyHash {
|
||||
std::size_t operator()(u_int96_t const& key) const noexcept {
|
||||
std::size_t h1 = std::hash<uint64_t>{}(key.n0);
|
||||
std::size_t h2 = std::hash<uint32_t>{}(key.n1);
|
||||
return h1 ^ (h2 << 1);
|
||||
}
|
||||
};
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const u_int96_t& key);
|
||||
|
||||
#endif // GB_TYPES_H
|
||||
|
Reference in New Issue
Block a user