diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2019-10-03 08:56:15 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2019-11-01 10:47:44 +0000 |
commit | f4c345da92694e6cff2e62381960dbde4ae51393 (patch) | |
tree | 17a8220b4fbeacf580888a3ca5a35a3e7d2f2186 | |
parent | 4be669c26cbf6b32df0e05ea42184399dc7cb896 (diff) |
Add initial skeleton.
4 files changed, 75 insertions, 0 deletions
diff --git a/staging_vespalib/src/vespa/vespalib/util/CMakeLists.txt b/staging_vespalib/src/vespa/vespalib/util/CMakeLists.txt index 20d47c90453..d5d47ed5c61 100644 --- a/staging_vespalib/src/vespa/vespalib/util/CMakeLists.txt +++ b/staging_vespalib/src/vespa/vespalib/util/CMakeLists.txt @@ -19,5 +19,6 @@ vespa_add_library(staging_vespalib_vespalib_util OBJECT timer.cpp xmlserializable.cpp xmlstream.cpp + zncurve.cpp DEPENDS ) diff --git a/staging_vespalib/src/vespa/vespalib/util/zncurve.cpp b/staging_vespalib/src/vespa/vespalib/util/zncurve.cpp new file mode 100644 index 00000000000..64157468f7e --- /dev/null +++ b/staging_vespalib/src/vespa/vespalib/util/zncurve.cpp @@ -0,0 +1,12 @@ +// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#include "zncurve.hpp" + +namespace vespalib { + +template class ZNPoint<2, uint32_t>; +template class ZNPoint<4, uint32_t>; +template class ZNPoint<8, uint32_t>; + +} // namespace vespalib + diff --git a/staging_vespalib/src/vespa/vespalib/util/zncurve.h b/staging_vespalib/src/vespa/vespalib/util/zncurve.h new file mode 100644 index 00000000000..e8b82e77e96 --- /dev/null +++ b/staging_vespalib/src/vespa/vespalib/util/zncurve.h @@ -0,0 +1,21 @@ +// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#pragma once + +#include <cstdint> + +namespace vespalib { + +template<int numDim, class T> +class ZNPoint { +public: + ZNPoint(const T * begin); + uint64_t distance(const ZNPoint & rhs) const; + bool operator < (const ZNPoint & rhs) const; +private: + T _vector[numDim]; + uint8_t _zCurve[sizeof(T)*numDim]; +}; + +} // namespace vespalib + diff --git a/staging_vespalib/src/vespa/vespalib/util/zncurve.hpp b/staging_vespalib/src/vespa/vespalib/util/zncurve.hpp new file mode 100644 index 00000000000..896b668ddcc --- /dev/null +++ b/staging_vespalib/src/vespa/vespalib/util/zncurve.hpp @@ -0,0 +1,41 @@ +// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +#pragma once + +#include "zncurve.h" +#include <cstring> +#include <cmath> + +namespace vespalib { + +template<int numDim, class T> +ZNPoint<numDim, T>::ZNPoint(const T * begin) + : _vector(), + _zCurve() +{ + for (uint32_t i(0); i < numDim; i++) { + _vector[i] = begin[i]; + } +} + +template<int numDim, class T> +uint64_t +ZNPoint<numDim, T>::distance(const ZNPoint & rhs) const +{ + uint64_t sum(0); + for (unsigned i(0); i < numDim; i++) { + int64_t diff = _vector[i] - rhs._vector[i]; + sum += diff*diff; + } + return sqrt(sum); +} + +template<int numDim, class T> +bool +ZNPoint<numDim, T>::operator < (const ZNPoint & rhs) const +{ + return memcmp(_zCurve, rhs._zCurve, sizeof(_zCurve)) < 0; +} + +} // namespace vespalib + |