beaver-db 0.16.0__py3-none-any.whl → 0.16.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 beaver-db might be problematic. Click here for more details.
- beaver/lists.py +55 -53
- {beaver_db-0.16.0.dist-info → beaver_db-0.16.1.dist-info}/METADATA +1 -1
- {beaver_db-0.16.0.dist-info → beaver_db-0.16.1.dist-info}/RECORD +6 -6
- {beaver_db-0.16.0.dist-info → beaver_db-0.16.1.dist-info}/WHEEL +0 -0
- {beaver_db-0.16.0.dist-info → beaver_db-0.16.1.dist-info}/licenses/LICENSE +0 -0
- {beaver_db-0.16.0.dist-info → beaver_db-0.16.1.dist-info}/top_level.txt +0 -0
beaver/lists.py
CHANGED
|
@@ -40,38 +40,40 @@ class ListManager[T]:
|
|
|
40
40
|
Retrieves an item or slice from the list (e.g., `my_list[0]`, `my_list[1:3]`).
|
|
41
41
|
"""
|
|
42
42
|
if isinstance(key, slice):
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
43
|
+
with self._conn:
|
|
44
|
+
start, stop, step = key.indices(len(self))
|
|
45
|
+
if step != 1:
|
|
46
|
+
raise ValueError("Slicing with a step is not supported.")
|
|
47
|
+
|
|
48
|
+
limit = stop - start
|
|
49
|
+
if limit <= 0:
|
|
50
|
+
return []
|
|
51
|
+
|
|
52
|
+
cursor = self._conn.cursor()
|
|
53
|
+
cursor.execute(
|
|
54
|
+
"SELECT item_value FROM beaver_lists WHERE list_name = ? ORDER BY item_order ASC LIMIT ? OFFSET ?",
|
|
55
|
+
(self._name, limit, start),
|
|
56
|
+
)
|
|
57
|
+
results = [self._deserialize(row["item_value"]) for row in cursor.fetchall()]
|
|
58
|
+
cursor.close()
|
|
59
|
+
return results
|
|
59
60
|
|
|
60
61
|
elif isinstance(key, int):
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
62
|
+
with self._conn:
|
|
63
|
+
list_len = len(self)
|
|
64
|
+
if key < -list_len or key >= list_len:
|
|
65
|
+
raise IndexError("List index out of range.")
|
|
66
|
+
|
|
67
|
+
offset = key if key >= 0 else list_len + key
|
|
68
|
+
|
|
69
|
+
cursor = self._conn.cursor()
|
|
70
|
+
cursor.execute(
|
|
71
|
+
"SELECT item_value FROM beaver_lists WHERE list_name = ? ORDER BY item_order ASC LIMIT 1 OFFSET ?",
|
|
72
|
+
(self._name, offset),
|
|
73
|
+
)
|
|
74
|
+
result = cursor.fetchone()
|
|
75
|
+
cursor.close()
|
|
76
|
+
return self._deserialize(result["item_value"])
|
|
75
77
|
|
|
76
78
|
else:
|
|
77
79
|
raise TypeError("List indices must be integers or slices.")
|
|
@@ -81,13 +83,13 @@ class ListManager[T]:
|
|
|
81
83
|
if not isinstance(key, int):
|
|
82
84
|
raise TypeError("List indices must be integers.")
|
|
83
85
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
86
|
+
with self._conn:
|
|
87
|
+
list_len = len(self)
|
|
88
|
+
if key < -list_len or key >= list_len:
|
|
89
|
+
raise IndexError("List index out of range.")
|
|
87
90
|
|
|
88
|
-
|
|
91
|
+
offset = key if key >= 0 else list_len + key
|
|
89
92
|
|
|
90
|
-
with self._conn:
|
|
91
93
|
cursor = self._conn.cursor()
|
|
92
94
|
# Find the rowid of the item to update
|
|
93
95
|
cursor.execute(
|
|
@@ -110,13 +112,13 @@ class ListManager[T]:
|
|
|
110
112
|
if not isinstance(key, int):
|
|
111
113
|
raise TypeError("List indices must be integers.")
|
|
112
114
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
115
|
+
with self._conn:
|
|
116
|
+
list_len = len(self)
|
|
117
|
+
if key < -list_len or key >= list_len:
|
|
118
|
+
raise IndexError("List index out of range.")
|
|
116
119
|
|
|
117
|
-
|
|
120
|
+
offset = key if key >= 0 else list_len + key
|
|
118
121
|
|
|
119
|
-
with self._conn:
|
|
120
122
|
cursor = self._conn.cursor()
|
|
121
123
|
# Find the rowid of the item to delete
|
|
122
124
|
cursor.execute(
|
|
@@ -206,20 +208,20 @@ class ListManager[T]:
|
|
|
206
208
|
|
|
207
209
|
def insert(self, index: int, value: T):
|
|
208
210
|
"""Inserts an item at a specific index."""
|
|
209
|
-
list_len = len(self)
|
|
210
|
-
if index <= 0:
|
|
211
|
-
self.prepend(value)
|
|
212
|
-
return
|
|
213
|
-
if index >= list_len:
|
|
214
|
-
self.push(value)
|
|
215
|
-
return
|
|
216
|
-
|
|
217
|
-
# Midpoint insertion for O(1) inserts
|
|
218
|
-
order_before = self._get_order_at_index(index - 1)
|
|
219
|
-
order_after = self._get_order_at_index(index)
|
|
220
|
-
new_order = order_before + (order_after - order_before) / 2.0
|
|
221
|
-
|
|
222
211
|
with self._conn:
|
|
212
|
+
list_len = len(self)
|
|
213
|
+
if index <= 0:
|
|
214
|
+
self.prepend(value)
|
|
215
|
+
return
|
|
216
|
+
if index >= list_len:
|
|
217
|
+
self.push(value)
|
|
218
|
+
return
|
|
219
|
+
|
|
220
|
+
# Midpoint insertion for O(1) inserts
|
|
221
|
+
order_before = self._get_order_at_index(index - 1)
|
|
222
|
+
order_after = self._get_order_at_index(index)
|
|
223
|
+
new_order = order_before + (order_after - order_before) / 2.0
|
|
224
|
+
|
|
223
225
|
self._conn.execute(
|
|
224
226
|
"INSERT INTO beaver_lists (list_name, item_order, item_value) VALUES (?, ?, ?)",
|
|
225
227
|
(self._name, new_order, self._serialize(value)),
|
|
@@ -4,13 +4,13 @@ beaver/channels.py,sha256=pCO8wFJAHdMzBLKvinI32L_XfU2B91H2qfsj1Tej-bc,9322
|
|
|
4
4
|
beaver/collections.py,sha256=Uz241TSs0xRABPYeKenDYmkbaM0PKfvcBX5j0lMzMMA,24306
|
|
5
5
|
beaver/core.py,sha256=t_UzpqcbF2U8BjmQ9aIWTvUzPuVuOLcPzTrZQ2htjn4,13706
|
|
6
6
|
beaver/dicts.py,sha256=1BQ9A_cMkJ7l5ayWbDG-4Wi3WtQ-9BKd7Wj_CB7dGlU,5410
|
|
7
|
-
beaver/lists.py,sha256=
|
|
7
|
+
beaver/lists.py,sha256=Q7xjyReBWFg47nBrXbt09GvBJkEmXvpW9ptL9xCnXC8,9946
|
|
8
8
|
beaver/logs.py,sha256=mlJizZU0emlqLwuNeBJSPlict35Vyi35L4eIl5orv-M,9673
|
|
9
9
|
beaver/queues.py,sha256=IQoeNhcYrVZTuH_4bWhtiEa-EYbFx_2iVKkR254XPnE,5953
|
|
10
10
|
beaver/types.py,sha256=65rDdj97EegghEkKCNjI67bPYtTTI_jyB-leHdIypx4,1249
|
|
11
11
|
beaver/vectors.py,sha256=j7RL2Y_xMAF2tPTi6E2LdJqZerSQXlnEQJOGZkefTsA,18358
|
|
12
|
-
beaver_db-0.16.
|
|
13
|
-
beaver_db-0.16.
|
|
14
|
-
beaver_db-0.16.
|
|
15
|
-
beaver_db-0.16.
|
|
16
|
-
beaver_db-0.16.
|
|
12
|
+
beaver_db-0.16.1.dist-info/licenses/LICENSE,sha256=1xrIY5JnMk_QDQzsqmVzPIIyCgZAkWCC8kF2Ddo1UT0,1071
|
|
13
|
+
beaver_db-0.16.1.dist-info/METADATA,sha256=nbK4YyecWQiD7xmv4F5uKgRrV4OXRxkOVyGDuQjUHtY,17070
|
|
14
|
+
beaver_db-0.16.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
15
|
+
beaver_db-0.16.1.dist-info/top_level.txt,sha256=FxA4XnX5Qm5VudEXCduFriqi4dQmDWpQ64d7g69VQKI,7
|
|
16
|
+
beaver_db-0.16.1.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|