summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--eval/src/vespa/eval/eval/basic_nodes.h5
-rw-r--r--eval/src/vespa/eval/eval/key_gen.cpp6
-rw-r--r--eval/src/vespa/eval/eval/llvm/llvm_wrapper.cpp5
-rw-r--r--eval/src/vespa/eval/eval/make_tensor_function.cpp2
-rw-r--r--eval/src/vespa/eval/eval/test/eval_spec.cpp10
-rw-r--r--eval/src/vespa/eval/eval/test/reference_evaluation.cpp2
-rw-r--r--searchlib/src/tests/features/prod_features.cpp20
-rw-r--r--searchlib/src/vespa/searchlib/features/attributefeature.cpp6
-rw-r--r--searchlib/src/vespa/searchlib/features/utils.h8
-rw-r--r--searchlib/src/vespa/searchlib/fef/query_value.cpp18
-rw-r--r--searchlib/src/vespa/searchlib/fef/query_value.h2
-rw-r--r--vespalib/src/vespa/vespalib/locale/c.cpp2
-rw-r--r--vespalib/src/vespa/vespalib/util/string_hash.cpp6
-rw-r--r--vespalib/src/vespa/vespalib/util/string_hash.h4
14 files changed, 47 insertions, 49 deletions
diff --git a/eval/src/vespa/eval/eval/basic_nodes.h b/eval/src/vespa/eval/eval/basic_nodes.h
index 2db00bbcb7d..af6ee24289a 100644
--- a/eval/src/vespa/eval/eval/basic_nodes.h
+++ b/eval/src/vespa/eval/eval/basic_nodes.h
@@ -6,6 +6,7 @@
#include "string_stuff.h"
#include <vespa/vespalib/util/hdr_abort.h>
#include <vespa/vespalib/stllike/string.h>
+#include <vespa/vespalib/stllike/hash_fun.h>
#include <vespa/vespalib/util/string_hash.h>
#include <memory>
#include <map>
@@ -120,9 +121,9 @@ private:
public:
String(const vespalib::string &value_in) : _value(value_in) {}
bool is_const_double() const override { return true; }
- double get_const_double_value() const override { return hash(); }
+ double get_const_double_value() const override { return hash2d(_value); }
const vespalib::string &value() const { return _value; }
- uint32_t hash() const { return hash_code(_value.data(), _value.size()); }
+ uint64_t hash() const { return hashValue(_value.data(), _value.size()); }
vespalib::string dump(DumpContext &) const override {
return as_quoted_string(_value);
}
diff --git a/eval/src/vespa/eval/eval/key_gen.cpp b/eval/src/vespa/eval/eval/key_gen.cpp
index a8f9700e865..6bf61f5336e 100644
--- a/eval/src/vespa/eval/eval/key_gen.cpp
+++ b/eval/src/vespa/eval/eval/key_gen.cpp
@@ -4,8 +4,7 @@
#include "node_visitor.h"
#include "node_traverser.h"
-namespace vespalib {
-namespace eval {
+namespace vespalib::eval {
using namespace nodes;
@@ -106,5 +105,4 @@ vespalib::string gen_key(const Function &function, PassParams pass_params)
return key_gen.key;
}
-} // namespace vespalib::eval
-} // namespace vespalib
+}
diff --git a/eval/src/vespa/eval/eval/llvm/llvm_wrapper.cpp b/eval/src/vespa/eval/eval/llvm/llvm_wrapper.cpp
index 158bc91dd6a..3fafb8f8b18 100644
--- a/eval/src/vespa/eval/eval/llvm/llvm_wrapper.cpp
+++ b/eval/src/vespa/eval/eval/llvm/llvm_wrapper.cpp
@@ -12,7 +12,6 @@
#include <llvm/IR/IRBuilder.h>
#include <llvm/IR/Intrinsics.h>
#include <llvm/ExecutionEngine/ExecutionEngine.h>
-#include <llvm/Analysis/Passes.h>
#include <llvm/IR/DataLayout.h>
#include <llvm/Transforms/Scalar.h>
#include <llvm/Transforms/IPO/PassManagerBuilder.h>
@@ -176,7 +175,7 @@ struct FunctionBuilder : public NodeVisitor, public NodeTraverser {
params.push_back(&(*itr));
}
}
- ~FunctionBuilder();
+ ~FunctionBuilder() override;
//-------------------------------------------------------------------------
@@ -385,7 +384,7 @@ struct FunctionBuilder : public NodeVisitor, public NodeTraverser {
push(get_param(item.id()));
}
void visit(const String &item) override {
- push_double(item.hash());
+ push_double(item.get_const_double_value());
}
void visit(const In &item) override {
llvm::Value *lhs = pop_double();
diff --git a/eval/src/vespa/eval/eval/make_tensor_function.cpp b/eval/src/vespa/eval/eval/make_tensor_function.cpp
index 1386196e719..72e8ac6cbde 100644
--- a/eval/src/vespa/eval/eval/make_tensor_function.cpp
+++ b/eval/src/vespa/eval/eval/make_tensor_function.cpp
@@ -167,7 +167,7 @@ struct TensorFunctionBuilder : public NodeVisitor, public NodeTraverser {
make_inject(node, node.id());
}
void visit(const String &node) override {
- make_const(node, stash.create<DoubleValue>(node.hash()));
+ make_const(node, stash.create<DoubleValue>(node.get_const_double_value()));
}
void visit(const In &node) override {
auto my_in = std::make_unique<In>(std::make_unique<Symbol>(0));
diff --git a/eval/src/vespa/eval/eval/test/eval_spec.cpp b/eval/src/vespa/eval/eval/test/eval_spec.cpp
index 02e9c34a75e..3bd9df18438 100644
--- a/eval/src/vespa/eval/eval/test/eval_spec.cpp
+++ b/eval/src/vespa/eval/eval/test/eval_spec.cpp
@@ -124,11 +124,11 @@ EvalSpec::add_terminal_cases() {
add_expression({}, "10").add_case({}, 10.0);
add_expression({}, "100").add_case({}, 100.0);
add_rule({"a", -5.0, 5.0}, "a", [](double a){ return a; });
- add_expression({}, "\"\"").add_case({}, vespalib::hash_code(""));
- add_expression({}, "\"foo\"").add_case({}, vespalib::hash_code("foo"));
- add_expression({}, "\"foo bar baz\"").add_case({}, vespalib::hash_code("foo bar baz"));
- add_expression({}, "\">\\\\\\\"\\t\\n\\r\\f<\"").add_case({}, vespalib::hash_code(">\\\"\t\n\r\f<"));
- add_expression({}, "\">\\x08\\x10\\x12\\x14<\"").add_case({}, vespalib::hash_code(">\x08\x10\x12\x14<"));
+ add_expression({}, "\"\"").add_case({}, vespalib::hash2d(""));
+ add_expression({}, "\"foo\"").add_case({}, vespalib::hash2d("foo"));
+ add_expression({}, "\"foo bar baz\"").add_case({}, vespalib::hash2d("foo bar baz"));
+ add_expression({}, "\">\\\\\\\"\\t\\n\\r\\f<\"").add_case({}, vespalib::hash2d(">\\\"\t\n\r\f<"));
+ add_expression({}, "\">\\x08\\x10\\x12\\x14<\"").add_case({}, vespalib::hash2d(">\x08\x10\x12\x14<"));
}
void
diff --git a/eval/src/vespa/eval/eval/test/reference_evaluation.cpp b/eval/src/vespa/eval/eval/test/reference_evaluation.cpp
index da0f5a1d1f0..acbc7463e28 100644
--- a/eval/src/vespa/eval/eval/test/reference_evaluation.cpp
+++ b/eval/src/vespa/eval/eval/test/reference_evaluation.cpp
@@ -145,7 +145,7 @@ struct EvalNode : public NodeVisitor {
eval_param(node.id());
}
void visit(const String &node) override {
- eval_const(num(node.hash()));
+ eval_const(num(node.get_const_double_value()));
}
void visit(const In &node) override {
auto my_op1 = [&](double a) {
diff --git a/searchlib/src/tests/features/prod_features.cpp b/searchlib/src/tests/features/prod_features.cpp
index 80650050b25..73b66f36172 100644
--- a/searchlib/src/tests/features/prod_features.cpp
+++ b/searchlib/src/tests/features/prod_features.cpp
@@ -251,13 +251,13 @@ Test::testAttribute()
addScore("attribute(sebool)", 0).
addScore("attribute(sfloat)", 60.5f).
addScore("attribute(sdouble)", 67.5f).
- addScore("attribute(sstr)", (feature_t)vespalib::hash_code("foo")).
+ addScore("attribute(sstr)", vespalib::hash2d("foo")).
addScore("attribute(sint).count", 1).
addScore("attribute(sfloat).count", 1).
addScore("attribute(sstr).count", 1).
addScore("attribute(udefint)", search::attribute::getUndefined<feature_t>()).
addScore("attribute(udeffloat)", search::attribute::getUndefined<feature_t>()).
- addScore("attribute(udefstr)", (feature_t)vespalib::hash_code(""));
+ addScore("attribute(udefstr)", vespalib::hash2d(""));
FtFeatureTest ft(_factory, exp.getKeys());
ft.getIndexEnv().getBuilder()
@@ -284,8 +284,8 @@ Test::testAttribute()
addScore("attribute(aint,2)", 0).
addScore("attribute(afloat,0)", 70.5f).
addScore("attribute(afloat,1)", 80.5f).
- addScore("attribute(astr,0)", (feature_t)vespalib::hash_code("bar")).
- addScore("attribute(astr,1)", (feature_t)vespalib::hash_code("baz")).
+ addScore("attribute(astr,0)", vespalib::hash2d("bar")).
+ addScore("attribute(astr,1)", vespalib::hash2d("baz")).
addScore("attribute(aint).count", 2).
addScore("attribute(aint,0).count", 0).
addScore("attribute(afloat).count", 2).
@@ -333,10 +333,10 @@ Test::testAttribute()
addScore("attribute(wsstr,foo).value", 0).
addScore("attribute(wsstr,foo).weight", 0).
addScore("attribute(wsstr,foo).contains", 0).
- addScore("attribute(wsstr,qux).value", (feature_t)vespalib::hash_code("qux")).
+ addScore("attribute(wsstr,qux).value", vespalib::hash2d("qux")).
addScore("attribute(wsstr,qux).weight", 11).
addScore("attribute(wsstr,qux).contains", 1).
- addScore("attribute(wsstr,quux).value", (feature_t)vespalib::hash_code("quux")).
+ addScore("attribute(wsstr,quux).value", vespalib::hash2d("quux")).
addScore("attribute(wsstr,quux).weight", 12).
addScore("attribute(wsstr,quux).contains", 1).
addScore("attribute(wsint).count", 2).
@@ -1762,10 +1762,10 @@ Test::testQuery()
addScore("query(def3)", 0.0).
addScore("query(val1)", 1.1).
addScore("query(val2)", 2.2).
- addScore("query(hash1)", vespalib::hash_code("foo")).
- addScore("query(hash2)", vespalib::hash_code("2")).
- addScore("query(hash3)", vespalib::hash_code("foo")).
- addScore("query(hash4)", vespalib::hash_code("'foo"));
+ addScore("query(hash1)", vespalib::hash2d("foo")).
+ addScore("query(hash2)", vespalib::hash2d("2")).
+ addScore("query(hash3)", vespalib::hash2d("foo")).
+ addScore("query(hash4)", vespalib::hash2d("'foo"));
FtFeatureTest ft(_factory, exp.getKeys());
ft.getIndexEnv().getProperties()
.add("query(def1)", "1.0")
diff --git a/searchlib/src/vespa/searchlib/features/attributefeature.cpp b/searchlib/src/vespa/searchlib/features/attributefeature.cpp
index 8afb5ec1f21..dae1ccc994b 100644
--- a/searchlib/src/vespa/searchlib/features/attributefeature.cpp
+++ b/searchlib/src/vespa/searchlib/features/attributefeature.cpp
@@ -113,7 +113,7 @@ public:
*
* @param attribute The attribute vector to use.
*/
- SingleAttributeExecutor(const T & attribute) : _attribute(attribute) { }
+ explicit SingleAttributeExecutor(const T & attribute) : _attribute(attribute) { }
void handle_bind_outputs(vespalib::ArrayRef<fef::NumberOrObject> outputs_in) override {
fef::FeatureExecutor::handle_bind_outputs(outputs_in);
auto o = outputs().get_bound();
@@ -128,7 +128,7 @@ class BoolAttributeExecutor final : public fef::FeatureExecutor {
private:
const SingleBoolAttribute & _attribute;
public:
- BoolAttributeExecutor(const SingleBoolAttribute & attribute)
+ explicit BoolAttributeExecutor(const SingleBoolAttribute & attribute)
: _attribute(attribute)
{}
void execute(uint32_t docId) override {
@@ -162,7 +162,7 @@ private:
const attribute::IAttributeVector & _attribute;
public:
- CountOnlyAttributeExecutor(const attribute::IAttributeVector & attribute) : _attribute(attribute) { }
+ explicit CountOnlyAttributeExecutor(const attribute::IAttributeVector & attribute) : _attribute(attribute) { }
void execute(uint32_t docId) override;
void handle_bind_outputs(vespalib::ArrayRef<fef::NumberOrObject> outputs_in) override {
fef::FeatureExecutor::handle_bind_outputs(outputs_in);
diff --git a/searchlib/src/vespa/searchlib/features/utils.h b/searchlib/src/vespa/searchlib/features/utils.h
index eeecd55c6da..9a8ddacb99f 100644
--- a/searchlib/src/vespa/searchlib/features/utils.h
+++ b/searchlib/src/vespa/searchlib/features/utils.h
@@ -57,7 +57,7 @@ inline feature_t getAsFeature(T value)
*/
template <>
inline feature_t getAsFeature<ConstCharPtr>(ConstCharPtr value) {
- return static_cast<feature_t>(vespalib::hash_code(value, strlen(value)));
+ return vespalib::hash2d(value, strlen(value));
}
/**
@@ -68,7 +68,7 @@ inline feature_t getAsFeature<ConstCharPtr>(ConstCharPtr value) {
*/
template <>
inline feature_t getAsFeature<vespalib::stringref>(vespalib::stringref value) {
- return static_cast<feature_t>(vespalib::hash_code(value));
+ return vespalib::hash2d(value);
}
@@ -184,7 +184,7 @@ lookupTable(const search::fef::IIndexEnvironment & env, const vespalib::string &
inline const search::fef::ITermFieldData *
getTermFieldData(const search::fef::IQueryEnvironment &env, uint32_t termId, uint32_t fieldId) {
const search::fef::ITermData *td = env.getTerm(termId);
- return (td == 0) ? 0 : td->lookupField(fieldId);
+ return (td == nullptr) ? nullptr : td->lookupField(fieldId);
}
/**
@@ -198,7 +198,7 @@ getTermFieldData(const search::fef::IQueryEnvironment &env, uint32_t termId, uin
inline search::fef::TermFieldHandle
getTermFieldHandle(const search::fef::IQueryEnvironment &env, uint32_t termId, uint32_t fieldId) {
const search::fef::ITermFieldData *tfd = getTermFieldData(env, termId, fieldId);
- return (tfd == 0) ? search::fef::IllegalHandle : tfd->getHandle();
+ return (tfd == nullptr) ? search::fef::IllegalHandle : tfd->getHandle();
}
/**
diff --git a/searchlib/src/vespa/searchlib/fef/query_value.cpp b/searchlib/src/vespa/searchlib/fef/query_value.cpp
index 8b881bc722f..ea17743bfc7 100644
--- a/searchlib/src/vespa/searchlib/fef/query_value.cpp
+++ b/searchlib/src/vespa/searchlib/fef/query_value.cpp
@@ -4,6 +4,7 @@
#include "iindexenvironment.h"
#include "indexproperties.h"
#include "iqueryenvironment.h"
+#include <vespa/searchlib/features/utils.h>
#include <vespa/document/datatype/tensor_data_type.h>
#include <vespa/eval/eval/fast_value.h>
#include <vespa/eval/eval/interpreted_function.h>
@@ -11,7 +12,6 @@
#include <vespa/eval/eval/value_codec.h>
#include <vespa/vespalib/locale/c.h>
#include <vespa/vespalib/util/issue.h>
-#include <vespa/vespalib/util/string_hash.h>
#include <cerrno>
using document::TensorDataType;
@@ -59,10 +59,10 @@ as_feature(const vespalib::string& str)
errno = 0;
double val = vespalib::locale::c::strtod(str.c_str(), &end);
if (errno != 0 || *end != '\0') { // not happy
- if (str.size() > 0 && str[0] == '\'') {
- val = vespalib::hash_code(str.substr(1));
+ if ( ! str.empty() && str[0] == '\'') {
+ val = features::util::getAsFeature(vespalib::stringref(str.substr(1)));
} else {
- val = vespalib::hash_code(str);
+ val = features::util::getAsFeature(vespalib::stringref(str));
}
}
return val;
@@ -84,7 +84,7 @@ as_tensor(const vespalib::string& expr, const ValueType& wanted_type)
auto fun = Function::parse(expr);
if (!fun->has_error() && (fun->num_params() == 0)) {
NodeTypes types = NodeTypes(*fun, {});
- ValueType res_type = types.get_type(fun->root());
+ const ValueType & res_type = types.get_type(fun->root());
if (res_type == wanted_type) {
SimpleObjectParams params({});
InterpretedFunction ifun(factory, *fun, types);
@@ -152,12 +152,12 @@ QueryValue::QueryValue()
{
}
-QueryValue::QueryValue(const vespalib::string& key, const vespalib::eval::ValueType& type)
+QueryValue::QueryValue(const vespalib::string& key, vespalib::eval::ValueType type)
: _key(key),
_name("query(" + key + ")"),
_old_key("$" + key),
_stored_value_key("query.value." + key),
- _type(type)
+ _type(std::move(type))
{
}
@@ -171,7 +171,7 @@ QueryValue::from_config(const vespalib::string& key, const IIndexEnvironment& en
if (type.is_error()) {
throw InvalidValueTypeException(key, type_str);
}
- return {key, type};
+ return {key, std::move(type)};
}
std::unique_ptr<Value>
@@ -187,7 +187,7 @@ QueryValue::make_default_value(const IIndexEnvironment& env) const
} else {
if (p.found()) {
auto tensor = as_tensor(p.get(), _type);
- if (tensor.get() == nullptr) {
+ if ( ! tensor) {
throw InvalidTensorValueException(_type, p.get().c_str());
}
return tensor;
diff --git a/searchlib/src/vespa/searchlib/fef/query_value.h b/searchlib/src/vespa/searchlib/fef/query_value.h
index fb014883268..17042d662c3 100644
--- a/searchlib/src/vespa/searchlib/fef/query_value.h
+++ b/searchlib/src/vespa/searchlib/fef/query_value.h
@@ -59,7 +59,7 @@ private:
public:
QueryValue();
- QueryValue(const vespalib::string& key, const vespalib::eval::ValueType& type);
+ QueryValue(const vespalib::string& key, vespalib::eval::ValueType type);
~QueryValue();
/**
diff --git a/vespalib/src/vespa/vespalib/locale/c.cpp b/vespalib/src/vespa/vespalib/locale/c.cpp
index f6d71857d5a..ffc29b2e104 100644
--- a/vespalib/src/vespa/vespalib/locale/c.cpp
+++ b/vespalib/src/vespa/vespalib/locale/c.cpp
@@ -3,7 +3,7 @@
#include "c.h"
#include "locale.h"
#include <cstdlib>
-#include <errno.h>
+#include <cerrno>
namespace vespalib::locale::c {
diff --git a/vespalib/src/vespa/vespalib/util/string_hash.cpp b/vespalib/src/vespa/vespalib/util/string_hash.cpp
index 572ba765743..0e8b93dca04 100644
--- a/vespalib/src/vespa/vespalib/util/string_hash.cpp
+++ b/vespalib/src/vespa/vespalib/util/string_hash.cpp
@@ -4,7 +4,7 @@
namespace vespalib {
-uint32_t hash_code(const char *str, size_t len) {
+double hash2d(const char *str, size_t len) {
uint32_t hash = 0;
for (size_t i = 0; i < len; ++i) {
hash = (hash << 5) - hash + str[i];
@@ -12,8 +12,8 @@ uint32_t hash_code(const char *str, size_t len) {
return hash;
}
-uint32_t hash_code(vespalib::stringref str) {
- return hash_code(str.data(), str.size());
+double hash2d(vespalib::stringref str) {
+ return hash2d(str.data(), str.size());
}
} // namespace vespalib
diff --git a/vespalib/src/vespa/vespalib/util/string_hash.h b/vespalib/src/vespa/vespalib/util/string_hash.h
index 14a5a85a009..495a8378b42 100644
--- a/vespalib/src/vespa/vespalib/util/string_hash.h
+++ b/vespalib/src/vespa/vespalib/util/string_hash.h
@@ -9,8 +9,8 @@ namespace vespalib {
/**
* simple string hashing function similar to the one used by Java.
**/
-uint32_t hash_code(const char *str, size_t len);
-uint32_t hash_code(vespalib::stringref str);
+double hash2d(const char *str, size_t len);
+double hash2d(vespalib::stringref str);
} // namespace vespalib