forked from kpu/kenlm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove HAVE_BOOST, break StringPiece hash into separate header
- Loading branch information
Showing
7 changed files
with
49 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,8 +10,4 @@ | |
//#define HAVE_ICU | ||
#endif | ||
|
||
#ifndef HAVE_BOOST | ||
//#define HAVE_BOOST | ||
#endif | ||
|
||
#endif // UTIL_HAVE__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#ifndef UTIL_STRING_PIECE_HASH__ | ||
#define UTIL_STRING_PIECE_HASH__ | ||
|
||
#include "util/string_piece.hh" | ||
|
||
#include <boost/functional/hash.hpp> | ||
#include <boost/version.hpp> | ||
|
||
inline size_t hash_value(const StringPiece &str) { | ||
return boost::hash_range(str.data(), str.data() + str.length()); | ||
} | ||
|
||
/* Support for lookup of StringPiece in boost::unordered_map<std::string> */ | ||
struct StringPieceCompatibleHash : public std::unary_function<const StringPiece &, size_t> { | ||
size_t operator()(const StringPiece &str) const { | ||
return hash_value(str); | ||
} | ||
}; | ||
|
||
struct StringPieceCompatibleEquals : public std::binary_function<const StringPiece &, const std::string &, bool> { | ||
bool operator()(const StringPiece &first, const StringPiece &second) const { | ||
return first == second; | ||
} | ||
}; | ||
template <class T> typename T::const_iterator FindStringPiece(const T &t, const StringPiece &key) { | ||
#if BOOST_VERSION < 104200 | ||
std::string temp(key.data(), key.size()); | ||
return t.find(temp); | ||
#else | ||
return t.find(key, StringPieceCompatibleHash(), StringPieceCompatibleEquals()); | ||
#endif | ||
} | ||
|
||
template <class T> typename T::iterator FindStringPiece(T &t, const StringPiece &key) { | ||
#if BOOST_VERSION < 104200 | ||
std::string temp(key.data(), key.size()); | ||
return t.find(temp); | ||
#else | ||
return t.find(key, StringPieceCompatibleHash(), StringPieceCompatibleEquals()); | ||
#endif | ||
} | ||
|
||
#endif // UTIL_STRING_PIECE_HASH__ |