scruby 0.10.2__py3-none-any.whl → 0.10.4__py3-none-any.whl
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.
Potentially problematic release.
This version of scruby might be problematic. Click here for more details.
- scruby/constants.py +3 -3
- scruby/db.py +35 -21
- scruby/errors.py +23 -0
- {scruby-0.10.2.dist-info → scruby-0.10.4.dist-info}/METADATA +3 -3
- scruby-0.10.4.dist-info/RECORD +9 -0
- scruby-0.10.2.dist-info/RECORD +0 -8
- {scruby-0.10.2.dist-info → scruby-0.10.4.dist-info}/WHEEL +0 -0
- {scruby-0.10.2.dist-info → scruby-0.10.4.dist-info}/licenses/LICENSE +0 -0
scruby/constants.py
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
The module contains the following variables:
|
|
4
4
|
|
|
5
5
|
- `DB_ROOT` - Path to root directory of database. `By default = "ScrubyDB"` (*in root of project*).
|
|
6
|
-
- `
|
|
6
|
+
- `HASH_REDUCE_LEFT` - The length of the hash reduction on the left side.
|
|
7
7
|
- `0` - 4294967296 branches in collection (by default).
|
|
8
8
|
- `2` - 16777216 branches in collectionю
|
|
9
9
|
- `4` - 65536 branches in collectionю
|
|
@@ -14,7 +14,7 @@ from __future__ import annotations
|
|
|
14
14
|
|
|
15
15
|
__all__ = (
|
|
16
16
|
"DB_ROOT",
|
|
17
|
-
"
|
|
17
|
+
"HASH_REDUCE_LEFT",
|
|
18
18
|
)
|
|
19
19
|
|
|
20
20
|
from typing import Literal
|
|
@@ -28,4 +28,4 @@ DB_ROOT: str = "ScrubyDB"
|
|
|
28
28
|
# 2 = 16777216 branches in collectionю
|
|
29
29
|
# 4 = 65536 branches in collectionю
|
|
30
30
|
# 6 = 256 branches in collection (main purpose is tests).
|
|
31
|
-
|
|
31
|
+
HASH_REDUCE_LEFT: Literal[0, 2, 4, 6] = 0
|
scruby/db.py
CHANGED
|
@@ -44,9 +44,9 @@ class Scruby[T]:
|
|
|
44
44
|
self.__meta = _Meta
|
|
45
45
|
self.__class_model = class_model
|
|
46
46
|
self.__db_root = constants.DB_ROOT
|
|
47
|
-
self.
|
|
47
|
+
self.__hash_reduce_left = constants.HASH_REDUCE_LEFT
|
|
48
48
|
# The maximum number of keys.
|
|
49
|
-
match self.
|
|
49
|
+
match self.__hash_reduce_left:
|
|
50
50
|
case 0:
|
|
51
51
|
self.__max_num_keys = 4294967296
|
|
52
52
|
case 2:
|
|
@@ -56,10 +56,11 @@ class Scruby[T]:
|
|
|
56
56
|
case 6:
|
|
57
57
|
self.__max_num_keys = 256
|
|
58
58
|
case _ as unreachable:
|
|
59
|
-
msg: str = f"{unreachable} - Unacceptable value for
|
|
59
|
+
msg: str = f"{unreachable} - Unacceptable value for HASH_REDUCE_LEFT."
|
|
60
60
|
logger.critical(msg)
|
|
61
61
|
assert_never(Never(unreachable))
|
|
62
|
-
# Create metadata if absent.
|
|
62
|
+
# 1.Create metadata if absent.
|
|
63
|
+
# 2.Check metadata.
|
|
63
64
|
self._create_metadata()
|
|
64
65
|
|
|
65
66
|
def _create_metadata(self) -> None:
|
|
@@ -68,7 +69,7 @@ class Scruby[T]:
|
|
|
68
69
|
This method is for internal use.
|
|
69
70
|
"""
|
|
70
71
|
key: int = 0
|
|
71
|
-
key_as_hash: str = f"{key:08x}"[self.
|
|
72
|
+
key_as_hash: str = f"{key:08x}"[self.__hash_reduce_left :]
|
|
72
73
|
separated_hash: str = "/".join(list(key_as_hash))
|
|
73
74
|
branch_path = SyncPath(
|
|
74
75
|
*(
|
|
@@ -92,7 +93,7 @@ class Scruby[T]:
|
|
|
92
93
|
This method is for internal use.
|
|
93
94
|
"""
|
|
94
95
|
key: int = 0
|
|
95
|
-
key_as_hash: str = f"{key:08x}"[self.
|
|
96
|
+
key_as_hash: str = f"{key:08x}"[self.__hash_reduce_left :]
|
|
96
97
|
separated_hash: str = "/".join(list(key_as_hash))
|
|
97
98
|
return Path(
|
|
98
99
|
*(
|
|
@@ -148,7 +149,7 @@ class Scruby[T]:
|
|
|
148
149
|
logger.error("The key should not be empty.")
|
|
149
150
|
raise KeyError("The key should not be empty.")
|
|
150
151
|
# Key to crc32 sum.
|
|
151
|
-
key_as_hash: str = f"{zlib.crc32(key.encode('utf-8')):08x}"[self.
|
|
152
|
+
key_as_hash: str = f"{zlib.crc32(key.encode('utf-8')):08x}"[self.__hash_reduce_left :]
|
|
152
153
|
# Convert crc32 sum in the segment of path.
|
|
153
154
|
separated_hash: str = "/".join(list(key_as_hash))
|
|
154
155
|
# The path of the branch to the database.
|
|
@@ -265,10 +266,10 @@ class Scruby[T]:
|
|
|
265
266
|
return
|
|
266
267
|
|
|
267
268
|
@staticmethod
|
|
268
|
-
def
|
|
269
|
+
def _task_find(
|
|
269
270
|
key: int,
|
|
270
271
|
filter_fn: Callable,
|
|
271
|
-
|
|
272
|
+
HASH_REDUCE_LEFT: str,
|
|
272
273
|
db_root: str,
|
|
273
274
|
class_model: T,
|
|
274
275
|
) -> dict[str, Any] | None:
|
|
@@ -276,7 +277,7 @@ class Scruby[T]:
|
|
|
276
277
|
|
|
277
278
|
This method is for internal use.
|
|
278
279
|
"""
|
|
279
|
-
key_as_hash: str = f"{key:08x}"[
|
|
280
|
+
key_as_hash: str = f"{key:08x}"[HASH_REDUCE_LEFT:]
|
|
280
281
|
separated_hash: str = "/".join(list(key_as_hash))
|
|
281
282
|
leaf_path: SyncPath = SyncPath(
|
|
282
283
|
*(
|
|
@@ -316,8 +317,8 @@ class Scruby[T]:
|
|
|
316
317
|
If None, then there is no limit on the wait time.
|
|
317
318
|
"""
|
|
318
319
|
keys: range = range(1, self.__max_num_keys)
|
|
319
|
-
search_task_fn: Callable = self.
|
|
320
|
-
|
|
320
|
+
search_task_fn: Callable = self._task_find
|
|
321
|
+
HASH_REDUCE_LEFT: int = self.__hash_reduce_left
|
|
321
322
|
db_root: str = self.__db_root
|
|
322
323
|
class_model: T = self.__class_model
|
|
323
324
|
with concurrent.futures.ThreadPoolExecutor(max_workers) as executor:
|
|
@@ -326,7 +327,7 @@ class Scruby[T]:
|
|
|
326
327
|
search_task_fn,
|
|
327
328
|
key,
|
|
328
329
|
filter_fn,
|
|
329
|
-
|
|
330
|
+
HASH_REDUCE_LEFT,
|
|
330
331
|
db_root,
|
|
331
332
|
class_model,
|
|
332
333
|
)
|
|
@@ -358,8 +359,8 @@ class Scruby[T]:
|
|
|
358
359
|
If None, then there is no limit on the wait time.
|
|
359
360
|
"""
|
|
360
361
|
keys: range = range(1, self.__max_num_keys)
|
|
361
|
-
search_task_fn: Callable = self.
|
|
362
|
-
|
|
362
|
+
search_task_fn: Callable = self._task_find
|
|
363
|
+
HASH_REDUCE_LEFT: int = self.__hash_reduce_left
|
|
363
364
|
db_root: str = self.__db_root
|
|
364
365
|
class_model: T = self.__class_model
|
|
365
366
|
counter: int = 0
|
|
@@ -372,7 +373,7 @@ class Scruby[T]:
|
|
|
372
373
|
search_task_fn,
|
|
373
374
|
key,
|
|
374
375
|
filter_fn,
|
|
375
|
-
|
|
376
|
+
HASH_REDUCE_LEFT,
|
|
376
377
|
db_root,
|
|
377
378
|
class_model,
|
|
378
379
|
)
|
|
@@ -401,10 +402,23 @@ class Scruby[T]:
|
|
|
401
402
|
max_workers: int | None = None,
|
|
402
403
|
timeout: float | None = None,
|
|
403
404
|
) -> int:
|
|
404
|
-
"""Count the number of documents a matching the filter in this collection.
|
|
405
|
+
"""Count the number of documents a matching the filter in this collection.
|
|
406
|
+
|
|
407
|
+
The search is based on the effect of a quantum loop.
|
|
408
|
+
The search effectiveness depends on the number of processor threads.
|
|
409
|
+
Ideally, hundreds and even thousands of threads are required.
|
|
410
|
+
|
|
411
|
+
Args:
|
|
412
|
+
filter_fn: A function that execute the conditions of filtering.
|
|
413
|
+
max_workers: The maximum number of processes that can be used to
|
|
414
|
+
execute the given calls. If None or not given then as many
|
|
415
|
+
worker processes will be created as the machine has processors.
|
|
416
|
+
timeout: The number of seconds to wait for the result if the future isn't done.
|
|
417
|
+
If None, then there is no limit on the wait time.
|
|
418
|
+
"""
|
|
405
419
|
keys: range = range(1, self.__max_num_keys)
|
|
406
|
-
search_task_fn: Callable = self.
|
|
407
|
-
|
|
420
|
+
search_task_fn: Callable = self._task_find
|
|
421
|
+
HASH_REDUCE_LEFT: int = self.__hash_reduce_left
|
|
408
422
|
db_root: str = self.__db_root
|
|
409
423
|
class_model: T = self.__class_model
|
|
410
424
|
counter: int = 0
|
|
@@ -414,10 +428,10 @@ class Scruby[T]:
|
|
|
414
428
|
search_task_fn,
|
|
415
429
|
key,
|
|
416
430
|
filter_fn,
|
|
417
|
-
|
|
431
|
+
HASH_REDUCE_LEFT,
|
|
418
432
|
db_root,
|
|
419
433
|
class_model,
|
|
420
434
|
)
|
|
421
435
|
if future.result(timeout) is not None:
|
|
422
436
|
counter += 1
|
|
423
|
-
|
|
437
|
+
return counter
|
scruby/errors.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"""Scruby Exceptions."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
__all__ = (
|
|
6
|
+
"ScrubyException",
|
|
7
|
+
"MetadataValueError",
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class ScrubyException(Exception):
|
|
12
|
+
"""Root Custom Exception."""
|
|
13
|
+
|
|
14
|
+
def __init__(self, *args, **kwargs) -> None: # type: ignore[no-untyped-def] # noqa: D107
|
|
15
|
+
super().__init__(*args, **kwargs)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class MetadataValueError(ScrubyException):
|
|
19
|
+
"""Exception is raised if value of variable in metadata does not matching expected."""
|
|
20
|
+
|
|
21
|
+
def __init__(self, message: str) -> None: # noqa: D107
|
|
22
|
+
self.message = message
|
|
23
|
+
super().__init__(self.message)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: scruby
|
|
3
|
-
Version: 0.10.
|
|
3
|
+
Version: 0.10.4
|
|
4
4
|
Summary: A fast key-value storage library.
|
|
5
5
|
Project-URL: Homepage, https://github.com/kebasyaty/scruby
|
|
6
6
|
Project-URL: Repository, https://github.com/kebasyaty/scruby
|
|
@@ -175,7 +175,7 @@ from scruby import Scruby, constants
|
|
|
175
175
|
from pprint import pprint as pp
|
|
176
176
|
|
|
177
177
|
constants.DB_ROOT = "ScrubyDB" # By default = "ScrubyDB"
|
|
178
|
-
constants.
|
|
178
|
+
constants.HASH_REDUCE_LEFT = 6 # 256 branches in collection
|
|
179
179
|
# (main purpose is tests).
|
|
180
180
|
|
|
181
181
|
class User(BaseModel):
|
|
@@ -246,7 +246,7 @@ from scruby import Scruby, constants
|
|
|
246
246
|
from pprint import pprint as pp
|
|
247
247
|
|
|
248
248
|
constants.DB_ROOT = "ScrubyDB" # By default = "ScrubyDB"
|
|
249
|
-
constants.
|
|
249
|
+
constants.HASH_REDUCE_LEFT = 6 # 256 branches in collection
|
|
250
250
|
# (main purpose is tests).
|
|
251
251
|
|
|
252
252
|
class User(BaseModel):
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
scruby/__init__.py,sha256=wFwUS1KcLxfIopXOVS8gPue9fNzIIU2cVj_RgK5drz4,849
|
|
2
|
+
scruby/constants.py,sha256=3LZfcxcuRqwzoB0-iogLMjKBZRdxfWJmTbyPwVRhQgY,1007
|
|
3
|
+
scruby/db.py,sha256=k_I2rphHG7Y5vq8oGDoimlKEwPEwmYzkqn7_DO0M6ic,15853
|
|
4
|
+
scruby/errors.py,sha256=aHQri4LNcFVQrSHwjyzb1fL8O49SwjYEU4QgMOo4uyA,622
|
|
5
|
+
scruby/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
6
|
+
scruby-0.10.4.dist-info/METADATA,sha256=oJLzRBPPatu6dsq7EQyxf-UHQn4uJ1kF3C7Q-heqVNw,10819
|
|
7
|
+
scruby-0.10.4.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
8
|
+
scruby-0.10.4.dist-info/licenses/LICENSE,sha256=2zZINd6m_jNYlowdQImlEizyhSui5cBAJZRhWQURcEc,1095
|
|
9
|
+
scruby-0.10.4.dist-info/RECORD,,
|
scruby-0.10.2.dist-info/RECORD
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
scruby/__init__.py,sha256=wFwUS1KcLxfIopXOVS8gPue9fNzIIU2cVj_RgK5drz4,849
|
|
2
|
-
scruby/constants.py,sha256=GbB-O0qaVdi5EHUp-zRAppFXLR-oHxpXUFVAOCpS0C8,1022
|
|
3
|
-
scruby/db.py,sha256=LwSmkgFfxHLIKIJ6skE4FZ-Ad2GAItKbXYiMPBS8f18,15189
|
|
4
|
-
scruby/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
-
scruby-0.10.2.dist-info/METADATA,sha256=cJT0AGNe98yqY0CChu-lUmxLy03jy99U_11YdHndrvk,10829
|
|
6
|
-
scruby-0.10.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
7
|
-
scruby-0.10.2.dist-info/licenses/LICENSE,sha256=2zZINd6m_jNYlowdQImlEizyhSui5cBAJZRhWQURcEc,1095
|
|
8
|
-
scruby-0.10.2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|