Skip to content

Commit

Permalink
Remove HAVE_BOOST, break StringPiece hash into separate header
Browse files Browse the repository at this point in the history
  • Loading branch information
kpu committed Jan 21, 2013
1 parent ff15b5a commit 0429861
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 48 deletions.
2 changes: 1 addition & 1 deletion Jamroot
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ path-constant TOP : . ;
include $(TOP)/jam-files/sanity.jam ;

boost 103600 ;
project : requirements $(requirements) <define>HAVE_BOOST <include>. ;
project : requirements $(requirements) <include>. ;
project : default-build <threading>multi <warnings>on <variant>release ;

external-lib z ;
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ Hideo Okuma and Tomoyuki Yoshimura from NICT contributed ports to ARM and MinGW.
There are a number of macros you can set on the g++ command line or in util/have.hh .

* `KENLM_MAX_ORDER` is the maximum order that can be loaded. This is done to make state an efficient POD rather than a vector.
* `HAVE_BOOST` enables Boost-style hashing of StringPiece. This is only needed if you intend to hash StringPiece in your code.
* `HAVE_ICU` If your code links against ICU, define this to disable the internal StringPiece and replace it with ICU's copy of StringPiece, avoiding naming conflicts.

ARPA files can be read in compressed format with these options:
Expand Down
5 changes: 4 additions & 1 deletion jam-files/sanity.jam
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ if $(with-macports) {
boost-search = <search>$(with-macports)/lib ;
I-boost-include = -I$(with-macports)/include ;
boost-include = <include>$(with-macports)/include ;
requirements += $(boost-include) ;
} else {
with-boost = [ option.get "with-boost" ] ;
with-boost ?= [ os.environ "BOOST_ROOT" ] ;
Expand All @@ -103,6 +104,7 @@ if $(with-macports) {
boost-search = <search>$(with-boost)/lib <search>$(with-boost)/lib64 ;
I-boost-include = -I$(with-boost)/include ;
boost-include = <include>$(with-boost)/include ;
requirements += $(boost-include) ;
} else {
L-boost-search = "" ;
boost-search = ;
Expand All @@ -127,7 +129,8 @@ rule boost-lib ( name macro : deps * ) {
lib inner_boost_$(name) : : $(boost-search) <name>boost_$(name)$(boost-lib-version) : : <library>$(deps) ;
}

alias boost_$(name) : inner_boost_$(name) : $(boost-auto-shared) : : <link>shared:<define>BOOST_$(macro) $(boost-include) ;
alias boost_$(name) : inner_boost_$(name) : $(boost-auto-shared) : : <link>shared:<define>BOOST_$(macro) ;
requirements += <link>shared:<define>BOOST_$(macro) ;
}

#Argument is e.g. 103600
Expand Down
1 change: 1 addition & 0 deletions lm/filter/vocab.hh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "util/multi_intersection.hh"
#include "util/string_piece.hh"
#include "util/string_piece_hash.hh"
#include "util/tokenize_piece.hh"

#include <boost/noncopyable.hpp>
Expand Down
4 changes: 0 additions & 4 deletions util/have.hh
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,4 @@
//#define HAVE_ICU
#endif

#ifndef HAVE_BOOST
//#define HAVE_BOOST
#endif

#endif // UTIL_HAVE__
41 changes: 0 additions & 41 deletions util/string_piece.hh
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@

#include "util/have.hh"

#ifdef HAVE_BOOST
#include <boost/functional/hash/hash.hpp>
#endif // HAVE_BOOST

#include <cstring>
#include <iosfwd>
#include <ostream>
Expand Down Expand Up @@ -256,46 +252,9 @@ inline std::ostream& operator<<(std::ostream& o, const StringPiece& piece) {
return o.write(piece.data(), static_cast<std::streamsize>(piece.size()));
}

#ifdef HAVE_BOOST
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

#ifdef HAVE_ICU
U_NAMESPACE_END
using U_NAMESPACE_QUALIFIER StringPiece;
#endif


#endif // BASE_STRING_PIECE_H__
43 changes: 43 additions & 0 deletions util/string_piece_hash.hh
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__

0 comments on commit 0429861

Please sign in to comment.