small-cache 0.0.3__tar.gz → 0.0.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {small_cache-0.0.3 → small_cache-0.0.4}/CMakeLists.txt +1 -1
- {small_cache-0.0.3 → small_cache-0.0.4}/PKG-INFO +1 -1
- {small_cache-0.0.3 → small_cache-0.0.4}/pyproject.toml +2 -2
- {small_cache-0.0.3 → small_cache-0.0.4}/src/small_cache.cpp +22 -22
- {small_cache-0.0.3 → small_cache-0.0.4}/.github/dependabot.yml +0 -0
- {small_cache-0.0.3 → small_cache-0.0.4}/.github/workflows/pip.yml +0 -0
- {small_cache-0.0.3 → small_cache-0.0.4}/.github/workflows/wheels.yml +0 -0
- {small_cache-0.0.3 → small_cache-0.0.4}/.gitignore +0 -0
- {small_cache-0.0.3 → small_cache-0.0.4}/README.md +0 -0
- {small_cache-0.0.3 → small_cache-0.0.4}/src/small_cache/__init__.py +0 -0
- {small_cache-0.0.3 → small_cache-0.0.4}/tests/test_basic.py +0 -0
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
[build-system]
|
|
2
|
-
requires = ["scikit-build-core >=0.10", "nanobind
|
|
2
|
+
requires = ["scikit-build-core >=0.10", "nanobind ==2.9.2"]
|
|
3
3
|
build-backend = "scikit_build_core.build"
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "small-cache"
|
|
7
|
-
version = "0.0.
|
|
7
|
+
version = "0.0.4"
|
|
8
8
|
description = "Small cache"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.11"
|
|
@@ -8,7 +8,6 @@
|
|
|
8
8
|
#include <tsl/sparse_map.h>
|
|
9
9
|
#include <absl/hash/hash.h>
|
|
10
10
|
#include <absl/container/flat_hash_map.h>
|
|
11
|
-
#include <absl/container/flat_hash_set.h>
|
|
12
11
|
#include <boost/flyweight.hpp>
|
|
13
12
|
#include <optional>
|
|
14
13
|
#include <algorithm>
|
|
@@ -317,37 +316,37 @@ public:
|
|
|
317
316
|
return {};
|
|
318
317
|
}
|
|
319
318
|
|
|
320
|
-
|
|
319
|
+
std::vector<std::vector<pyAttrValue>> get_many(const strVec &ids, const strVec &attributes) {
|
|
320
|
+
std::vector<std::vector<pyAttrValue>> out;
|
|
321
|
+
out.resize(ids.size());
|
|
322
|
+
for (size_t i = 0; i < ids.size(); ++i) {
|
|
323
|
+
out[i] = get_one(ids[i], attributes);
|
|
324
|
+
}
|
|
325
|
+
return out;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
struct getAllResponse {
|
|
321
329
|
uint64_t iterator_version{};
|
|
322
330
|
uint64_t iterator{};
|
|
323
331
|
std::vector<std::pair<str, std::vector<pyAttrValue>>> result{};
|
|
324
332
|
};
|
|
325
333
|
|
|
326
|
-
str
|
|
327
|
-
|
|
334
|
+
str get_all(const strVec &attributes, uint64_t per_iteration = 10000, uint64_t iterator_version = 0,
|
|
335
|
+
uint64_t iterator = 0) {
|
|
328
336
|
if (transactionOpened)
|
|
329
|
-
throw std::runtime_error("Can't get
|
|
337
|
+
throw std::runtime_error("Can't get all when transaction is opened");
|
|
330
338
|
if (iterator && iterator_version == 0) {
|
|
331
339
|
throw std::runtime_error("Invalid iterator version");
|
|
332
340
|
}
|
|
333
341
|
if (iterator && iterator_version != this->iterator_version)
|
|
334
342
|
throw std::runtime_error("Iterator already invalidated");
|
|
335
|
-
|
|
336
|
-
std::vector<str> keys;
|
|
337
|
-
if (ids.empty()) {
|
|
338
|
-
keys = cache | std::views::keys | std::ranges::to<std::vector>();
|
|
339
|
-
std::ranges::sort(keys);
|
|
340
|
-
} else {
|
|
341
|
-
absl::flat_hash_set<str> set_of_ids(ids.begin(), ids.end());
|
|
342
|
-
keys = cache | std::views::keys |
|
|
343
|
-
std::views::filter([&](const auto &key) { return set_of_ids.contains(key); }) |
|
|
344
|
-
std::ranges::to<std::vector>();
|
|
345
|
-
}
|
|
343
|
+
getAllResponse resp{};
|
|
344
|
+
std::vector<str> keys = cache | std::views::keys | std::ranges::to<std::vector>();
|
|
346
345
|
std::ranges::sort(keys);
|
|
347
346
|
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
347
|
+
uint64_t start = iterator;
|
|
348
|
+
uint64_t available = keys.size() > start ? keys.size() - start : 0;
|
|
349
|
+
uint64_t to_take = std::min<uint64_t>(available, per_iteration);
|
|
351
350
|
|
|
352
351
|
resp.result.reserve(to_take);
|
|
353
352
|
|
|
@@ -443,9 +442,10 @@ NB_MODULE(_small_cache_impl, m) {
|
|
|
443
442
|
.def("end_transaction", &SmallCache::end_transaction)
|
|
444
443
|
.def("add", &SmallCache::add_item, nb::arg("item_id"), nb::arg("attributes"))
|
|
445
444
|
.def("get_one", &SmallCache::get_one, nb::arg("id"), nb::arg("attributes"))
|
|
446
|
-
.def("get_many", &SmallCache::get_many, nb::arg("ids"), nb::arg("attributes")
|
|
447
|
-
|
|
448
|
-
|
|
445
|
+
.def("get_many", &SmallCache::get_many, nb::arg("ids"), nb::arg("attributes"))
|
|
446
|
+
.def("get_all", &SmallCache::get_all, nb::arg("attributes"), nb::arg("per_iteration") = 10000,
|
|
447
|
+
nb::arg("iterator_version") = 0,
|
|
448
|
+
nb::arg("iterator") = 0)
|
|
449
449
|
.def("load_page", &SmallCache::load_page, nb::arg("json_text"));
|
|
450
450
|
// nb::class_<SmallCache::getAllResponse>(cache, "getAllResponse")
|
|
451
451
|
// .def(nb::init<>())
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|