bool-hybrid-array 9.10.13__py3-none-any.whl → 9.10.15__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.
- bool_hybrid_array/__init__.py +2 -1
- bool_hybrid_array/int_array/__init__.py +21 -59
- {bool_hybrid_array-9.10.13.dist-info → bool_hybrid_array-9.10.15.dist-info}/METADATA +3 -1
- bool_hybrid_array-9.10.15.dist-info/RECORD +10 -0
- bool_hybrid_array-9.10.13.dist-info/RECORD +0 -10
- {bool_hybrid_array-9.10.13.dist-info → bool_hybrid_array-9.10.15.dist-info}/WHEEL +0 -0
- {bool_hybrid_array-9.10.13.dist-info → bool_hybrid_array-9.10.15.dist-info}/licenses/LICENSE +0 -0
- {bool_hybrid_array-9.10.13.dist-info → bool_hybrid_array-9.10.15.dist-info}/top_level.txt +0 -0
bool_hybrid_array/__init__.py
CHANGED
|
@@ -3,7 +3,7 @@ from types import ModuleType
|
|
|
3
3
|
from . import core
|
|
4
4
|
from .core import __builtins__,builtins
|
|
5
5
|
from . import int_array
|
|
6
|
-
__version__ = "9.10.
|
|
6
|
+
__version__ = "9.10.15"
|
|
7
7
|
public_objects = []
|
|
8
8
|
for name in dir(core):
|
|
9
9
|
if not name.startswith("_"):
|
|
@@ -17,6 +17,7 @@ globals().update({
|
|
|
17
17
|
})
|
|
18
18
|
try:
|
|
19
19
|
__dict__ = ProtectedBuiltinsDict(globals())
|
|
20
|
+
sys.modules[__name__+'.int_array'] = ProtectedBuiltinsDict(int_array.__dict__)
|
|
20
21
|
sys.modules[__name__] = ProtectedBuiltinsDict(globals().copy())
|
|
21
22
|
sys.modules[__name__].name = 'bool_hybrid_array'
|
|
22
23
|
core.__dict__ = ProtectedBuiltinsDict(core.__dict__)
|
|
@@ -8,8 +8,7 @@ class IntBitTag(BHA_Bool, metaclass=ResurrectMeta):
|
|
|
8
8
|
__repr__ = __str__
|
|
9
9
|
|
|
10
10
|
class IntHybridArray(BoolHybridArray):
|
|
11
|
-
def __init__(self, int_array: list[int], bit_length: int = 8
|
|
12
|
-
self.Type = Type
|
|
11
|
+
def __init__(self, int_array: list[int], bit_length: int = 8):
|
|
13
12
|
self.bit_length = bit_length
|
|
14
13
|
bool_data = []
|
|
15
14
|
max_required_bits = 1
|
|
@@ -93,10 +92,9 @@ class IntHybridArray(BoolHybridArray):
|
|
|
93
92
|
if block_end > self.size:
|
|
94
93
|
raise IndexError("索引超出范围")
|
|
95
94
|
bit_chunk = [super().__getitem__(j) for j in range(block_start, block_end)]
|
|
96
|
-
return self.
|
|
95
|
+
return self.to_int(bit_chunk)
|
|
97
96
|
|
|
98
97
|
def __setitem__(self, key, value):
|
|
99
|
-
|
|
100
98
|
value = int(value)
|
|
101
99
|
if isinstance(key, slice):
|
|
102
100
|
start, stop, step = key.indices(len(self))
|
|
@@ -148,63 +146,20 @@ class IntHybridArray(BoolHybridArray):
|
|
|
148
146
|
bool_data = [sign_bit] + num_bits
|
|
149
147
|
for bit_idx in range(self.bit_length):
|
|
150
148
|
super().__setitem__(block_start + bit_idx, bool_data[bit_idx])
|
|
151
|
-
|
|
152
|
-
value = int(value)
|
|
153
|
-
index = index if index >= 0 else index + len(self)
|
|
154
|
-
if not (0 <= index <= len(self)):
|
|
155
|
-
raise IndexError("插入索引超出范围")
|
|
156
|
-
if value == 0:
|
|
157
|
-
required_bits = 1
|
|
158
|
-
else:
|
|
159
|
-
required_bits = 1 + abs(value).bit_length()
|
|
160
|
-
need_resize = required_bits > self.bit_length
|
|
161
|
-
old_data = list(self) if need_resize else None
|
|
162
|
-
if need_resize:
|
|
163
|
-
self.bit_length = required_bits
|
|
164
|
-
self.total_bits = 0
|
|
165
|
-
super().__init__(0, 0, False, IntBitTag, False)
|
|
166
|
-
for num in old_data[:index]:
|
|
167
|
-
self._add_single_num(num)
|
|
168
|
-
self._add_single_num(value)
|
|
169
|
-
for num in old_data[index:]:
|
|
170
|
-
self._add_single_num(num)
|
|
171
|
-
else:
|
|
172
|
-
insert_bit_start = index * self.bit_length
|
|
173
|
-
if value >= 0:
|
|
174
|
-
sign_bit = False
|
|
175
|
-
num_bits = [bool((num >> i) & 1) for i in range(self.bit_length - 1)]
|
|
176
|
-
else:
|
|
177
|
-
sign_bit = True
|
|
178
|
-
abs_num = abs(value)
|
|
179
|
-
num_bits = [not bool((abs_num >> i) & 1) for i in range(self.bit_length - 1)]
|
|
180
|
-
carry = 1
|
|
181
|
-
for j in range(len(num_bits)):
|
|
182
|
-
if carry:
|
|
183
|
-
num_bits[j] = not num_bits[j]
|
|
184
|
-
carry = 0 if num_bits[j] else 1
|
|
185
|
-
bool_data = [sign_bit] + num_bits
|
|
186
|
-
for i in range(self.bit_length):
|
|
187
|
-
super().insert(insert_bit_start + i, bool_data[i])
|
|
188
|
-
self.total_bits += self.bit_length
|
|
189
|
-
def append(self,v):
|
|
190
|
-
v = int(v)
|
|
191
|
-
req_bits = 1 + abs(v).bit_length() if v != 0 else 1
|
|
192
|
-
if req_bits > self.bit_length:
|
|
193
|
-
old_data = list(self)
|
|
194
|
-
self.bit_length = req_bits
|
|
195
|
-
self.clear()
|
|
196
|
-
self.extend(old_data)
|
|
197
|
-
self.total_bits += self.bit_length
|
|
198
|
-
self[-1] = v
|
|
149
|
+
|
|
199
150
|
def __iter__(self):
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
151
|
+
for i in range(0, self.total_bits, self.bit_length):
|
|
152
|
+
if i + self.bit_length > self.size:
|
|
153
|
+
break
|
|
154
|
+
bit_chunk = [super().__getitem__(j) for j in range(i, i + self.bit_length)]
|
|
155
|
+
yield self.to_int(bit_chunk)
|
|
156
|
+
|
|
205
157
|
def __str__(self):
|
|
206
158
|
return f"IntHybridArray([{', '.join(map(str, self))}])"
|
|
207
159
|
__repr__ = __str__
|
|
160
|
+
|
|
161
|
+
def __len__(self):
|
|
162
|
+
return self.total_bits // self.bit_length
|
|
208
163
|
def __delitem__(self, index: int = -1):
|
|
209
164
|
index = index if index >= 0 else index + len(self)
|
|
210
165
|
if not (0 <= index < len(self)):
|
|
@@ -215,8 +170,6 @@ class IntHybridArray(BoolHybridArray):
|
|
|
215
170
|
for _ in range(self.bit_length):
|
|
216
171
|
super().__delitem__(pop_bit_start)
|
|
217
172
|
self.total_bits -= self.bit_length
|
|
218
|
-
def __len__(self):
|
|
219
|
-
return self.total_bits // self.bit_length
|
|
220
173
|
def index(self, value):
|
|
221
174
|
value = int(value)
|
|
222
175
|
x = f"{value} 不在 IntHybridArray 中"
|
|
@@ -239,3 +192,12 @@ class IntHybridArray(BoolHybridArray):
|
|
|
239
192
|
if x != f"{value} 不在 IntHybridArray 中":
|
|
240
193
|
return x
|
|
241
194
|
raise ValueError(x)
|
|
195
|
+
def extend(self, iterable:Iterable) -> None:
|
|
196
|
+
if isinstance(iterable, (Iterator, Generator, map)):
|
|
197
|
+
iterable,copy = itertools.tee(iterable, 2)
|
|
198
|
+
len_ = sum(1 for _ in copy)
|
|
199
|
+
else:
|
|
200
|
+
len_ = len(iterable)
|
|
201
|
+
self.total_bits += len_*self.bit_length
|
|
202
|
+
for i,j in zip(range(len_),iterable):
|
|
203
|
+
self[-i-1] = j
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: bool-hybrid-array
|
|
3
|
-
Version: 9.10.
|
|
3
|
+
Version: 9.10.15
|
|
4
4
|
Summary: 一个高效的布尔数组(密集+稀疏混合存储,节省内存)
|
|
5
5
|
Home-page: https://github.com/BKsell/bool-hybrid-array
|
|
6
6
|
Author: 蔡靖杰
|
|
@@ -558,6 +558,8 @@ except OverflowError as e:
|
|
|
558
558
|
* **9.10.11**:修复NameError: name 'int_array' is not defined. Did you mean: 'bytearray'?的错误
|
|
559
559
|
* **9.10.12**:把find方法的返回值改为IntHybridArray
|
|
560
560
|
* **9.10.13**:给IntHybridArray新增多种列表操作
|
|
561
|
+
* **9.10.14**:修复IntHybridArray中因单个 0 导致所有数字位长被压缩到 1的问题
|
|
562
|
+
* **9.10.15**:修复IntHybridArray变成布尔数组的错误
|
|
561
563
|
|
|
562
564
|
|
|
563
565
|
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
bool_hybrid_array/__init__.py,sha256=m4L8YfX1-psmzeZZz1ksRmkj5wk7JbBcHYgiVnuAkYY,876
|
|
2
|
+
bool_hybrid_array/__main__.py,sha256=3MsUAXMj6Pe1EzP7YreuUePbXZeQvFSCnejnTeS42kU,8324
|
|
3
|
+
bool_hybrid_array/core.py,sha256=zp4jam5xC_CZvVVkmfT6fPAhBzf4-wspDnYuz0z49Ys,36578
|
|
4
|
+
bool_hybrid_array/秘密.md,sha256=Ii2NvXmv-Ktu04zJsGLcQZvlzT4gOatByE4B2wTK1Ks,48
|
|
5
|
+
bool_hybrid_array/int_array/__init__.py,sha256=EnjBonyL35YKDTtQ2g6tnrf4tTKEt5k-EAEbqLRuptI,8548
|
|
6
|
+
bool_hybrid_array-9.10.15.dist-info/licenses/LICENSE,sha256=Sg4rnGXkBDYkwJCWyxdWp5H60rhVAxpNvFh_l3JWZdY,1070
|
|
7
|
+
bool_hybrid_array-9.10.15.dist-info/METADATA,sha256=mS-KbHgJZm0VG_6P8nj4Ae3vlfuOeCk8YTQSao_bblE,22788
|
|
8
|
+
bool_hybrid_array-9.10.15.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
9
|
+
bool_hybrid_array-9.10.15.dist-info/top_level.txt,sha256=vk-TD77wuVQsN1rJ6uVWZX4sC_wya_WplRDwQKJoBZM,18
|
|
10
|
+
bool_hybrid_array-9.10.15.dist-info/RECORD,,
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
bool_hybrid_array/__init__.py,sha256=3Un6yG5b9peKnh8G5hXauOSf5NigC42BRA72cPQW8SU,793
|
|
2
|
-
bool_hybrid_array/__main__.py,sha256=3MsUAXMj6Pe1EzP7YreuUePbXZeQvFSCnejnTeS42kU,8324
|
|
3
|
-
bool_hybrid_array/core.py,sha256=zp4jam5xC_CZvVVkmfT6fPAhBzf4-wspDnYuz0z49Ys,36578
|
|
4
|
-
bool_hybrid_array/秘密.md,sha256=Ii2NvXmv-Ktu04zJsGLcQZvlzT4gOatByE4B2wTK1Ks,48
|
|
5
|
-
bool_hybrid_array/int_array/__init__.py,sha256=yZXd8I-kSKCGeRiMn8kfs9afRXWMmEmmoM9qME9Jv84,10173
|
|
6
|
-
bool_hybrid_array-9.10.13.dist-info/licenses/LICENSE,sha256=Sg4rnGXkBDYkwJCWyxdWp5H60rhVAxpNvFh_l3JWZdY,1070
|
|
7
|
-
bool_hybrid_array-9.10.13.dist-info/METADATA,sha256=C1Vgk-1lS4zLjtsTgDufdx-7DUur43Zc_PdOPlWV5ho,22623
|
|
8
|
-
bool_hybrid_array-9.10.13.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
9
|
-
bool_hybrid_array-9.10.13.dist-info/top_level.txt,sha256=vk-TD77wuVQsN1rJ6uVWZX4sC_wya_WplRDwQKJoBZM,18
|
|
10
|
-
bool_hybrid_array-9.10.13.dist-info/RECORD,,
|
|
File without changes
|
{bool_hybrid_array-9.10.13.dist-info → bool_hybrid_array-9.10.15.dist-info}/licenses/LICENSE
RENAMED
|
File without changes
|
|
File without changes
|