diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2022-11-20 18:15:32 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2022-11-20 18:15:32 +0000 |
commit | 37c0e98af2ab7fbeb307019a20e572def4f1ddb6 (patch) | |
tree | 02312684c58dea559b7ade43ab30abc86c9ea0a8 /searchlib/src | |
parent | b693d572df945b9e82798e0c40b8b7b565f6a4a8 (diff) |
Separate where you nede an actual hash, and where you want the string hashed to a double.
Diffstat (limited to 'searchlib/src')
5 files changed, 27 insertions, 27 deletions
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(); /** |