From 8dce83b423159201d91e97c5d779ef8c064b025d Mon Sep 17 00:00:00 2001 From: Henning Baldersheim Date: Wed, 26 Apr 2017 22:13:52 +0200 Subject: No virtual on override Optimize includes. --- .../src/tests/array/allocinarray_benchmark.cpp | 1 - .../src/tests/array/allocinarray_test.cpp | 4 - .../src/tests/array/sort_benchmark.cpp | 1 - staging_vespalib/src/tests/benchmark/benchmark.cpp | 3 - staging_vespalib/src/tests/benchmark/testbase.cpp | 6 +- staging_vespalib/src/tests/benchmark/testbase.h | 29 +- staging_vespalib/src/tests/bits/bits_test.cpp | 4 +- staging_vespalib/src/tests/clock/clock_test.cpp | 6 +- staging_vespalib/src/tests/crc/crc_test.cpp | 4 +- staging_vespalib/src/tests/create-test.sh | 5 +- .../src/tests/databuffer/databuffer_test.cpp | 3 - staging_vespalib/src/tests/directio/directio.cpp | 5 +- .../src/tests/encoding/base64/base64_test.cpp | 8 +- .../src/tests/fileheader/fileheader_test.cpp | 16 +- .../floatingpointtype/floatingpointtypetest.cpp | 4 +- .../growablebytebuffer/growablebytebuffer_test.cpp | 4 +- .../src/tests/librarypool/librarypool_test.cpp | 3 - .../src/tests/memorydatastore/memorydatastore.cpp | 5 +- .../src/tests/objectdump/objectdump.cpp | 8 +- .../src/tests/objects/identifiable_test.cpp | 4 +- .../src/tests/objectselection/objectselection.cpp | 10 +- .../polymorphicarray/polymorphicarray_test.cpp | 4 +- .../tests/programoptions/programoptions_test.cpp | 7 +- staging_vespalib/src/tests/rusage/rusage_test.cpp | 5 +- .../src/tests/shutdownguard/shutdownguard_test.cpp | 3 - .../src/tests/state_server/state_server_test.cpp | 20 +- staging_vespalib/src/tests/stllike/avl.cpp | 265 --------------- staging_vespalib/src/tests/timer/timer_test.cpp | 4 +- .../process_memory_stats_test.cpp | 1 - .../tests/xmlserializable/xmlserializabletest.cpp | 4 +- staging_vespalib/src/vespa/vespalib/stllike/avl.h | 367 --------------------- .../src/vespa/vespalib/stllike/avl_map.h | 65 ---- .../src/vespa/vespalib/util/programoptions.h | 81 ++--- 33 files changed, 88 insertions(+), 871 deletions(-) delete mode 100644 staging_vespalib/src/tests/stllike/avl.cpp delete mode 100644 staging_vespalib/src/vespa/vespalib/stllike/avl.h delete mode 100644 staging_vespalib/src/vespa/vespalib/stllike/avl_map.h (limited to 'staging_vespalib') diff --git a/staging_vespalib/src/tests/array/allocinarray_benchmark.cpp b/staging_vespalib/src/tests/array/allocinarray_benchmark.cpp index ce21c918219..75092255f9e 100644 --- a/staging_vespalib/src/tests/array/allocinarray_benchmark.cpp +++ b/staging_vespalib/src/tests/array/allocinarray_benchmark.cpp @@ -1,5 +1,4 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include #include #include #include diff --git a/staging_vespalib/src/tests/array/allocinarray_test.cpp b/staging_vespalib/src/tests/array/allocinarray_test.cpp index 059fff91cec..c68cc3fa874 100644 --- a/staging_vespalib/src/tests/array/allocinarray_test.cpp +++ b/staging_vespalib/src/tests/array/allocinarray_test.cpp @@ -1,14 +1,10 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include -#include #include #include #include #include #include -LOG_SETUP("array_test"); - using namespace vespalib; class Test : public TestApp diff --git a/staging_vespalib/src/tests/array/sort_benchmark.cpp b/staging_vespalib/src/tests/array/sort_benchmark.cpp index 9e2b286e864..29f1560e426 100644 --- a/staging_vespalib/src/tests/array/sort_benchmark.cpp +++ b/staging_vespalib/src/tests/array/sort_benchmark.cpp @@ -1,5 +1,4 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include #include #include #include diff --git a/staging_vespalib/src/tests/benchmark/benchmark.cpp b/staging_vespalib/src/tests/benchmark/benchmark.cpp index 1c4c5a59c63..7a25fa39063 100644 --- a/staging_vespalib/src/tests/benchmark/benchmark.cpp +++ b/staging_vespalib/src/tests/benchmark/benchmark.cpp @@ -1,7 +1,4 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include -#include -LOG_SETUP("benchmark_test"); #include #include "testbase.h" diff --git a/staging_vespalib/src/tests/benchmark/testbase.cpp b/staging_vespalib/src/tests/benchmark/testbase.cpp index 9ac20638218..93f5c9b975a 100644 --- a/staging_vespalib/src/tests/benchmark/testbase.cpp +++ b/staging_vespalib/src/tests/benchmark/testbase.cpp @@ -1,10 +1,8 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include -//#include -#include -#include #include "testbase.h" +#include +#include LOG_SETUP(".testbase"); namespace vespalib { diff --git a/staging_vespalib/src/tests/benchmark/testbase.h b/staging_vespalib/src/tests/benchmark/testbase.h index 02f11e21cac..beb485e6dab 100644 --- a/staging_vespalib/src/tests/benchmark/testbase.h +++ b/staging_vespalib/src/tests/benchmark/testbase.h @@ -45,7 +45,7 @@ public: private: typedef std::vector Vector; size_t callByReference(const Vector & values) const __attribute__((noinline)); - virtual size_t onRun() override; + size_t onRun() override; }; class ParamByValueVectorInt : public Benchmark @@ -55,7 +55,7 @@ public: private: typedef std::vector Vector; size_t callByValue(Vector values) const __attribute__((noinline)); - virtual size_t onRun() override; + size_t onRun() override; }; class ParamByReferenceVectorString : public Benchmark @@ -65,7 +65,7 @@ public: private: typedef std::vector Vector; size_t callByReference(const Vector & values) const __attribute__((noinline)); - virtual size_t onRun() override; + size_t onRun() override; }; class ParamByValueVectorString : public Benchmark @@ -75,7 +75,7 @@ public: private: typedef std::vector Vector; size_t callByValue(Vector values) const __attribute__((noinline)); - virtual size_t onRun() override; + size_t onRun() override; }; class ReturnByReferenceVectorString : public Benchmark @@ -85,7 +85,7 @@ public: private: typedef std::vector Vector; const Vector & returnByReference(Vector & values) const __attribute__((noinline)); - virtual size_t onRun() override; + size_t onRun() override; }; class ReturnByValueVectorString : public Benchmark @@ -95,7 +95,7 @@ public: private: typedef std::vector Vector; Vector returnByValue() const __attribute__((noinline)); - virtual size_t onRun() override; + size_t onRun() override; }; class ReturnByValueMultiVectorString : public Benchmark @@ -105,7 +105,7 @@ public: private: typedef std::vector Vector; Vector returnByValue() const __attribute__((noinline)); - virtual size_t onRun() override; + size_t onRun() override; }; class CreateVespalibString : public Benchmark @@ -113,7 +113,7 @@ class CreateVespalibString : public Benchmark public: DECLARE_BENCHMARK(CreateVespalibString); private: - virtual size_t onRun() override; + size_t onRun() override; }; class ClockSystem : public Benchmark @@ -121,7 +121,7 @@ class ClockSystem : public Benchmark public: DECLARE_BENCHMARK(ClockSystem); private: - virtual size_t onRun() override; + size_t onRun() override; }; class ClockREALTIME : public Benchmark @@ -129,7 +129,7 @@ class ClockREALTIME : public Benchmark public: DECLARE_BENCHMARK(ClockREALTIME); private: - virtual size_t onRun() override; + size_t onRun() override; }; class ClockMONOTONIC : public Benchmark @@ -137,7 +137,7 @@ class ClockMONOTONIC : public Benchmark public: DECLARE_BENCHMARK(ClockMONOTONIC); private: - virtual size_t onRun() override; + size_t onRun() override; }; class ClockMONOTONIC_RAW : public Benchmark @@ -146,7 +146,7 @@ public: DECLARE_BENCHMARK(ClockMONOTONIC_RAW); ClockMONOTONIC_RAW(); private: - virtual size_t onRun() override; + size_t onRun() override; }; class ClockPROCESS_CPUTIME_ID : public Benchmark @@ -154,7 +154,7 @@ class ClockPROCESS_CPUTIME_ID : public Benchmark public: DECLARE_BENCHMARK(ClockPROCESS_CPUTIME_ID); private: - virtual size_t onRun() override; + size_t onRun() override; }; class ClockTHREAD_CPUTIME_ID : public Benchmark @@ -162,8 +162,7 @@ class ClockTHREAD_CPUTIME_ID : public Benchmark public: DECLARE_BENCHMARK(ClockTHREAD_CPUTIME_ID); private: - virtual size_t onRun() override; + size_t onRun() override; }; } - diff --git a/staging_vespalib/src/tests/bits/bits_test.cpp b/staging_vespalib/src/tests/bits/bits_test.cpp index f7b3ef1bf84..783651db366 100644 --- a/staging_vespalib/src/tests/bits/bits_test.cpp +++ b/staging_vespalib/src/tests/bits/bits_test.cpp @@ -1,7 +1,5 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include -#include -LOG_SETUP("bits_test"); + #include #include #include diff --git a/staging_vespalib/src/tests/clock/clock_test.cpp b/staging_vespalib/src/tests/clock/clock_test.cpp index 025d8766a29..58a01a520b6 100644 --- a/staging_vespalib/src/tests/clock/clock_test.cpp +++ b/staging_vespalib/src/tests/clock/clock_test.cpp @@ -1,9 +1,7 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include -#include -LOG_SETUP("sharedptr_test"); -#include + #include +#include using vespalib::Clock; using fastos::TimeStamp; diff --git a/staging_vespalib/src/tests/crc/crc_test.cpp b/staging_vespalib/src/tests/crc/crc_test.cpp index 6a5a0779d8b..df8ac89db62 100644 --- a/staging_vespalib/src/tests/crc/crc_test.cpp +++ b/staging_vespalib/src/tests/crc/crc_test.cpp @@ -1,7 +1,5 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include -#include -LOG_SETUP("crc_test"); + #include #include #include diff --git a/staging_vespalib/src/tests/create-test.sh b/staging_vespalib/src/tests/create-test.sh index 56234dbab30..0e735e1b890 100755 --- a/staging_vespalib/src/tests/create-test.sh +++ b/staging_vespalib/src/tests/create-test.sh @@ -15,10 +15,9 @@ gen_project_file() { gen_source() { echo "generating '$1' ..." - echo "#include " > $1 + echo "#include " > $1 + echo "#include " >> $1 echo "LOG_SETUP(\"${test}_test\");" >> $1 - echo "#include " >> $1 - echo "#include " >> $1 echo "" >> $1 echo "using namespace vespalib;" >> $1 echo "" >> $1 diff --git a/staging_vespalib/src/tests/databuffer/databuffer_test.cpp b/staging_vespalib/src/tests/databuffer/databuffer_test.cpp index 7ec83e58b5c..1a242e8eec4 100644 --- a/staging_vespalib/src/tests/databuffer/databuffer_test.cpp +++ b/staging_vespalib/src/tests/databuffer/databuffer_test.cpp @@ -1,7 +1,4 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include -#include -LOG_SETUP("databuffer_test"); #include #include diff --git a/staging_vespalib/src/tests/directio/directio.cpp b/staging_vespalib/src/tests/directio/directio.cpp index 570d7276bc9..0fb3b8a4434 100644 --- a/staging_vespalib/src/tests/directio/directio.cpp +++ b/staging_vespalib/src/tests/directio/directio.cpp @@ -1,10 +1,9 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include -#include -LOG_SETUP("directio_test"); + #include #include #include +#include using namespace fastos; using namespace vespalib; diff --git a/staging_vespalib/src/tests/encoding/base64/base64_test.cpp b/staging_vespalib/src/tests/encoding/base64/base64_test.cpp index e765ac7d601..a22484463a5 100644 --- a/staging_vespalib/src/tests/encoding/base64/base64_test.cpp +++ b/staging_vespalib/src/tests/encoding/base64/base64_test.cpp @@ -1,14 +1,8 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include +#include #include - -#include -#include #include -#include - -LOG_SETUP("base64_test"); using namespace vespalib; diff --git a/staging_vespalib/src/tests/fileheader/fileheader_test.cpp b/staging_vespalib/src/tests/fileheader/fileheader_test.cpp index f2a6c8402ee..55ca571cdac 100644 --- a/staging_vespalib/src/tests/fileheader/fileheader_test.cpp +++ b/staging_vespalib/src/tests/fileheader/fileheader_test.cpp @@ -1,10 +1,8 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include -#include -LOG_SETUP("fileheader_test"); #include #include +#include #include using namespace vespalib; @@ -29,15 +27,9 @@ private: void testRewriteErrors(); void testLayout(); - void - testReadSize(bool mapped); - - void - testReadSizeErrors(bool mapped); - - bool - testReadSizeError(DataBuffer &buf, const std::string &expected, - bool mapped); + void testReadSize(bool mapped); + void testReadSizeErrors(bool mapped); + bool testReadSizeError(DataBuffer &buf, const std::string &expected, bool mapped); public: int Main() override { diff --git a/staging_vespalib/src/tests/floatingpointtype/floatingpointtypetest.cpp b/staging_vespalib/src/tests/floatingpointtype/floatingpointtypetest.cpp index 98b6804ac8e..19e52dbe885 100644 --- a/staging_vespalib/src/tests/floatingpointtype/floatingpointtypetest.cpp +++ b/staging_vespalib/src/tests/floatingpointtype/floatingpointtypetest.cpp @@ -1,9 +1,7 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. - // Include first to make sure it includes all it need. -#include -#include #include +#include class Test : public vespalib::TestApp { diff --git a/staging_vespalib/src/tests/growablebytebuffer/growablebytebuffer_test.cpp b/staging_vespalib/src/tests/growablebytebuffer/growablebytebuffer_test.cpp index aaf3f383c33..1ba9c912344 100644 --- a/staging_vespalib/src/tests/growablebytebuffer/growablebytebuffer_test.cpp +++ b/staging_vespalib/src/tests/growablebytebuffer/growablebytebuffer_test.cpp @@ -1,7 +1,5 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include -#include -LOG_SETUP("guard_test"); + #include #include diff --git a/staging_vespalib/src/tests/librarypool/librarypool_test.cpp b/staging_vespalib/src/tests/librarypool/librarypool_test.cpp index 665dbca8a86..87e04d3ffbd 100644 --- a/staging_vespalib/src/tests/librarypool/librarypool_test.cpp +++ b/staging_vespalib/src/tests/librarypool/librarypool_test.cpp @@ -1,10 +1,7 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include #include #include #include -#include -LOG_SETUP("librarypool_test"); using namespace vespalib; diff --git a/staging_vespalib/src/tests/memorydatastore/memorydatastore.cpp b/staging_vespalib/src/tests/memorydatastore/memorydatastore.cpp index 5430e8c1465..5a1c0d7fb32 100644 --- a/staging_vespalib/src/tests/memorydatastore/memorydatastore.cpp +++ b/staging_vespalib/src/tests/memorydatastore/memorydatastore.cpp @@ -1,11 +1,8 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include -#include -LOG_SETUP("data_test"); + #include #include #include -#include using namespace vespalib; diff --git a/staging_vespalib/src/tests/objectdump/objectdump.cpp b/staging_vespalib/src/tests/objectdump/objectdump.cpp index 671e89b5011..3bdbe2401e4 100644 --- a/staging_vespalib/src/tests/objectdump/objectdump.cpp +++ b/staging_vespalib/src/tests/objectdump/objectdump.cpp @@ -1,5 +1,5 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include + #include #include #include @@ -22,7 +22,7 @@ IMPLEMENT_IDENTIFIABLE(Base, vespalib::Identifiable); struct Baz : public Base { DECLARE_IDENTIFIABLE(Baz); - virtual Baz *clone() const override { return new Baz(*this); } + Baz *clone() const override { return new Baz(*this); } }; IMPLEMENT_IDENTIFIABLE(Baz, Base); @@ -45,9 +45,9 @@ struct Bar : public Base _int32(-4), _uint32(4), _int64(-8), _uint64(8), _float(2.5), _double(2.75), _string("bla bla") {} - virtual Bar *clone() const override { return new Bar(*this); } + Bar *clone() const override { return new Bar(*this); } - virtual void visitMembers(ObjectVisitor &v) const override { + void visitMembers(ObjectVisitor &v) const override { visit(v, "_bool", _bool); visit(v, "_int8", _int8); visit(v, "_uint8", _uint8); diff --git a/staging_vespalib/src/tests/objects/identifiable_test.cpp b/staging_vespalib/src/tests/objects/identifiable_test.cpp index c60f33b9b55..5ef48b6e779 100644 --- a/staging_vespalib/src/tests/objects/identifiable_test.cpp +++ b/staging_vespalib/src/tests/objects/identifiable_test.cpp @@ -1,5 +1,5 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include + #include #include #include @@ -40,7 +40,7 @@ class A : public Abstract public: DECLARE_IDENTIFIABLE(A); A() { } - virtual void someAbstractVirtualMethod() override { } + void someAbstractVirtualMethod() override { }; }; class B : public A diff --git a/staging_vespalib/src/tests/objectselection/objectselection.cpp b/staging_vespalib/src/tests/objectselection/objectselection.cpp index 27ecb068231..db696230082 100644 --- a/staging_vespalib/src/tests/objectselection/objectselection.cpp +++ b/staging_vespalib/src/tests/objectselection/objectselection.cpp @@ -1,5 +1,5 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include + #include #include #include @@ -17,7 +17,7 @@ struct Foo : public Identifiable DECLARE_IDENTIFIABLE(Foo); virtual Foo *clone() const { return new Foo(*this); } - virtual void selectMembers(const ObjectPredicate &p, ObjectOperation &o) override { + void selectMembers(const ObjectPredicate &p, ObjectOperation &o) override { for (uint32_t i = 0; i < nodes.size(); ++i) { nodes[i]->select(p, o); } @@ -32,7 +32,7 @@ struct Bar : public Foo DECLARE_IDENTIFIABLE(Bar); Bar() : value(0) {} Bar(int v) { value = v; } - virtual Bar *clone() const override { return new Bar(*this); } + Bar *clone() const override { return new Bar(*this); } }; IMPLEMENT_IDENTIFIABLE(Bar, Identifiable); @@ -40,7 +40,7 @@ struct ObjectType : public ObjectPredicate { uint32_t cid; ObjectType(uint32_t id) : cid(id) {} - virtual bool check(const Identifiable &obj) const override { + bool check(const Identifiable &obj) const override { return (obj.getClass().id() == cid); } }; @@ -48,7 +48,7 @@ struct ObjectType : public ObjectPredicate struct ObjectCollect : public ObjectOperation { std::vector nodes; - virtual void execute(Identifiable &obj) override { + void execute(Identifiable &obj) override { nodes.push_back(&obj); } }; diff --git a/staging_vespalib/src/tests/polymorphicarray/polymorphicarray_test.cpp b/staging_vespalib/src/tests/polymorphicarray/polymorphicarray_test.cpp index affb7287674..a1c8a31729c 100644 --- a/staging_vespalib/src/tests/polymorphicarray/polymorphicarray_test.cpp +++ b/staging_vespalib/src/tests/polymorphicarray/polymorphicarray_test.cpp @@ -1,5 +1,5 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include + #include #include @@ -112,7 +112,7 @@ class Factory : public ComplexArrayT::Factory { public: A * create() override { return new Complex(); } - virtual Factory * clone() const override { return new Factory(*this); } + Factory * clone() const override { return new Factory(*this); } }; TEST("require that complex arrays conforms") { diff --git a/staging_vespalib/src/tests/programoptions/programoptions_test.cpp b/staging_vespalib/src/tests/programoptions/programoptions_test.cpp index 881954bfa3f..709f8a3b723 100644 --- a/staging_vespalib/src/tests/programoptions/programoptions_test.cpp +++ b/staging_vespalib/src/tests/programoptions/programoptions_test.cpp @@ -1,14 +1,9 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include +#include #include #include - #include -#include -#include - -LOG_SETUP("programoptions_test"); namespace vespalib { diff --git a/staging_vespalib/src/tests/rusage/rusage_test.cpp b/staging_vespalib/src/tests/rusage/rusage_test.cpp index 0367ab8c374..5094bd8b5c9 100644 --- a/staging_vespalib/src/tests/rusage/rusage_test.cpp +++ b/staging_vespalib/src/tests/rusage/rusage_test.cpp @@ -1,8 +1,5 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include -#include -#include -LOG_SETUP("alloc_test"); + #include #include diff --git a/staging_vespalib/src/tests/shutdownguard/shutdownguard_test.cpp b/staging_vespalib/src/tests/shutdownguard/shutdownguard_test.cpp index c31e34afe76..45e838ae271 100644 --- a/staging_vespalib/src/tests/shutdownguard/shutdownguard_test.cpp +++ b/staging_vespalib/src/tests/shutdownguard/shutdownguard_test.cpp @@ -1,7 +1,4 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include -#include -LOG_SETUP("shutdownguard_test"); #include #include diff --git a/staging_vespalib/src/tests/state_server/state_server_test.cpp b/staging_vespalib/src/tests/state_server/state_server_test.cpp index f572dbcd8e1..e15a3826669 100644 --- a/staging_vespalib/src/tests/state_server/state_server_test.cpp +++ b/staging_vespalib/src/tests/state_server/state_server_test.cpp @@ -1,5 +1,5 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include + #include #include #include @@ -52,10 +52,8 @@ vespalib::string getFull(int port, const vespalib::string &path) { return getPag struct DummyHandler : JsonGetHandler { vespalib::string result; DummyHandler(const vespalib::string &result_in) : result(result_in) {} - virtual vespalib::string get(const vespalib::string &, - const vespalib::string &, - const std::map &) - const override + vespalib::string get(const vespalib::string &, const vespalib::string &, + const std::map &) const override { return result; } @@ -113,10 +111,8 @@ TEST_FFFF("require that handler is selected based on longest matching url prefix } struct EchoHost : JsonGetHandler { - virtual vespalib::string get(const vespalib::string &host, - const vespalib::string &, - const std::map &) - const override + vespalib::string get(const vespalib::string &host, const vespalib::string &, + const std::map &) const override { return "[\"" + host + "\"]"; } @@ -316,11 +312,11 @@ TEST_FFFFF("require that custom handlers can be added to the state server", } struct EchoConsumer : MetricsProducer { - virtual vespalib::string getMetrics(const vespalib::string &consumer) override { + vespalib::string getMetrics(const vespalib::string &consumer) override { return "[\"" + consumer + "\"]"; } - virtual vespalib::string getTotalMetrics(const vespalib::string &consumer) override { - return "[\"" + consumer + "\"]"; + vespalib::string getTotalMetrics(const vespalib::string &consumer) override { + return "[\"" + consumer + "\"]"; } }; diff --git a/staging_vespalib/src/tests/stllike/avl.cpp b/staging_vespalib/src/tests/stllike/avl.cpp deleted file mode 100644 index 53df03319d7..00000000000 --- a/staging_vespalib/src/tests/stllike/avl.cpp +++ /dev/null @@ -1,265 +0,0 @@ -// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include -#include -LOG_SETUP("memory_test"); -#include -#include -#include - -using namespace vespalib; -using std::make_pair; - -class Test : public TestApp -{ -public: - int Main(); - void testAvlTreeSet(); - void testAvlTreeSet2(); - void testAvlTreeMap(); - void testAvlTreeFind(); -}; - -int -Test::Main() -{ - TEST_INIT("avl_test"); - testAvlTreeSet(); - testAvlTreeSet2(); - testAvlTreeMap(); - testAvlTreeFind(); - TEST_DONE(); -} - -namespace { - struct Foo { - int i; - - Foo() : i(0) {} - Foo(int i_) : i(i_) {} - - bool operator<(const Foo& f) const - { return (i < f.i); } - friend std::ostream & operator << (std::ostream & os, const Foo & f) { return os << f.i; } - }; -} - -void Test::testAvlTreeSet2() -{ - const size_t testSize(2000); - avl_set set(100); - // Verfify start conditions. - EXPECT_TRUE(set.size() == 0); - EXPECT_TRUE(set.begin() == set.end()); - EXPECT_TRUE(set.find(7) == set.end()); - // Insert one element - set.insert(Foo(7)); - EXPECT_TRUE(set.size() == 1); - EXPECT_TRUE(set.begin() != set.end()); - EXPECT_TRUE(set.find(Foo(7)) != set.end()); - EXPECT_TRUE(*set.find(Foo(7)) == Foo(7)); - EXPECT_TRUE(set.find(Foo(8)) == set.end()); - // erase non existing - set.erase(Foo(8)); - EXPECT_TRUE(set.size() == 1); - EXPECT_TRUE(set.begin() != set.end()); - EXPECT_TRUE(set.find(Foo(7)) != set.end()); - EXPECT_TRUE(*set.find(Foo(7)) == Foo(7)); - EXPECT_TRUE(set.find(Foo(8)) == set.end()); - // erase existing - set.erase(Foo(7)); - EXPECT_TRUE(set.size() == 0); - EXPECT_TRUE(set.begin() == set.end()); - EXPECT_TRUE(set.find(Foo(7)) == set.end()); - for (size_t i(0); i < testSize; i++) { - set.insert(Foo(i)); - avl_set::iterator it = set.find(Foo(i)); - ASSERT_TRUE(it != set.end()); - for (size_t j=0; j < i; j++) { - it = set.find(Foo(j)); - ASSERT_TRUE(it != set.end()); - } - } - EXPECT_TRUE(set.size() == testSize); - avl_set::iterator it = set.find(Foo((testSize/2)-1)); - ASSERT_TRUE(it != set.end()); - EXPECT_EQUAL(*it, Foo((testSize/2)-1)); - for (size_t i(0); i < testSize/2; i++) { - set.erase(Foo(i*2)); - } - ASSERT_TRUE(it != set.end()); - EXPECT_EQUAL(*it, Foo((testSize/2)-1)); - EXPECT_TRUE(set.find(Foo(testSize/2)) == set.end()); - EXPECT_TRUE(set.size() == testSize/2); - for (size_t i(0); i < testSize; i++) { - set.insert(Foo(i)); - } - EXPECT_EQUAL(set.size(), testSize); - EXPECT_TRUE(*set.find(Foo(7)) == Foo(7)); - EXPECT_TRUE(*set.find(Foo(0)) == Foo(0)); - EXPECT_TRUE(*set.find(Foo(1)) == Foo(1)); - EXPECT_TRUE(*set.find(Foo(testSize-1)) == Foo(testSize-1)); - EXPECT_TRUE(set.find(Foo(testSize)) == set.end()); - - set.clear(); - - EXPECT_EQUAL(set.size(), 0u); - EXPECT_TRUE(set.find(Foo(7)) == set.end()); -} - -void Test::testAvlTreeSet() -{ - avl_set set(1000); - // Verfify start conditions. - EXPECT_TRUE(set.size() == 0); - EXPECT_TRUE(set.begin() == set.end()); - EXPECT_TRUE(set.find(7) == set.end()); - // Insert one element - set.insert(7); - EXPECT_TRUE(set.size() == 1); - EXPECT_TRUE(set.begin() != set.end()); - EXPECT_TRUE(set.find(7) != set.end()); - EXPECT_TRUE(*set.find(7) == 7); - EXPECT_TRUE(set.find(8) == set.end()); - // erase non existing - set.erase(8); - EXPECT_TRUE(set.size() == 1); - EXPECT_TRUE(set.begin() != set.end()); - EXPECT_TRUE(set.find(7) != set.end()); - EXPECT_TRUE(*set.find(7) == 7); - EXPECT_TRUE(set.find(8) == set.end()); - // erase existing - set.erase(7); - EXPECT_TRUE(set.size() == 0); - EXPECT_TRUE(set.begin() == set.end()); - EXPECT_TRUE(set.find(7) == set.end()); - for (size_t i(0); i < 10000; i++) { - set.insert(i); - } - EXPECT_TRUE(set.size() == 10000); - for (size_t i(0); i < 5000; i++) { - set.erase(i*2); - } - EXPECT_TRUE(*set.find(4999) == 4999); - EXPECT_TRUE(set.find(5000) == set.end()); - EXPECT_TRUE(set.size() == 5000); - for (size_t i(0); i < 10000; i++) { - set.insert(i); - } - EXPECT_EQUAL(set.size(), 10000u); - EXPECT_TRUE(*set.find(7) == 7); - EXPECT_TRUE(*set.find(0) == 0); - EXPECT_TRUE(*set.find(1) == 1); - EXPECT_TRUE(*set.find(9999) == 9999); - EXPECT_TRUE(set.find(10000) == set.end()); - - set.clear(); - - EXPECT_EQUAL(set.size(), 0u); - EXPECT_TRUE(set.find(7) == set.end()); -} - -void Test::testAvlTreeMap() -{ - avl_map set(1000); - // Verfify start conditions. - EXPECT_TRUE(set.size() == 0); - EXPECT_TRUE(set.begin() == set.end()); - EXPECT_TRUE(set.find(7) == set.end()); - // Insert one element - set.insert(make_pair(7, 70)); - EXPECT_TRUE(set.size() == 1); - EXPECT_TRUE(set.begin() != set.end()); - EXPECT_TRUE(set.find(7) != set.end()); - EXPECT_TRUE(set.find(7)->first == 7); - EXPECT_TRUE(set.find(7)->second == 70); - EXPECT_TRUE(set.find(8) == set.end()); - // erase non existing - set.erase(8); - EXPECT_TRUE(set.size() == 1); - EXPECT_TRUE(set.begin() != set.end()); - EXPECT_TRUE(set.find(7) != set.end()); - EXPECT_TRUE(set.find(7)->first == 7); - EXPECT_TRUE(set.find(7)->second == 70); - EXPECT_TRUE(set.find(8) == set.end()); - // erase existing - set.erase(7); - EXPECT_TRUE(set.size() == 0); - EXPECT_TRUE(set.begin() == set.end()); - EXPECT_TRUE(set.find(7) == set.end()); - for (size_t i(0); i < 10000; i++) { - set.insert(make_pair(i,i*10)); - } - EXPECT_TRUE(set.size() == 10000); - for (size_t i(0); i < 5000; i++) { - set.erase(i*2); - } - EXPECT_TRUE(set.find(4999)->first == 4999); - EXPECT_TRUE(set.find(4999)->second == 49990); - EXPECT_TRUE(set.find(5000) == set.end()); - EXPECT_TRUE(set.size() == 5000); - for (size_t i(0); i < 10000; i++) { - set.insert(make_pair(i,i*10)); - } - EXPECT_EQUAL(set.size(), 10000u); - EXPECT_TRUE(set.find(7)->first == 7); - EXPECT_TRUE(set.find(7)->second == 70); - EXPECT_TRUE(set.find(0)->first == 0); - EXPECT_TRUE(set.find(0)->second == 0); - EXPECT_TRUE(set.find(1)->first == 1); - EXPECT_TRUE(set.find(1)->second == 10); - EXPECT_TRUE(set.find(9999)->first == 9999); - EXPECT_TRUE(set.find(9999)->second == 99990); - EXPECT_TRUE(set.find(10000) == set.end()); - - avl_map set2(7); - set.swap(set2); - EXPECT_EQUAL(set2.size(), 10000u); - EXPECT_TRUE(set2.find(7)->first == 7); - EXPECT_TRUE(set2.find(7)->second == 70); - - EXPECT_EQUAL(set.size(), 0u); - EXPECT_TRUE(set.find(7) == set.end()); - for (int i=0; i < 100; i++) { - set.insert(make_pair(i,i*10)); - } - for (int i=0; i < 100; i++) { - EXPECT_TRUE(set.find(i)->second == i*10); - } - - avl_map set3; - set3.insert(set.begin(), set.end()); - for (int i=0; i < 100; i++) { - EXPECT_EQUAL(i*10, set.find(i)->second); - } -} - -class S { -public: - explicit S(uint64_t l=0) : _a(l&0xfffffffful), _b(l>>32) { } - uint32_t avl() const { return _a; } - uint32_t a() const { return _a; } - friend bool operator == (const S & a, const S & b) { return a._a == b._a && a._b == b._b; } -private: - uint32_t _a, _b; -}; - -struct myavl { - size_t operator() (const S & arg) const { return arg.avl(); } -}; - -struct myextract { - uint32_t operator() (const S & arg) const { return arg.a(); } -}; - -void Test::testAvlTreeFind() -{ - avl_set set(1000); - for (size_t i(0); i < 10000; i++) { - set.insert(S(i)); - } - EXPECT_TRUE(*set.find(S(1)) == S(1)); - avl_set::iterator cit = set.find, std::equal_to >(7); - EXPECT_TRUE(*cit == S(7)); -} - -TEST_APPHOOK(Test) diff --git a/staging_vespalib/src/tests/timer/timer_test.cpp b/staging_vespalib/src/tests/timer/timer_test.cpp index ad782f4089f..21b60b828cc 100644 --- a/staging_vespalib/src/tests/timer/timer_test.cpp +++ b/staging_vespalib/src/tests/timer/timer_test.cpp @@ -1,7 +1,5 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include -#include -LOG_SETUP("timer_test"); + #include #include #include diff --git a/staging_vespalib/src/tests/util/process_memory_stats/process_memory_stats_test.cpp b/staging_vespalib/src/tests/util/process_memory_stats/process_memory_stats_test.cpp index 43288d630cf..9d178b850a9 100644 --- a/staging_vespalib/src/tests/util/process_memory_stats/process_memory_stats_test.cpp +++ b/staging_vespalib/src/tests/util/process_memory_stats/process_memory_stats_test.cpp @@ -1,6 +1,5 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include #include #include #include diff --git a/staging_vespalib/src/tests/xmlserializable/xmlserializabletest.cpp b/staging_vespalib/src/tests/xmlserializable/xmlserializabletest.cpp index 1035c021f68..90fcdb8f94f 100644 --- a/staging_vespalib/src/tests/xmlserializable/xmlserializabletest.cpp +++ b/staging_vespalib/src/tests/xmlserializable/xmlserializabletest.cpp @@ -1,9 +1,7 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include -#include - #include +#include namespace vespalib { diff --git a/staging_vespalib/src/vespa/vespalib/stllike/avl.h b/staging_vespalib/src/vespa/vespalib/stllike/avl.h deleted file mode 100644 index be8ccbd3497..00000000000 --- a/staging_vespalib/src/vespa/vespalib/stllike/avl.h +++ /dev/null @@ -1,367 +0,0 @@ -// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#pragma once - -#include -#include -#include -#include - -#include "hash_fun.h" - -namespace vespalib { - -/** - Yet another avl implementation. This one is justified by - different memory management. - - The interface is tried to keep similar to stl version. However the - are some major differences. In order to avoid an allocation / - deallocation for every object inserted / erased, it stores all - objects in a std::vector. This should significantly speed up - things. However it does remove properties that the stl versions - have. The most obvious is that insert might invalidate iterators. - That is due to possible resizing of memory store. That can be - avoided by using a deque. However a deque is more complex and will - be slower. Since speed is here preferred over functionality that is - not yet done. - The same trick could be done for tree based map/set. - An entry can be valid or invalid(not set, or erased). - The entry contains the element + a next index. - - After selecting the proper prime number for modulo operation, the - vector reserves requested space. Resize (triggered by full vector) - doubles size. Then the first 'prime' entries are initialized to - invalid. Then the objects are filled in. If the selected bucket is - invalid the element is inserted directly. If not it is - 'push_back'ed, on the vector and linked in after the head element - for that bucket. Erased elements are marked invalid, but not - reused. They are reclaimed on resize. - - Advantage: - - Significantly faster insert on average. No alloc/dealloc per element. - Disadvantage: - - insert spikes due to possible resize. - - not fully stl-compliant. - Conclusion: - - Probably very good for typical use. Fx duplicate removal. - Advice: - - If you know how many elements you are going to put in, construct - the hash with 2 times the amount. Since a hash will never be - fully filled. - ( hash_set(2*num_expected_elements) ). -**/ - -class avl_base -{ -public: - typedef unsigned int next_t; -}; - -template< typename Key, typename Value, typename Compare, typename KeyExtract > -class avl : public avl_base -{ -protected: - class Node { - public: - enum {npos=-1u, invalid=-2u}; - Node() : _parent(npos), _left(npos), _right(npos) { } - Node(const Value & node, next_t parent=npos, next_t left=npos, next_t right=npos) : _parent(parent), _left(left), _right(right), _node(node) { } - Value & getValue() { return _node; } - const Value & getValue() const { return _node; } - next_t getParent() const { return _parent; } - void setParent(next_t v) { _parent = v; } - next_t getLeft() const { return _left; } - void setLeft(next_t v) { _left = v; } - next_t getRight() const { return _right; } - void setRight(next_t v) { _right = v; } - private: - next_t _parent; - next_t _left; - next_t _right; - Value _node; - }; - typedef std::vector NodeStore; - virtual void move(const NodeStore & oldStore); -public: - class iterator { - public: - iterator(avl * avl, next_t start) : _node(start), _avl(avl) { } - Value & operator * () const { return _avl->get(_node); } - Value * operator -> () const { return & _avl->get(_node); } - iterator & operator ++ () { - _node = _avl->getNextRight(_node); - return *this; - } - iterator operator ++ (int) { - iterator prev = *this; - ++(*this); - return prev; - } - bool operator==(const iterator& rhs) const { return (_node == rhs._node); } - bool operator!=(const iterator& rhs) const { return (_node != rhs._node); } - private: - next_t _node; - avl * _avl; - - friend class avl::const_iterator; - }; - class const_iterator { - public: - const_iterator(const avl * avl, next_t start) : _node(start), _avl(avl) { } - const_iterator(const iterator &i) : _node(i._node), _avl(i._avl) {} - Value & operator * () const { return _avl->get(_node); } - Value * operator -> () const { return & _avl->get(_node); } - iterator & operator ++ () { - _node = _avl->getNextRight(_node); - return *this; - } - iterator operator ++ (int) { - iterator prev = *this; - ++(*this); - return prev; - } - bool operator==(const iterator& rhs) const { return (_node == rhs._node); } - bool operator!=(const iterator& rhs) const { return (_node != rhs._node); } - private: - next_t _node; - avl * _avl; - - friend class avl::const_iterator; - }; - -public: - avl(size_t reservedSpace); - iterator begin() { return iterator(this, getLeftMost(_root)); } - iterator end() { return iterator(this, Node::npos); } - const_iterator begin() const { return const_iterator(this, getLeftMost(_root)); } - const_iterator end() const { return const_iterator(this, Node::npos); } - size_t capacity() const { return _nodes.capacity(); } - size_t size() const { return _nodes.size(); } - bool empty() const { return _root == npos; } - template< typename AltKey, typename AltExtract, typename AltCompare > - iterator find(const AltKey & key); - iterator find(const Key & key); - iterator find(const Key & key) { return iterator(this, internalFind(key)); } - template< typename AltKey, typename AltExtract, typename AltCompare > - const_iterator find(const AltKey & key) const; - const_iterator find(const Key & key) const { return const_iterator(this, internalFind(key)); } - void insert(const Value & node); - void erase(const Key & key); - void clear() { _nodes.clear(); } - void reserve(size_t newReserve) { _nodes.reserve(newReserve); } - void swap(avl & rhs); - /** - * Get an approximate number of memory consumed by hash set. Not including - * any data K would store outside of sizeof(K) of course. - */ - size_t getMemoryConsumption() const; - -protected: - /// These two methods are only for the ones that know what they are doing. - /// valid input here are stuff returned from iterator.getInternalIndex. - next_t insertInternal(const Value & node); - Value & getByInternalIndex(size_t index) { return _nodes[index].getValue(); } - const Value & getByInternalIndex(size_t index) const { return _nodes[index].getValue(); } - template - void erase(MoveHandler & moveHandler, const Key & key); -private: - next_t _begin; - next_t _root; - NodeStore _nodes; - Compare _compare; - KeyExtract _keyExtractor; - next_t internalFind(const Key & key) const; - Value & get(size_t index) { return _nodes[index].getValue(); } - const Value & get(size_t index) const { return _nodes[index].getValue(); } - next_t getRightMost(next_t n) { - while(_nodes[n].hasRight()) { - n = _nodes[n].getRight()); - } - return n; - } - next_t getLeftMost(next_t n) { - while(_nodes[n].hasLeft()) { - n = _nodes[n].getleft()); - } - return n; - } - next_t getNextRight(next_t n) const { - if (_nodes[n].hasParent()) { - next_t parent = _nodes[_node].getParent(); - if (_nodes[parent].getLeft() == _node) { - return parent; - } else { - return getNextRight(parent); - } - } else if (_nodes[n].hasRight()) { - return getLeftMost(_nodes[n].getRight()); - } else { - return npos; - } - } - next_t getNextLeft(next_t n) const { - if (_nodes[n].hasParent()) { - next_t parent = _nodes[_node].getParent(); - if (_nodes[parent].getRight() == _node) { - return parent; - } else { - return getNextLeft(parent); - } - } else if (_nodes[n].hasLeft()) { - return getRightMost(_nodes[n].getLeft()); - } else { - return npos; - } - } -}; - -template< typename Key, typename Value, typename Compare, typename KeyExtract > -void avl::swap(avl & rhs) -{ - std::swap(_root, rhs._root); - _nodes.swap(rhs._nodes); - std::swap(_compare, rhs._compare); - std::swap(_keyExtractor, rhs._keyExtractor); -} - -template< typename Key, typename Value, typename Compare, typename KeyExtract > -avl::avl(size_t reservedSpace) : - _root(npos), - _nodes() -{ - if (reservedSpace > 0) { - reserve(reservedSpace); - } -} - -template< typename Key, typename Value, typename Compare, typename KeyExtract > -typename avl::iterator -avl::internalFind(const Key & key) -{ - next_t found = npos; // Last node which is not less than key. - - for (next_t n(_begin); n != npos; ) { - if (!_compare(_keyExtractor(_nodes[n]), key)) { - found = n; - n = getNextLeft(n); - } else { - n = getNextRight(n); - } - } - return ((found != npos) && ! _compare(key, _keyExtractor(_nodes[found]))) - ? found - : npos; -} - -template< typename Key, typename Value, typename Compare, typename KeyExtract > -typename avl::next_t -avl::insert(const Value & node) -{ - next_t n = _begin; - next_t e = npos; - Key key(_keyExtractor(node); - while (n != npos) { - e = n; - n = _compare(_keyExtractor(_nodes[n]), key) - ? getNextLeft(n) - : getNextRight(n); - } - return insert(n, e, node); -} - -template< typename Key, typename Value, typename Compare, typename KeyExtract > -typename avl::next_t -avl::insert(next_t n, next_t e, const Value & value) -{ - bool insert_left = (n != npos) || - (e == npos) || - _compare(_keyExtractor(value), _keyExtractor(_nodes[e])); - - next_t newN = _nodes.size(); - Node node(value); - _nodes.push_back(node); - - insert_and_rebalance(insert_left, newN, e, this->_M_impl._M_header); - return iterator(newN); -} - -template< typename Key, typename Value, typename Compare, typename KeyExtract > -void -avl::erase(const Key & key) -{ - next_t found = internalFind(key); - if (found != npos) { - // Link out - erase_and_rebalance(found); - // Swap with last - std::swap(_nodes[found], _nodes.back()); - nodes.resize(nodes.size() - 1); - // relink parent to last - if (_nodes[found].hasParent()) { - next_t parent = _nodes[found].getParent(); - if (_nodes[parent].getLeft() == old) { - _nodes[parent].setLeft(found); - } else { - _nodes[parent].setRight(found); - } - } - } -} - -template< typename Key, typename Value, typename Compare, typename KeyExtract > -size_t -avl::getMemoryConsumption() const -{ - return sizeof(*this) + _nodes.capacity() * sizeof(Node); -} - -#if 0 -template< typename Key, typename Value, typename Compare, typename KeyExtract > -template< typename AltKey, typename AltExtract, typename AltCompare> -typename avl::const_iterator -avl::find(const AltKey & key) const -{ - if (_modulo > 0) { - AltHash altHasher; - next_t h = altHasher(key) % _modulo; - if (_nodes[h].valid()) { - next_t start(h); - AltExtract altExtract; - AltCompare altCompare; - do { - if (altCompare(altExtract(_keyExtractor(_nodes[h].getValue())), key)) { - return const_iterator(this, start, h); - } - h = _nodes[h].getNext(); - } while (h != Node::npos); - } - } - return end(); -} - -template< typename Key, typename Value, typename Compare, typename KeyExtract > -template< typename AltKey, typename AltExtract, typename AltCompare> -typename avl::iterator -avl::find(const AltKey & key) -{ - if (_modulo > 0) { - AltHash altHasher; - next_t h = altHasher(key) % _modulo; - if (_nodes[h].valid()) { - next_t start(h); - AltExtract altExtract; - AltCompare altCompare; - do { - if (altCompare(altExtract(_keyExtractor(_nodes[h].getValue())), key)) { - return iterator(this, start, h); - } - h = _nodes[h].getNext(); - } while (h != Node::npos); - } - } - return end(); -} -#endif - -} - diff --git a/staging_vespalib/src/vespa/vespalib/stllike/avl_map.h b/staging_vespalib/src/vespa/vespalib/stllike/avl_map.h deleted file mode 100644 index 7eae6aea684..00000000000 --- a/staging_vespalib/src/vespa/vespalib/stllike/avl_map.h +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#pragma once - -#include - -namespace vespalib { - -template< typename K, typename V, typename EQ = std::equal_to > -class avl_map -{ -public: - typedef std::pair value_type; - typedef K key_type; - typedef V mapped_type; -private: - typedef avl< K, value_type, EQ, std::_Select1st< value_type > > Avl; - Avl _avl; -public: - typedef typename Avl::iterator iterator; - typedef typename Avl::const_iterator const_iterator; -public: - avl_map(size_t reserveSize=0) : _avl(reserveSize) { } - iterator begin() { return _avl.begin(); } - iterator end() { return _avl.end(); } - const_iterator begin() const { return _avl.begin(); } - const_iterator end() const { return _avl.end(); } - size_t capacity() const { return _avl.capacity(); } - size_t size() const { return _avl.size(); } - bool empty() const { return _avl.empty(); } - void insert(const value_type & value) { return _avl.insert(value); } - template - void insert(InputIt first, InputIt last); - V & operator [] (const K & key) const { return *_avl.find(key)->second; } - V & operator [] (const K & key); - void erase(const K & key) { return _avl.erase(key); } - iterator find(const K & key) { return _avl.find(key); } - const_iterator find(const K & key) const { return _avl.find(key); } - void clear() { _avl.clear(); } - void resize(size_t newSize) { _avl.resize(newSize); } - void swap(avl_map & rhs) { _avl.swap(rhs._avl); } -}; - -template -template -void avl_map::insert(InputIt first, InputIt last) { - while (first != last) { - _avl.insert(*first); - ++first; - } -} - -template< typename K, typename V, typename H, typename EQ > -V & avl_map::operator [] (const K & key) -{ - iterator found = _avl.find(key); - if (found != _avl.end()) { - return found->second; - } - insert(value_type(key, V())); - return _avl.find(key)->second; -} - -} - - diff --git a/staging_vespalib/src/vespa/vespalib/util/programoptions.h b/staging_vespalib/src/vespa/vespalib/util/programoptions.h index 58d1d133d04..9e25f960af7 100644 --- a/staging_vespalib/src/vespa/vespalib/util/programoptions.h +++ b/staging_vespalib/src/vespa/vespalib/util/programoptions.h @@ -23,12 +23,10 @@ #pragma once +#include #include #include -#include #include -#include -#include namespace vespalib { @@ -237,9 +235,9 @@ struct ProgramOptions::OptionParser { struct ProgramOptions::OptionHeader : public OptionParser { OptionHeader(const std::string& desc) : OptionParser("", 0, desc) {} - virtual void set(const std::vector&) override {} - virtual void setDefault() override {} - virtual bool isHeader() const override { return true; } + void set(const std::vector&) override {} + void setDefault() override {} + bool isHeader() const override { return true; } }; template @@ -262,61 +260,45 @@ struct ProgramOptions::NumberOptionParser : public OptionParser { : OptionParser(nameList, 1, getStringValue(defValue), desc), _number(number), _defaultValue(defValue) - { - } - - virtual void set(const std::vector& arguments) override; - - virtual void setDefault() override { _number = _defaultValue; } - - virtual std::string getArgType(uint32_t /* index */) const override - { return getTypeName(); } + {} + void set(const std::vector& arguments) override; + void setDefault() override { _number = _defaultValue; } + std::string getArgType(uint32_t /* index */) const override { + return getTypeName(); + } }; struct ProgramOptions::BoolOptionParser : public OptionParser { bool& _value; bool _defaultValue; - BoolOptionParser(const std::string& nameList, bool& value, - const std::string& description); - - virtual void set(const std::vector&) override { _value = true; } - - virtual void setDefault() override { _value = false; } + BoolOptionParser(const std::string& nameList, bool& value, const std::string& description); + void set(const std::vector&) override { _value = true; } + void setDefault() override { _value = false; } }; struct ProgramOptions::FlagOptionParser : public OptionParser { bool& _value; bool _unsetValue; - FlagOptionParser(const std::string& nameList, bool& value, - const std::string& description); - FlagOptionParser(const std::string& nameList, bool& value, - const bool& unsetValue, const std::string& description); - - virtual void set(const std::vector&) override { _value = !_unsetValue; } - - virtual void setDefault() override { _value = _unsetValue; } + FlagOptionParser(const std::string& nameList, bool& value, const std::string& description); + FlagOptionParser(const std::string& nameList, bool& value, const bool& unsetValue, const std::string& description); + void set(const std::vector&) override { _value = !_unsetValue; } + void setDefault() override { _value = _unsetValue; } }; struct ProgramOptions::StringOptionParser : public OptionParser { std::string& _value; std::string _defaultValue; - StringOptionParser(const std::string& nameList, std::string& value, - const std::string& description); - + StringOptionParser(const std::string& nameList, std::string& value, const std::string& description); StringOptionParser(const std::string& nameList, std::string& value, const std::string& defVal, const std::string& desc); - virtual void set(const std::vector& arguments) override - { _value = arguments[0]; } - - virtual void setDefault() override { _value = _defaultValue; } - - virtual std::string getArgType(uint32_t /* index */) const override - { return "string"; } + void set(const std::vector& arguments) override { _value = arguments[0]; } + void setDefault() override { _value = _defaultValue; } + std::string getArgType(uint32_t /* index */) const override { return "string"; } }; struct ProgramOptions::MapOptionParser : public OptionParser { @@ -327,14 +309,14 @@ struct ProgramOptions::MapOptionParser : public OptionParser { std::map& value, const std::string& description); - virtual void set(const std::vector& arguments) override - { _value[arguments[0]] = arguments[1]; } + void set(const std::vector& arguments) override { + _value[arguments[0]] = arguments[1]; + } - virtual std::string getArgType(uint32_t /* index */) const override - { return "string"; } + std::string getArgType(uint32_t /* index */) const override { return "string"; } - // Default of map is just an empty map. - virtual void setDefault() override { _value.clear(); } + // Default of map is just an empty map. + void setDefault() override { _value.clear(); } }; template @@ -356,9 +338,8 @@ struct ProgramOptions::ListOptionParser : public OptionParser { void setEntryParser(OptionParser::UP entryParser) { _entryParser = std::move(entryParser); } - - virtual bool isRequired() const override { return false; } - virtual void set(const std::vector& arguments) override { + bool isRequired() const override { return false; } + void set(const std::vector& arguments) override { for (uint32_t i=0; i v; v.push_back(arguments[i]); @@ -366,10 +347,10 @@ struct ProgramOptions::ListOptionParser : public OptionParser { _value.push_back(_singleValue); } } - virtual void setDefault() override { + void setDefault() override { _value.clear(); } - virtual std::string getArgType(uint32_t index) const override { + std::string getArgType(uint32_t index) const override { return _entryParser->getArgType(index) + "[]"; } }; -- cgit v1.2.3