scruby 0.7.0__py3-none-any.whl → 0.7.1__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 +4 -4
- scruby/db.py +7 -7
- {scruby-0.7.0.dist-info → scruby-0.7.1.dist-info}/METADATA +2 -2
- scruby-0.7.1.dist-info/RECORD +8 -0
- scruby-0.7.0.dist-info/RECORD +0 -8
- {scruby-0.7.0.dist-info → scruby-0.7.1.dist-info}/WHEEL +0 -0
- {scruby-0.7.0.dist-info → scruby-0.7.1.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
|
+
- `LENGTH_REDUCTION_HASH` - The length of the hash reduction on the left side.
|
|
7
7
|
- `0` - 4294967296 keys (by default).
|
|
8
8
|
- `2` - 16777216 keys.
|
|
9
9
|
- `4` - 65536 keys.
|
|
@@ -14,7 +14,7 @@ from __future__ import annotations
|
|
|
14
14
|
|
|
15
15
|
__all__ = (
|
|
16
16
|
"DB_ROOT",
|
|
17
|
-
"
|
|
17
|
+
"LENGTH_REDUCTION_HASH",
|
|
18
18
|
)
|
|
19
19
|
|
|
20
20
|
from typing import Literal
|
|
@@ -23,9 +23,9 @@ from typing import Literal
|
|
|
23
23
|
# By default = "ScrubyDB" (in root of project).
|
|
24
24
|
DB_ROOT: str = "ScrubyDB"
|
|
25
25
|
|
|
26
|
-
#
|
|
26
|
+
# The length of the hash reduction on the left side.
|
|
27
27
|
# 0 = 4294967296 keys (by default).
|
|
28
28
|
# 2 = 16777216 keys.
|
|
29
29
|
# 4 = 65536 keys.
|
|
30
30
|
# 6 = 256 keys (main purpose is tests).
|
|
31
|
-
|
|
31
|
+
LENGTH_REDUCTION_HASH: Literal[0, 2, 4, 6] = 0
|
scruby/db.py
CHANGED
|
@@ -33,9 +33,9 @@ class Scruby[T]:
|
|
|
33
33
|
) -> None:
|
|
34
34
|
self.__class_model = class_model
|
|
35
35
|
self.__db_root = constants.DB_ROOT
|
|
36
|
-
self.
|
|
36
|
+
self.__length_reduction_hash = constants.LENGTH_REDUCTION_HASH
|
|
37
37
|
# The maximum number of keys.
|
|
38
|
-
match self.
|
|
38
|
+
match self.__length_reduction_hash:
|
|
39
39
|
case 0:
|
|
40
40
|
self.__max_num_keys = 4294967296
|
|
41
41
|
case 2:
|
|
@@ -58,7 +58,7 @@ class Scruby[T]:
|
|
|
58
58
|
if len(key) == 0:
|
|
59
59
|
raise KeyError("The key should not be empty.")
|
|
60
60
|
# Key to crc32 sum.
|
|
61
|
-
key_as_hash: str = f"{zlib.crc32(key.encode('utf-8')):08x}"[self.
|
|
61
|
+
key_as_hash: str = f"{zlib.crc32(key.encode('utf-8')):08x}"[self.__length_reduction_hash :]
|
|
62
62
|
# Convert crc32 sum in the segment of path.
|
|
63
63
|
separated_hash: str = "/".join(list(key_as_hash))
|
|
64
64
|
# The path of the branch to the database.
|
|
@@ -170,12 +170,12 @@ class Scruby[T]:
|
|
|
170
170
|
def search_task(
|
|
171
171
|
key: int,
|
|
172
172
|
filter_fn: Callable,
|
|
173
|
-
|
|
173
|
+
length_reduction_hash: str,
|
|
174
174
|
db_root: str,
|
|
175
175
|
class_model: T,
|
|
176
176
|
) -> dict[str, Any] | None:
|
|
177
177
|
"""Search task."""
|
|
178
|
-
key_as_hash: str = f"{key:08x}"[
|
|
178
|
+
key_as_hash: str = f"{key:08x}"[length_reduction_hash:]
|
|
179
179
|
separated_hash: str = "/".join(list(key_as_hash))
|
|
180
180
|
leaf_path: SyncPath = SyncPath(
|
|
181
181
|
*(
|
|
@@ -216,7 +216,7 @@ class Scruby[T]:
|
|
|
216
216
|
"""
|
|
217
217
|
keys: range = range(1, self.__max_num_keys)
|
|
218
218
|
search_task_fn: Callable = self.search_task
|
|
219
|
-
|
|
219
|
+
length_reduction_hash: int = self.__length_reduction_hash
|
|
220
220
|
db_root: str = self.__db_root
|
|
221
221
|
class_model: T = self.__class_model
|
|
222
222
|
with concurrent.futures.ThreadPoolExecutor(max_workers) as executor:
|
|
@@ -225,7 +225,7 @@ class Scruby[T]:
|
|
|
225
225
|
search_task_fn,
|
|
226
226
|
key,
|
|
227
227
|
filter_fn,
|
|
228
|
-
|
|
228
|
+
length_reduction_hash,
|
|
229
229
|
db_root,
|
|
230
230
|
class_model,
|
|
231
231
|
)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: scruby
|
|
3
|
-
Version: 0.7.
|
|
3
|
+
Version: 0.7.1
|
|
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
|
|
@@ -171,7 +171,7 @@ from scruby import Scruby, constants
|
|
|
171
171
|
from pprint import pprint as pp
|
|
172
172
|
|
|
173
173
|
constants.DB_ROOT = "ScrubyDB" # By default = "ScrubyDB"
|
|
174
|
-
constants.
|
|
174
|
+
constants.LENGTH_REDUCTION_HASH = 6 # 256 keys (main purpose is tests).
|
|
175
175
|
|
|
176
176
|
class User(BaseModel):
|
|
177
177
|
"""Model of User."""
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
scruby/__init__.py,sha256=myX7sG-7oAQZGdgfZtTGXYCCraTeuwi7SjBoltftpnM,648
|
|
2
|
+
scruby/constants.py,sha256=XcBbK_gkDC0makWE34M8gUotwj3smi2sWY4mMnfzUt4,874
|
|
3
|
+
scruby/db.py,sha256=FkYBsVYERtauTlWjl8b8cDTTIaH1w7lOzAneWUtNLDE,8114
|
|
4
|
+
scruby/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
+
scruby-0.7.1.dist-info/METADATA,sha256=qkiNaSRnF2pnWMImFLsAz16MMRD_amaDImy9DbFwNoM,8616
|
|
6
|
+
scruby-0.7.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
7
|
+
scruby-0.7.1.dist-info/licenses/LICENSE,sha256=2zZINd6m_jNYlowdQImlEizyhSui5cBAJZRhWQURcEc,1095
|
|
8
|
+
scruby-0.7.1.dist-info/RECORD,,
|
scruby-0.7.0.dist-info/RECORD
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
scruby/__init__.py,sha256=myX7sG-7oAQZGdgfZtTGXYCCraTeuwi7SjBoltftpnM,648
|
|
2
|
-
scruby/constants.py,sha256=1Po5FSYj1qst8F05L4cPyKsDHNmReXDx_IKYgNa06eI,892
|
|
3
|
-
scruby/db.py,sha256=qelkW6MzI4HQOtkXDb8qOJHfqsads3vILSnddboQEOc,8034
|
|
4
|
-
scruby/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
-
scruby-0.7.0.dist-info/METADATA,sha256=uH-rBdWc5tDUhFxTYac6Z3EDua6z-H-mWBXo9gB47Mc,8616
|
|
6
|
-
scruby-0.7.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
7
|
-
scruby-0.7.0.dist-info/licenses/LICENSE,sha256=2zZINd6m_jNYlowdQImlEizyhSui5cBAJZRhWQURcEc,1095
|
|
8
|
-
scruby-0.7.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|