bool-hybrid-array 9.10.12__py3-none-any.whl → 9.10.14__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 +103 -23
- {bool_hybrid_array-9.10.12.dist-info → bool_hybrid_array-9.10.14.dist-info}/METADATA +3 -1
- bool_hybrid_array-9.10.14.dist-info/RECORD +10 -0
- bool_hybrid_array-9.10.12.dist-info/RECORD +0 -10
- {bool_hybrid_array-9.10.12.dist-info → bool_hybrid_array-9.10.14.dist-info}/WHEEL +0 -0
- {bool_hybrid_array-9.10.12.dist-info → bool_hybrid_array-9.10.14.dist-info}/licenses/LICENSE +0 -0
- {bool_hybrid_array-9.10.12.dist-info → bool_hybrid_array-9.10.14.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.14"
|
|
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,20 +8,21 @@ 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):
|
|
11
|
+
def __init__(self, int_array: list[int], bit_length: int = 8, Type = int):
|
|
12
|
+
self.Type = Type
|
|
12
13
|
self.bit_length = bit_length
|
|
13
14
|
bool_data = []
|
|
14
15
|
max_required_bits = 1
|
|
15
16
|
for num in int_array:
|
|
16
17
|
if num == 0:
|
|
17
|
-
required_bits =
|
|
18
|
+
required_bits = 2
|
|
18
19
|
else:
|
|
19
20
|
abs_num = abs(num)
|
|
20
21
|
num_bits_needed = abs_num.bit_length()
|
|
21
22
|
required_bits = 1 + num_bits_needed
|
|
22
23
|
if required_bits > max_required_bits:
|
|
23
24
|
max_required_bits = required_bits
|
|
24
|
-
self.bit_length = max_required_bits
|
|
25
|
+
self.bit_length = max(max_required_bits, 2)
|
|
25
26
|
for num in int_array:
|
|
26
27
|
if num >= 0:
|
|
27
28
|
sign_bit = False
|
|
@@ -40,15 +41,10 @@ class IntHybridArray(BoolHybridArray):
|
|
|
40
41
|
self.total_bits = len(bool_data)
|
|
41
42
|
super().__init__(0, self.total_bits, False, IntBitTag, False)
|
|
42
43
|
for idx in range(self.total_bits):
|
|
43
|
-
|
|
44
|
-
super().__setitem__(idx, bool_data[idx])
|
|
45
|
-
else:
|
|
46
|
-
super().append(bool_data[idx])
|
|
44
|
+
super().__setitem__(idx, bool_data[idx])
|
|
47
45
|
for i in range(0, self.total_bits, self.bit_length):
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
bit_tag.is_sign_bit = True
|
|
51
|
-
|
|
46
|
+
bit_tag = super().__getitem__(i)
|
|
47
|
+
bit_tag.is_sign_bit = True
|
|
52
48
|
def to_int(self, bit_chunk):
|
|
53
49
|
sign_bit = bit_chunk[0].value
|
|
54
50
|
num_bits = [bit.value for bit in bit_chunk[1:]]
|
|
@@ -70,7 +66,6 @@ class IntHybridArray(BoolHybridArray):
|
|
|
70
66
|
num += (1 << j)
|
|
71
67
|
num = -num
|
|
72
68
|
return num
|
|
73
|
-
|
|
74
69
|
def __getitem__(self, key):
|
|
75
70
|
if isinstance(key, slice):
|
|
76
71
|
start, stop, step = key.indices(len(self))
|
|
@@ -92,8 +87,7 @@ class IntHybridArray(BoolHybridArray):
|
|
|
92
87
|
if block_end > self.size:
|
|
93
88
|
raise IndexError("索引超出范围")
|
|
94
89
|
bit_chunk = [super().__getitem__(j) for j in range(block_start, block_end)]
|
|
95
|
-
return self.to_int(bit_chunk)
|
|
96
|
-
|
|
90
|
+
return self.Type(self.to_int(bit_chunk))
|
|
97
91
|
def __setitem__(self, key, value):
|
|
98
92
|
value = int(value)
|
|
99
93
|
if isinstance(key, slice):
|
|
@@ -146,17 +140,103 @@ class IntHybridArray(BoolHybridArray):
|
|
|
146
140
|
bool_data = [sign_bit] + num_bits
|
|
147
141
|
for bit_idx in range(self.bit_length):
|
|
148
142
|
super().__setitem__(block_start + bit_idx, bool_data[bit_idx])
|
|
149
|
-
|
|
143
|
+
def insert(self, index, value):
|
|
144
|
+
value = int(value)
|
|
145
|
+
index = index if index >= 0 else index + len(self)
|
|
146
|
+
if not (0 <= index <= len(self)):
|
|
147
|
+
raise IndexError("插入索引超出范围")
|
|
148
|
+
if value == 0:
|
|
149
|
+
required_bits = 1
|
|
150
|
+
else:
|
|
151
|
+
required_bits = 1 + abs(value).bit_length()
|
|
152
|
+
need_resize = required_bits > self.bit_length
|
|
153
|
+
old_data = list(self) if need_resize else None
|
|
154
|
+
if need_resize:
|
|
155
|
+
self.bit_length = required_bits
|
|
156
|
+
self.total_bits = 0
|
|
157
|
+
super().__init__(0, 0, False, IntBitTag, False)
|
|
158
|
+
for num in old_data[:index]:
|
|
159
|
+
self._add_single_num(num)
|
|
160
|
+
self._add_single_num(value)
|
|
161
|
+
for num in old_data[index:]:
|
|
162
|
+
self._add_single_num(num)
|
|
163
|
+
else:
|
|
164
|
+
insert_bit_start = index * self.bit_length
|
|
165
|
+
if value >= 0:
|
|
166
|
+
sign_bit = False
|
|
167
|
+
num_bits = [bool((num >> i) & 1) for i in range(self.bit_length - 1)]
|
|
168
|
+
else:
|
|
169
|
+
sign_bit = True
|
|
170
|
+
abs_num = abs(value)
|
|
171
|
+
num_bits = [not bool((abs_num >> i) & 1) for i in range(self.bit_length - 1)]
|
|
172
|
+
carry = 1
|
|
173
|
+
for j in range(len(num_bits)):
|
|
174
|
+
if carry:
|
|
175
|
+
num_bits[j] = not num_bits[j]
|
|
176
|
+
carry = 0 if num_bits[j] else 1
|
|
177
|
+
bool_data = [sign_bit] + num_bits
|
|
178
|
+
for i in range(self.bit_length):
|
|
179
|
+
super().insert(insert_bit_start + i, bool_data[i])
|
|
180
|
+
self.total_bits += self.bit_length
|
|
181
|
+
def append(self,v):
|
|
182
|
+
v = int(v)
|
|
183
|
+
req_bits = 1 + abs(v).bit_length() if v != 0 else 1
|
|
184
|
+
if req_bits > self.bit_length:
|
|
185
|
+
old_data = list(self)
|
|
186
|
+
self.bit_length = req_bits
|
|
187
|
+
self.clear()
|
|
188
|
+
self.extend(old_data)
|
|
189
|
+
self.total_bits += self.bit_length
|
|
190
|
+
self[-1] = v
|
|
150
191
|
def __iter__(self):
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
192
|
+
return BHA_Iterator(map(self.__getitem__,range(len(self))))
|
|
193
|
+
def clear(self):
|
|
194
|
+
self.total_bits = 0
|
|
195
|
+
super().__init__(0, 0, False, IntBitTag, False)
|
|
196
|
+
self.bit_length = 8
|
|
157
197
|
def __str__(self):
|
|
158
198
|
return f"IntHybridArray([{', '.join(map(str, self))}])"
|
|
159
199
|
__repr__ = __str__
|
|
160
|
-
|
|
200
|
+
def __delitem__(self, index: int = -1):
|
|
201
|
+
index = index if index >= 0 else index + len(self)
|
|
202
|
+
if not (0 <= index < len(self)):
|
|
203
|
+
raise IndexError("删除索引超出范围")
|
|
204
|
+
target_num = self[index]
|
|
205
|
+
pop_bit_start = index * self.bit_length
|
|
206
|
+
pop_bit_end = pop_bit_start + self.bit_length
|
|
207
|
+
for _ in range(self.bit_length):
|
|
208
|
+
super().__delitem__(pop_bit_start)
|
|
209
|
+
self.total_bits -= self.bit_length
|
|
161
210
|
def __len__(self):
|
|
162
|
-
return self.total_bits // self.bit_length
|
|
211
|
+
return self.total_bits // self.bit_length
|
|
212
|
+
def index(self, value):
|
|
213
|
+
value = int(value)
|
|
214
|
+
x = f"{value} 不在 IntHybridArray 中"
|
|
215
|
+
for idx in range(len(self)+2>>2):
|
|
216
|
+
if self[idx] == value:
|
|
217
|
+
return idx
|
|
218
|
+
elif self[-idx] == value:
|
|
219
|
+
x = len(self)-idx
|
|
220
|
+
if x != f"{value} 不在 IntHybridArray 中":
|
|
221
|
+
return x
|
|
222
|
+
raise ValueError(x)
|
|
223
|
+
def rindex(self, value):
|
|
224
|
+
value = int(value)
|
|
225
|
+
x = f"{value} 不在 IntHybridArray 中"
|
|
226
|
+
for idx in range(len(self)+2>>2):
|
|
227
|
+
if self[-idx] == value:
|
|
228
|
+
return -idx
|
|
229
|
+
elif self[idx] == value:
|
|
230
|
+
x = -(len(self)-idx)
|
|
231
|
+
if x != f"{value} 不在 IntHybridArray 中":
|
|
232
|
+
return x
|
|
233
|
+
raise ValueError(x)
|
|
234
|
+
def extend(self, iterable:Iterable) -> None:
|
|
235
|
+
if isinstance(iterable, (Iterator, Generator, map)):
|
|
236
|
+
iterable,copy = itertools.tee(iterable, 2)
|
|
237
|
+
len_ = sum(1 for _ in copy)
|
|
238
|
+
else:
|
|
239
|
+
len_ = len(iterable)
|
|
240
|
+
self.total_bits += len_*self.bit_length
|
|
241
|
+
for i,j in zip(range(len_),iterable):
|
|
242
|
+
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.14
|
|
4
4
|
Summary: 一个高效的布尔数组(密集+稀疏混合存储,节省内存)
|
|
5
5
|
Home-page: https://github.com/BKsell/bool-hybrid-array
|
|
6
6
|
Author: 蔡靖杰
|
|
@@ -557,6 +557,8 @@ except OverflowError as e:
|
|
|
557
557
|
* **9.10.10**:新增int_array模块
|
|
558
558
|
* **9.10.11**:修复NameError: name 'int_array' is not defined. Did you mean: 'bytearray'?的错误
|
|
559
559
|
* **9.10.12**:把find方法的返回值改为IntHybridArray
|
|
560
|
+
* **9.10.13**:给IntHybridArray新增多种列表操作
|
|
561
|
+
* **9.10.14**:修复IntHybridArray中因单个 0 导致所有数字位长被压缩到 1的问题
|
|
560
562
|
|
|
561
563
|
|
|
562
564
|
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
bool_hybrid_array/__init__.py,sha256=yvJ9gw9SQf3Q3EaRPL4D1JaBTgkg73VlPwkZvM0g_zM,872
|
|
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=_sDSu7-DXEObnElKBYGWnb0OrIBeaQ1tzgwl_d1fkwY,10412
|
|
6
|
+
bool_hybrid_array-9.10.14.dist-info/licenses/LICENSE,sha256=Sg4rnGXkBDYkwJCWyxdWp5H60rhVAxpNvFh_l3JWZdY,1070
|
|
7
|
+
bool_hybrid_array-9.10.14.dist-info/METADATA,sha256=28LDpkvNmNI91OcpIQ9T5I_c8DKQH53OP9Z27gNuB_w,22723
|
|
8
|
+
bool_hybrid_array-9.10.14.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
9
|
+
bool_hybrid_array-9.10.14.dist-info/top_level.txt,sha256=vk-TD77wuVQsN1rJ6uVWZX4sC_wya_WplRDwQKJoBZM,18
|
|
10
|
+
bool_hybrid_array-9.10.14.dist-info/RECORD,,
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
bool_hybrid_array/__init__.py,sha256=Thq_-DGCyTyuvYeII-C1y1SJc_FFbwR642B5R01VL6M,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=ZDZSAmaMvuzzxBuTn-LfZX9Ww8_lWpBO5pNGlDRvpKU,6896
|
|
6
|
-
bool_hybrid_array-9.10.12.dist-info/licenses/LICENSE,sha256=Sg4rnGXkBDYkwJCWyxdWp5H60rhVAxpNvFh_l3JWZdY,1070
|
|
7
|
-
bool_hybrid_array-9.10.12.dist-info/METADATA,sha256=aDxTkR9nwJjkon2Xstxv__SPMzDG3Eci0R5BQY85UHw,22564
|
|
8
|
-
bool_hybrid_array-9.10.12.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
9
|
-
bool_hybrid_array-9.10.12.dist-info/top_level.txt,sha256=vk-TD77wuVQsN1rJ6uVWZX4sC_wya_WplRDwQKJoBZM,18
|
|
10
|
-
bool_hybrid_array-9.10.12.dist-info/RECORD,,
|
|
File without changes
|
{bool_hybrid_array-9.10.12.dist-info → bool_hybrid_array-9.10.14.dist-info}/licenses/LICENSE
RENAMED
|
File without changes
|
|
File without changes
|