Unverified Commit 18f3ca71 authored by Tommaso Tocci's avatar Tommaso Tocci
Browse files

squash! Use file ID instead of path on data operations

parent e57ed00d
Loading
Loading
Loading
Loading
+23 −0
Original line number Diff line number Diff line
#ifndef GKFS_HASH_UTIL_HPP
#define GKFS_HASH_UTIL_HPP

#include <functional>

template <class T>
inline void hash_combine(std::size_t & seed, const T & v) {
    std::hash<T> hasher;
    seed ^= hasher(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
}

namespace std {
    template<typename S, typename T> struct hash<pair<S, T>> {
        inline size_t operator()(const pair<S, T> & v) const {
            size_t seed = 0;
            ::hash_combine(seed, v.first);
            ::hash_combine(seed, v.second);
            return seed;
        }
    };
}

#endif //GKFS_HASH_UTIL_HPP
+0 −1
Original line number Diff line number Diff line
@@ -25,7 +25,6 @@ class SimpleHashDistributor : public Distributor {
        Host localhost_;
        unsigned int hosts_size_;
        std::vector<Host> all_hosts_;
        std::hash<std::string> str_hash;
    public:
        SimpleHashDistributor(Host localhost, unsigned int hosts_size);
        Host localhost() const override;
+1 −0
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@ target_sources(distributor
    ${INCLUDE_DIR}/global/global_defs.hpp
    PRIVATE
    ${CMAKE_CURRENT_LIST_DIR}/rpc/distributor.cpp
    ${INCLUDE_DIR}/global/hash_util.hpp
    )

add_library(log_util STATIC)
+5 −5
Original line number Diff line number Diff line
#include "global/rpc/distributor.hpp"
#include "global/hash_util.hpp"


SimpleHashDistributor::
@@ -17,15 +18,14 @@ localhost() const {

Host SimpleHashDistributor::
locate_data(const fuid_t fuid, const ChunkID chnk_id) const {
    /* We could have also used boost::hash_combine.
     * See https://en.cppreference.com/w/cpp/utility/hash for more details.
     */
    return (fuid + chnk_id) % hosts_size_;
    std::hash<std::pair<fuid_t, ChunkID>> hasher;
    return hasher(std::make_pair(fuid, chnk_id)) % hosts_size_;;
}

Host SimpleHashDistributor::
locate_file_metadata(const std::string& path) const {
    return str_hash(path) % hosts_size_;
    std::hash<std::string> hasher;
    return hasher(path) % hosts_size_;
}