Skip to content

Commit

Permalink
feat: add Size interface for binaryset
Browse files Browse the repository at this point in the history
Signed-off-by: chyezh <[email protected]>
  • Loading branch information
chyezh committed May 23, 2024
1 parent 080e5c2 commit bd7f0db
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ export VERBOSE=1
conan install .. --build=missing -o with_ut=True -s compiler.libcxx=libc++ -s build_type=Release
#DEBUG CPU
conan install .. --build=missing -o with_ut=True -s compiler.libcxx=libc++ -s build_type=Debug
#build with conan
conan build ..
```

#### Running Unit Tests
Expand Down
12 changes: 12 additions & 0 deletions include/knowhere/binaryset.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,18 @@ class BinarySet {
return binary_map_.find(key) != binary_map_.end();
}

// Return the total size of all binary data in binary set.
size_t
Size() const {
size_t size = 0;
for (auto& pair : binary_map_) {
if (pair.second != nullptr) {
size += pair.second->size;
}
}
return size;
}

public:
std::map<std::string, BinaryPtr> binary_map_;
};
Expand Down
34 changes: 34 additions & 0 deletions tests/ut/test_binaryset.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright (C) 2019-2023 Zilliz. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the License
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
// or implied. See the License for the specific language governing permissions and limitations under the License.

#include "catch2/catch_test_macros.hpp"
#include "knowhere/binaryset.h"

TEST_CASE("Test binaryset", "[binaryset]") {
SECTION("check binaryset interfaces") {
knowhere::BinarySet binary_set;
std::shared_ptr<uint8_t[]> sp1(new uint8_t[1]{1});
binary_set.Append("test", sp1, 1);
REQUIRE(binary_set.Contains("test"));
auto binary_get = binary_set.GetByName("test");
REQUIRE(binary_get->size == 1);
REQUIRE(binary_get->data != nullptr);
REQUIRE(binary_set.Size() == 1);

std::shared_ptr<uint8_t[]> sp2(new uint8_t[2]{1, 2});
binary_set.Append("test2", sp2, 2);
REQUIRE(binary_set.Contains("test2"));
binary_get = binary_set.GetByName("test2");
REQUIRE(binary_get->size == 2);
REQUIRE(binary_get->data != nullptr);
REQUIRE(binary_set.Size() == 3);
}
}

0 comments on commit bd7f0db

Please sign in to comment.