Skip to content

Commit

Permalink
use std::hash and C++11
Browse files Browse the repository at this point in the history
  • Loading branch information
Frantisek Boranek authored and Frantisek Boranek committed Oct 18, 2018
1 parent 70d9c88 commit 501d564
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
3 changes: 2 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ AC_CONFIG_FILES([tests/Makefile])

# check for C++ compiler
AC_PROG_CXX
AC_LANG_CPLUSPLUS
AX_CHECK_COMPILE_FLAG([-std=c++11], [],[AC_MSG_ERROR([Compiler without c++11])])

# pkg config
PKG_PROG_PKG_CONFIG([0.25])
Expand Down Expand Up @@ -145,7 +147,6 @@ AC_CHECK_HEADERS(fenv.h)
AC_CHECK_LIB(m, floor)
AC_REPLACE_FUNCS([trunc round])

AC_LANG_CPLUSPLUS
AC_CHECK_LIB([pcre++], [_init],,AC_MSG_ERROR([pcre++ not installed]))

AX_CHECK_COMPILE_FLAG([-std=c++14], [
Expand Down
2 changes: 1 addition & 1 deletion src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
AM_CXXFLAGS = -Wall

# extra compiler options
AM_CPPFLAGS = -D_ISOC99_SOURCE -fPIC ${DEPENS_CFLAGS}
AM_CPPFLAGS = -std=c++11 -D_ISOC99_SOURCE -fPIC ${DEPENS_CFLAGS}

# these are generated and thus ought to be prepared before anything else
BUILT_SOURCES = tenglex2.cc tengsyntax.cc
Expand Down
20 changes: 13 additions & 7 deletions src/tengfilesystem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@
#include <sys/stat.h>
#include <unistd.h>

#include <functional>
#include <stdexcept>
#include <stdio.h>

#include "tengfilesystem.h"
#include "tengutil.h"
#include "tengplatform.h"

#include <boost/functional/hash.hpp>
#include "tengutil.h"

namespace Teng {

Expand All @@ -42,6 +41,13 @@ static std::string makeFilename(const std::string& root, const std::string& file
return filename;
}

template<class S>
static void hashCombine(std::size_t& seed, S const& value)
{
std::size_t hash = std::hash<S>{}(value);
seed ^= hash + 0x9e3779b9 + (seed<<6) + (seed>>2); // or use boost::hash_combine
}

Filesystem_t::Filesystem_t(const std::string& root_)
: root(root_)
{
Expand Down Expand Up @@ -96,10 +102,10 @@ size_t Filesystem_t::hash(const std::string& filename_) const
throw std::runtime_error("File '" + filename + "' is a directory");
}

boost::hash_combine(seed, buf.st_ino);
boost::hash_combine(seed, buf.st_size);
boost::hash_combine(seed, buf.st_mtime);
boost::hash_combine(seed, buf.st_ctime);
hashCombine(seed, buf.st_ino); // unsigned long int - inode number
hashCombine(seed, buf.st_size); // long - total size, in bytes
hashCombine(seed, buf.st_mtime); // long - time of last modification
hashCombine(seed, buf.st_ctime); // long - time of last status change

return seed;
}
Expand Down

0 comments on commit 501d564

Please sign in to comment.