bool-hybrid-array 9.11.7__py3-none-any.whl → 9.11.9__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 +3 -2
- bool_hybrid_array/compile_core.pyd +0 -0
- bool_hybrid_array/core.c +75092 -0
- bool_hybrid_array/core.cp314-win_amd64.pyd +0 -0
- bool_hybrid_array/core.py +294 -56
- {bool_hybrid_array-9.11.7.dist-info → bool_hybrid_array-9.11.9.dist-info}/METADATA +3 -1
- bool_hybrid_array-9.11.9.dist-info/RECORD +13 -0
- bool_hybrid_array-9.11.7.dist-info/RECORD +0 -10
- {bool_hybrid_array-9.11.7.dist-info → bool_hybrid_array-9.11.9.dist-info}/WHEEL +0 -0
- {bool_hybrid_array-9.11.7.dist-info → bool_hybrid_array-9.11.9.dist-info}/licenses/LICENSE +0 -0
- {bool_hybrid_array-9.11.7.dist-info → bool_hybrid_array-9.11.9.dist-info}/top_level.txt +0 -0
|
Binary file
|
bool_hybrid_array/core.py
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
+
# cython: language_level=3, boundscheck=False, wraparound=False, initializedcheck=False
|
|
1
2
|
from __future__ import annotations
|
|
3
|
+
try:from mypy_extensions import mypyc_attr
|
|
4
|
+
except:
|
|
5
|
+
def mypyc_attr(*a,**k):
|
|
6
|
+
return lambda func:func
|
|
2
7
|
import builtins
|
|
3
8
|
from types import MappingProxyType
|
|
4
9
|
import array,bisect,numpy as np
|
|
@@ -7,24 +12,29 @@ import itertools,copy,sys,math,weakref,random,mmap,os
|
|
|
7
12
|
from functools import reduce
|
|
8
13
|
import operator,ctypes,gc,abc,types
|
|
9
14
|
from functools import lru_cache
|
|
10
|
-
from typing import
|
|
11
|
-
|
|
15
|
+
from typing import _GenericAlias
|
|
16
|
+
from typing import Callable, Union, Sequence, MutableSequence, Any, overload, Sized
|
|
17
|
+
from ctypes import *
|
|
18
|
+
try:
|
|
19
|
+
import msvcrt
|
|
20
|
+
except ImportError:
|
|
21
|
+
pass
|
|
22
|
+
hybrid_array_cache:list[tuple[Any]] = []
|
|
12
23
|
try:
|
|
13
24
|
msvcrt = ctypes.CDLL('msvcrt.dll')
|
|
14
25
|
memcpy = msvcrt.memcpy
|
|
15
26
|
except:
|
|
16
|
-
|
|
17
|
-
|
|
27
|
+
try:
|
|
28
|
+
libc = ctypes.CDLL('libc.so.6')
|
|
29
|
+
memcpy = libc.memcpy
|
|
30
|
+
except:
|
|
31
|
+
libc = ctypes.CDLL('libc.so')
|
|
32
|
+
memcpy = libc.memcpy
|
|
18
33
|
memcpy.argtypes = (ctypes.c_void_p, ctypes.c_void_p, ctypes.c_size_t)
|
|
19
34
|
memcpy.restype = ctypes.c_void_p
|
|
20
|
-
if 'UnionType' in types.__dict__:
|
|
21
|
-
class Union:
|
|
22
|
-
def __getitem__(self,*args):
|
|
23
|
-
return reduce(operator.or_, args)
|
|
24
|
-
Union = Union()
|
|
25
35
|
if 'GenericAlias' in types.__dict__:
|
|
26
36
|
_GenericAlias = types.GenericAlias
|
|
27
|
-
class ResurrectMeta(abc.ABCMeta,metaclass=abc.ABCMeta):
|
|
37
|
+
class ResurrectMeta(abc.ABCMeta,metaclass=abc.ABCMeta):# type: ignore
|
|
28
38
|
__module__ = 'bool_hybrid_array'
|
|
29
39
|
name = 'ResurrectMeta'
|
|
30
40
|
def __new__(cls, name, bases, namespace):
|
|
@@ -37,7 +47,7 @@ class ResurrectMeta(abc.ABCMeta,metaclass=abc.ABCMeta):
|
|
|
37
47
|
super_cls.__setattr__('name', name)
|
|
38
48
|
super_cls.__setattr__('bases', bases)
|
|
39
49
|
super_cls.__setattr__('namespace', namespace)
|
|
40
|
-
super_cls.__setattr__('original_dict', dict(obj.__dict__))
|
|
50
|
+
super_cls.__setattr__('original_dict', dict(obj.__dict__))# type: ignore[assignment]
|
|
41
51
|
try:del obj.original_dict["__abstractmethods__"]
|
|
42
52
|
except:pass
|
|
43
53
|
try:del obj.original_dict["_abc_impl"]
|
|
@@ -50,7 +60,7 @@ class ResurrectMeta(abc.ABCMeta,metaclass=abc.ABCMeta):
|
|
|
50
60
|
except:pass
|
|
51
61
|
try:del obj.original_dict['_abc_negative_cache_version']
|
|
52
62
|
except:pass
|
|
53
|
-
super_cls.__setattr__('original_dict', MappingProxyType(obj.original_dict))
|
|
63
|
+
super_cls.__setattr__('original_dict', MappingProxyType(obj.original_dict))# type: ignore[assignment]
|
|
54
64
|
return obj
|
|
55
65
|
@lru_cache
|
|
56
66
|
def __str__(cls):
|
|
@@ -62,14 +72,16 @@ class ResurrectMeta(abc.ABCMeta,metaclass=abc.ABCMeta):
|
|
|
62
72
|
return f'ResurrectMeta(cls = {cls},{name = },{bases = },{namespace = })'
|
|
63
73
|
return str(cls)
|
|
64
74
|
def __del__(cls):
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
75
|
+
try:
|
|
76
|
+
setattr(builtins,cls.name,cls)
|
|
77
|
+
if not sys.is_finalizing():
|
|
78
|
+
print(f'警告:禁止删除常变量:{cls}!')
|
|
79
|
+
raise TypeError(f'禁止删除常变量:{cls}')
|
|
80
|
+
except NameError:pass
|
|
69
81
|
def __hash__(cls):
|
|
70
82
|
return hash(cls.name+cls.__module__)
|
|
71
83
|
def __setattr__(cls,name,value):
|
|
72
|
-
if not hasattr(cls, 'x'):
|
|
84
|
+
if not hasattr(cls, 'x') or name.startswith('_'):
|
|
73
85
|
super().__setattr__(name,value)
|
|
74
86
|
return
|
|
75
87
|
if hasattr(cls, 'name') and cls.name == 'BHA_Bool' and repr(value) in {'T','F'} and name in {'T','F'}:
|
|
@@ -101,7 +113,7 @@ class ResurrectMeta(abc.ABCMeta,metaclass=abc.ABCMeta):
|
|
|
101
113
|
pass
|
|
102
114
|
original_dict = MappingProxyType(original_dict)
|
|
103
115
|
ResurrectMeta.__class__ = ResurrectMeta
|
|
104
|
-
class BHA_Function(metaclass=ResurrectMeta):
|
|
116
|
+
class BHA_Function(metaclass=ResurrectMeta):# type: ignore
|
|
105
117
|
def __init__(self,v):
|
|
106
118
|
self.data,self.module = v,__name__
|
|
107
119
|
def __call__(self,*a,**b):
|
|
@@ -121,14 +133,16 @@ def {name}({params}):
|
|
|
121
133
|
exec(func_code, globals(), local_namespace)
|
|
122
134
|
dynamic_func = local_namespace[name]
|
|
123
135
|
return cls(dynamic_func)
|
|
124
|
-
|
|
136
|
+
@mypyc_attr(native_class=False)
|
|
137
|
+
class BoolHybridArray(MutableSequence,Exception,metaclass=ResurrectMeta):# type: ignore
|
|
125
138
|
__module__ = 'bool_hybrid_array'
|
|
139
|
+
@mypyc_attr(native_class=False)
|
|
126
140
|
class _CompactBoolArray(Sequence,Exception):
|
|
127
141
|
def __init__(self, size: int):
|
|
128
142
|
self.size = size
|
|
129
143
|
self.n_uint8 = (size + 7) >> 3
|
|
130
|
-
self.data = np.zeros(self.n_uint8, dtype=np.uint8)
|
|
131
|
-
def __setitem__(self, index: int | slice, value):
|
|
144
|
+
self.data = np.zeros(self.n_uint8, dtype=np.uint8)# type: ignore[assignment]
|
|
145
|
+
def __setitem__(self, index: int | slice, value: Any):
|
|
132
146
|
ctypes_arr = self.data.ctypes.data_as(ctypes.POINTER(ctypes.c_ubyte))
|
|
133
147
|
if isinstance(index, slice):
|
|
134
148
|
start, stop, step = index.indices(self.size)
|
|
@@ -155,6 +169,7 @@ class BoolHybridArray(MutableSequence,Exception,metaclass=ResurrectMeta):
|
|
|
155
169
|
ctypes_arr[uint8_pos] &= ~(1 << bit_offset) & 0xFF
|
|
156
170
|
if value:
|
|
157
171
|
ctypes_arr[uint8_pos] |= (1 << bit_offset)
|
|
172
|
+
|
|
158
173
|
def __getitem__(self, index: int | slice) -> bool | list[bool]:
|
|
159
174
|
if isinstance(index, slice):
|
|
160
175
|
start, stop, step = index.indices(self.size)
|
|
@@ -180,7 +195,7 @@ class BoolHybridArray(MutableSequence,Exception,metaclass=ResurrectMeta):
|
|
|
180
195
|
new_instance = self.__class__(size=self.size)
|
|
181
196
|
new_instance.data = self.data.copy()
|
|
182
197
|
return new_instance
|
|
183
|
-
def __init__(self, split_index: int, size=None, is_sparse=False ,Type:Callable = None,hash_ = True) -> None:
|
|
198
|
+
def __init__(self, split_index: int, size=None, is_sparse=False ,Type:Callable = None,hash_:Any = True) -> None:
|
|
184
199
|
self.Type = Type if Type is not None else builtins.BHA_Bool
|
|
185
200
|
self.split_index = int(split_index)
|
|
186
201
|
self.size = size or 0
|
|
@@ -217,7 +232,7 @@ class BoolHybridArray(MutableSequence,Exception,metaclass=ResurrectMeta):
|
|
|
217
232
|
return func
|
|
218
233
|
def __hash__(self):
|
|
219
234
|
return self._cached_hash
|
|
220
|
-
def accessor(self, i: int, value:
|
|
235
|
+
def accessor(self, i: int, value: Any = None) -> Any:
|
|
221
236
|
def _get_sparse_info(index: int) -> tuple[int, bool]:
|
|
222
237
|
pos = bisect.bisect_left(self.large, index)
|
|
223
238
|
exists = pos < len(self.large) and self.large[pos] == index
|
|
@@ -241,7 +256,12 @@ class BoolHybridArray(MutableSequence,Exception,metaclass=ResurrectMeta):
|
|
|
241
256
|
if pos < len(self.large):
|
|
242
257
|
del self.large[pos]
|
|
243
258
|
return None
|
|
244
|
-
|
|
259
|
+
@overload
|
|
260
|
+
def __getitem__(self, idx: int, /) -> Any: ...
|
|
261
|
+
@overload
|
|
262
|
+
def __getitem__(self, idx: slice, /) -> list: ...
|
|
263
|
+
|
|
264
|
+
def __getitem__(self, key:int|slice = -1,/) -> Any:
|
|
245
265
|
if isinstance(key, slice):
|
|
246
266
|
start, stop, step = key.indices(self.size)
|
|
247
267
|
return BoolHybridArr((self[i] for i in range(start, stop, step)),hash_ = self.hash_)
|
|
@@ -249,7 +269,7 @@ class BoolHybridArray(MutableSequence,Exception,metaclass=ResurrectMeta):
|
|
|
249
269
|
if 0 <= key < self.size:
|
|
250
270
|
return self.Type(self.accessor(key))
|
|
251
271
|
raise IndexError("索引超出范围")
|
|
252
|
-
def __setitem__(self, key: int | slice, value) -> None:
|
|
272
|
+
def __setitem__(self, key: int | slice, value:Any) -> None:
|
|
253
273
|
if isinstance(key, int):
|
|
254
274
|
adjusted_key = key if key >= 0 else key + self.size
|
|
255
275
|
if not (0 <= adjusted_key < self.size):
|
|
@@ -284,15 +304,23 @@ class BoolHybridArray(MutableSequence,Exception,metaclass=ResurrectMeta):
|
|
|
284
304
|
def __repr__(self) -> str:
|
|
285
305
|
return(f"BoolHybridArray(split_index={self.split_index}, size={self.size}, "
|
|
286
306
|
+f"is_sparse={self.is_sparse}, small_len={len(self.small)}, large_len={len(self.large)})")
|
|
287
|
-
|
|
307
|
+
@overload
|
|
308
|
+
def __delitem__(self, key: int, /) -> None: ...
|
|
309
|
+
@overload
|
|
310
|
+
def __delitem__(self, key: slice, /) -> None: ...
|
|
311
|
+
|
|
312
|
+
def __delitem__(self, key: int|slice = -1,/) -> None:
|
|
288
313
|
key = key if key >= 0 else key + self.size
|
|
314
|
+
if isinstance(key, slice):
|
|
315
|
+
start, stop, step = key.indices(self.size)
|
|
316
|
+
for i in range(start,stop,step):del self[i]
|
|
289
317
|
if not (0 <= key < self.size):
|
|
290
318
|
raise IndexError(f"索引 {key} 超出范围 [0, {self.size})")
|
|
291
319
|
if key <= self.split_index:
|
|
292
320
|
if key >= len(self.small):
|
|
293
321
|
raise IndexError(f"小索引 {key} 超出small数组范围(长度{len(self.small)})")
|
|
294
|
-
self.small = np.delete(self.small, key)
|
|
295
|
-
self.small = np.append(self.small, not self.is_sparse)
|
|
322
|
+
self.small = np.delete(self.small, key)# type: ignore[assignment]
|
|
323
|
+
self.small = np.append(self.small, not self.is_sparse)# type: ignore[assignment]
|
|
296
324
|
self.split_index -= min(self.split_index, len(self.small) - 1)
|
|
297
325
|
else:
|
|
298
326
|
pos = bisect.bisect_left(self.large, key)
|
|
@@ -307,7 +335,7 @@ class BoolHybridArray(MutableSequence,Exception,metaclass=ResurrectMeta):
|
|
|
307
335
|
def __reversed__(self):
|
|
308
336
|
if not self:return BHA_Iterator([])
|
|
309
337
|
return BHA_Iterator(map(self.__getitem__,range(-1,-1,-1)))
|
|
310
|
-
def insert(self, key: int, value:
|
|
338
|
+
def insert(self, key: int, value: Any) -> None:
|
|
311
339
|
value = bool(value)
|
|
312
340
|
key = key if key >= 0 else key + self.size
|
|
313
341
|
key = max(0, min(key, self.size))
|
|
@@ -318,7 +346,7 @@ class BoolHybridArray(MutableSequence,Exception,metaclass=ResurrectMeta):
|
|
|
318
346
|
(0, key - len(self.small) + 1),
|
|
319
347
|
constant_values=not self.is_sparse
|
|
320
348
|
)
|
|
321
|
-
self.small = np.insert(self.small, key, value)
|
|
349
|
+
self.small = np.insert(self.small, key, value)# type: ignore[assignment]
|
|
322
350
|
self.split_index = min(self.split_index + 1, len(self.small) - 1)
|
|
323
351
|
else:
|
|
324
352
|
pos = bisect.bisect_left(self.large, key)
|
|
@@ -334,7 +362,7 @@ class BoolHybridArray(MutableSequence,Exception,metaclass=ResurrectMeta):
|
|
|
334
362
|
return BHA_Iterator(map(self.__getitem__,range(self.size)))
|
|
335
363
|
def __next__(self):
|
|
336
364
|
return next(self.generator)
|
|
337
|
-
def __contains__(self, value) -> bool:
|
|
365
|
+
def __contains__(self, value:Any) -> bool:
|
|
338
366
|
if not isinstance(value, (bool,np.bool_,self.Type,BHA_bool)):return False
|
|
339
367
|
if not self.size:return False
|
|
340
368
|
for i in range(10):
|
|
@@ -348,9 +376,9 @@ class BoolHybridArray(MutableSequence,Exception,metaclass=ResurrectMeta):
|
|
|
348
376
|
def __bool__(self) -> bool:
|
|
349
377
|
return bool(self.size)
|
|
350
378
|
def __any__(self):
|
|
351
|
-
return T in self
|
|
379
|
+
return builtins.T in self
|
|
352
380
|
def __all__(self):
|
|
353
|
-
return F not in self
|
|
381
|
+
return builtins.F not in self
|
|
354
382
|
def __eq__(self, other) -> bool:
|
|
355
383
|
if not isinstance(other, (BoolHybridArray, list, tuple, np.ndarray, array.array)):
|
|
356
384
|
return False
|
|
@@ -413,8 +441,6 @@ class BoolHybridArray(MutableSequence,Exception,metaclass=ResurrectMeta):
|
|
|
413
441
|
arr += other
|
|
414
442
|
arr.optimize()
|
|
415
443
|
return arr
|
|
416
|
-
def __invert__(self) -> BoolHybridArray:
|
|
417
|
-
return BoolHybridArr(not val for val in self)
|
|
418
444
|
def __rand__(self, other) -> BoolHybridArray:
|
|
419
445
|
if type(other) == int:
|
|
420
446
|
other = bin(other)[2:]
|
|
@@ -535,7 +561,8 @@ class BoolHybridArray(MutableSequence,Exception,metaclass=ResurrectMeta):
|
|
|
535
561
|
def __reduce__(self):
|
|
536
562
|
return BoolHybridArr,(np.asarray(self),self.is_sparse,self.Type,self.hash_,),
|
|
537
563
|
dequeue = lambda self:self.pop(0)
|
|
538
|
-
|
|
564
|
+
@mypyc_attr(native_class=False)
|
|
565
|
+
class BoolHybridArr(BoolHybridArray,metaclass=ResurrectMeta):# type: ignore
|
|
539
566
|
__module__ = 'bool_hybrid_array'
|
|
540
567
|
def __new__(cls, lst: Iterable = (), is_sparse=None, Type = None, hash_ = True, split_index = None) -> BoolHybridArray:
|
|
541
568
|
a = isinstance(lst, (Iterator, Generator, map))
|
|
@@ -610,7 +637,8 @@ def FalsesArray(size, Type = None,hash_ = True):
|
|
|
610
637
|
split_index = int(split_index) if split_index < 150e+7*2 else int(145e+7*2)
|
|
611
638
|
return BoolHybridArray(split_index,size,True,Type = Type,hash_ = hash_)
|
|
612
639
|
Bool_Array = np.arange(2,dtype = np.uint8)
|
|
613
|
-
|
|
640
|
+
@mypyc_attr(native_class=False)
|
|
641
|
+
class BHA_bool(int,metaclass=ResurrectMeta):# type: ignore
|
|
614
642
|
__module__ = 'bool_hybrid_array'
|
|
615
643
|
def __new__(cls, value):
|
|
616
644
|
core_value = bool(value)
|
|
@@ -644,16 +672,14 @@ class BHA_bool(int,metaclass=ResurrectMeta):
|
|
|
644
672
|
def __len__(self):
|
|
645
673
|
raise TypeError("'BHA_bool' object has no attribute '__len__'")
|
|
646
674
|
__rand__,__ror__,__rxor__ = __and__,__or__,__xor__
|
|
647
|
-
|
|
675
|
+
@mypyc_attr(native_class=False)
|
|
676
|
+
class BHA_Bool(BHA_bool,metaclass=ResurrectMeta):# type: ignore
|
|
648
677
|
__module__ = 'bool_hybrid_array'
|
|
649
678
|
@lru_cache
|
|
650
679
|
def __new__(cls,v):
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
builtins.T,builtins.F = BHA_Bool.T,BHA_Bool.F
|
|
655
|
-
return BHA_Bool.T if v else BHA_Bool.F
|
|
656
|
-
class BHA_List(list,metaclass=ResurrectMeta):
|
|
680
|
+
return builtins.T if v else builtins.F
|
|
681
|
+
@mypyc_attr(native_class=False)
|
|
682
|
+
class BHA_List(list,metaclass=ResurrectMeta):# type: ignore
|
|
657
683
|
__module__ = 'bool_hybrid_array'
|
|
658
684
|
def __init__(self,arr):
|
|
659
685
|
def Temp(v):
|
|
@@ -717,7 +743,8 @@ class BHA_List(list,metaclass=ResurrectMeta):
|
|
|
717
743
|
def to_ascii_art(self, width=20):
|
|
718
744
|
art = '\n'.join([' '.join(['■' if j else ' ' for j in i]) for i in self])
|
|
719
745
|
return art
|
|
720
|
-
|
|
746
|
+
@mypyc_attr(native_class=False)
|
|
747
|
+
class BHA_Iterator(Iterator,metaclass=ResurrectMeta):# type: ignore
|
|
721
748
|
__module__ = 'bool_hybrid_array'
|
|
722
749
|
def __init__(self,data):
|
|
723
750
|
self.data,self.copy_data = itertools.tee(iter(data),2)
|
|
@@ -738,12 +765,13 @@ class BHA_Iterator(Iterator,metaclass=ResurrectMeta):
|
|
|
738
765
|
arr = np.fromiter(self, dtype=dtype)
|
|
739
766
|
return arr.copy() if copy else arr.view()
|
|
740
767
|
__rand__,__ror__,__rxor__ = __and__,__or__,__xor__
|
|
741
|
-
|
|
768
|
+
@mypyc_attr(native_class=False)
|
|
769
|
+
class ProtectedBuiltinsDict(dict,metaclass=ResurrectMeta):# type: ignore
|
|
742
770
|
def __init__(self, *args, protected_names = ("T", "F", "BHA_Bool", "BHA_List", "BoolHybridArray", "BoolHybridArr",
|
|
743
771
|
"TruesArray", "FalsesArray", "ProtectedBuiltinsDict", "builtins",
|
|
744
772
|
"__builtins__", "__dict__","ResurrectMeta","math",
|
|
745
773
|
"np","protected_names","BHA_Function",
|
|
746
|
-
"__class__","Ask_BHA","Create_BHA","Ask_arr","numba_opt","bool_hybrid_array"),
|
|
774
|
+
"__class__","Ask_BHA","Create_BHA","Ask_arr","numba_opt","bool_hybrid_array","BHA_Queue","cin","cout","endl"),
|
|
747
775
|
name = 'builtins', **kwargs):
|
|
748
776
|
super().__init__(*args, **kwargs)
|
|
749
777
|
if name == 'builtins':
|
|
@@ -838,7 +866,7 @@ def Ask_BHA(path):
|
|
|
838
866
|
memcpy(arr.buffer_info()[0], bit_stream, total_len),arr)[-1]
|
|
839
867
|
if(n := int(x, base=16),
|
|
840
868
|
lead_zero := len(x) - len(x.lstrip('0')),
|
|
841
|
-
total_len := lead_zero +
|
|
869
|
+
total_len := lead_zero + n.bit_length())
|
|
842
870
|
else array.array('B'))
|
|
843
871
|
temp = BHA_List(map(temp2,temp))
|
|
844
872
|
if len(temp) == 1:
|
|
@@ -854,7 +882,8 @@ class BHA_Queue:
|
|
|
854
882
|
def enqueue(self,v):
|
|
855
883
|
self.a.push(v)
|
|
856
884
|
def dequeue(self):
|
|
857
|
-
if self.b:
|
|
885
|
+
if self.b:
|
|
886
|
+
return self.b.pop()
|
|
858
887
|
elif self.a:
|
|
859
888
|
tmp = BoolHybridArr(reversed(self.a))
|
|
860
889
|
self.b.split_index,self.b.large,self.b.small,self.b.is_sparse = tmp.split_index,tmp.large,tmp.small,tmp.is_sparse
|
|
@@ -886,7 +915,7 @@ def Create_BHA(path,arr):
|
|
|
886
915
|
mm[:] = temp
|
|
887
916
|
mm.flush()
|
|
888
917
|
def numba_opt():
|
|
889
|
-
import numba
|
|
918
|
+
import numba # type: ignore
|
|
890
919
|
sig = numba.types.Union([
|
|
891
920
|
numba.types.intp(
|
|
892
921
|
numba.types.Array(numba.types.uint32, 1, 'C'),
|
|
@@ -909,6 +938,215 @@ def numba_opt():
|
|
|
909
938
|
])
|
|
910
939
|
bisect.bisect_left = numba.njit(sig, cache=True)(bisect.bisect_left)
|
|
911
940
|
bisect.bisect_right = numba.njit(sig, cache=True)(bisect.bisect_right)
|
|
941
|
+
class InPutObject:
|
|
942
|
+
def __init__(self):
|
|
943
|
+
self._stdout = sys.stdout
|
|
944
|
+
if sys.platform == "win32":
|
|
945
|
+
self._get_char = lambda: ord(msvcrt.getche())
|
|
946
|
+
self.backch = " \b"
|
|
947
|
+
else:
|
|
948
|
+
libc_path = "libc.so.6" if sys.platform == "linux" else "libSystem.B.dylib"
|
|
949
|
+
self.libc = ctypes.cdll.LoadLibrary(libc_path)
|
|
950
|
+
self._get_char = lambda:(c:=ord(self.libc.getchar()),
|
|
951
|
+
self._stdout.write(chr(c)),self._stdout.flush())[0]
|
|
952
|
+
self.backch = "\b \b"
|
|
953
|
+
self._whitespace = {ord('\n'), ord('\t'), ord(' '), 0, ord("\r")}
|
|
954
|
+
self.getchar = self._get_char
|
|
955
|
+
self._buf = []
|
|
956
|
+
|
|
957
|
+
def _read_char(self):
|
|
958
|
+
while True:
|
|
959
|
+
if self._buf:char = self._buf.pop(0)
|
|
960
|
+
else:char = self._get_char()
|
|
961
|
+
if char in self._whitespace or char == -1:
|
|
962
|
+
continue
|
|
963
|
+
return char
|
|
964
|
+
|
|
965
|
+
def _parse_int(self):
|
|
966
|
+
chars = []
|
|
967
|
+
while True:
|
|
968
|
+
if self._buf:
|
|
969
|
+
char = self._buf.pop(0)
|
|
970
|
+
else:
|
|
971
|
+
char = self._get_char()
|
|
972
|
+
if char in self._whitespace or char == -1:
|
|
973
|
+
break
|
|
974
|
+
if char == 8:
|
|
975
|
+
sys.stdout.write(self.backch)
|
|
976
|
+
sys.stdout.flush()
|
|
977
|
+
try:
|
|
978
|
+
chars.pop()
|
|
979
|
+
except:
|
|
980
|
+
pass
|
|
981
|
+
continue
|
|
982
|
+
elif chr(char) not in '+-0123456789':
|
|
983
|
+
self._buf.append(char)
|
|
984
|
+
break
|
|
985
|
+
else:
|
|
986
|
+
chars.append(chr(char))
|
|
987
|
+
return ''.join(chars) if chars else '0'
|
|
988
|
+
|
|
989
|
+
def _parse_float(self):
|
|
990
|
+
chars = []
|
|
991
|
+
while True:
|
|
992
|
+
if self._buf:
|
|
993
|
+
char = self._buf.pop(0)
|
|
994
|
+
else:
|
|
995
|
+
char = self._get_char()
|
|
996
|
+
if char in self._whitespace or char == -1:
|
|
997
|
+
break
|
|
998
|
+
if char == 8:
|
|
999
|
+
sys.stdout.write(self.backch)
|
|
1000
|
+
sys.stdout.flush()
|
|
1001
|
+
try:
|
|
1002
|
+
chars.pop()
|
|
1003
|
+
except:
|
|
1004
|
+
pass
|
|
1005
|
+
continue
|
|
1006
|
+
elif chr(char) not in '+-0123456789.eE':
|
|
1007
|
+
self._buf.append(char)
|
|
1008
|
+
break
|
|
1009
|
+
chars.append(chr(char))
|
|
1010
|
+
return ''.join(chars) if chars else '0.0'
|
|
1011
|
+
|
|
1012
|
+
def _parse_complex(self):
|
|
1013
|
+
chars = []
|
|
1014
|
+
while True:
|
|
1015
|
+
if self._buf:
|
|
1016
|
+
char = self._buf.pop(0)
|
|
1017
|
+
else:
|
|
1018
|
+
char = self._get_char()
|
|
1019
|
+
if char in self._whitespace or char == -1:
|
|
1020
|
+
break
|
|
1021
|
+
if char == 8:
|
|
1022
|
+
sys.stdout.write(self.backch)
|
|
1023
|
+
sys.stdout.flush()
|
|
1024
|
+
try:
|
|
1025
|
+
chars.pop()
|
|
1026
|
+
except:
|
|
1027
|
+
pass
|
|
1028
|
+
continue
|
|
1029
|
+
if chr(char) not in '+-0123456789.eEj':
|
|
1030
|
+
self._buf.append(char)
|
|
1031
|
+
break
|
|
1032
|
+
chars.append(chr(char))
|
|
1033
|
+
return ''.join(chars) if chars else '0+0j'
|
|
1034
|
+
|
|
1035
|
+
def _parse_char(self):
|
|
1036
|
+
char = self._read_char()
|
|
1037
|
+
return chr(char) if char not in self._whitespace and char != -1 else '\0'
|
|
1038
|
+
|
|
1039
|
+
def _parse_char_array(self, max_len=1024):
|
|
1040
|
+
chars = []
|
|
1041
|
+
count = 0
|
|
1042
|
+
while count < max_len - 1:
|
|
1043
|
+
char = self._get_char()
|
|
1044
|
+
if char == 8:
|
|
1045
|
+
sys.stdout.write(self.backch)
|
|
1046
|
+
sys.stdout.flush()
|
|
1047
|
+
try:
|
|
1048
|
+
chars.pop()
|
|
1049
|
+
except:
|
|
1050
|
+
pass
|
|
1051
|
+
continue
|
|
1052
|
+
if char in self._whitespace or char == -1:
|
|
1053
|
+
break
|
|
1054
|
+
chars.append(chr(char))
|
|
1055
|
+
count += 1
|
|
1056
|
+
return ''.join(chars)
|
|
1057
|
+
def _parse_ptr(self):
|
|
1058
|
+
chars = []
|
|
1059
|
+
while True:
|
|
1060
|
+
if self._buf:
|
|
1061
|
+
char = self._buf.pop(0)
|
|
1062
|
+
else:
|
|
1063
|
+
char = self._get_char()
|
|
1064
|
+
if char in self._whitespace or char == -1:
|
|
1065
|
+
break
|
|
1066
|
+
if char == 8:
|
|
1067
|
+
sys.stdout.write(self.backch)
|
|
1068
|
+
sys.stdout.flush()
|
|
1069
|
+
try:
|
|
1070
|
+
chars.pop()
|
|
1071
|
+
except:
|
|
1072
|
+
pass
|
|
1073
|
+
continue
|
|
1074
|
+
if chr(char) not in '0123456789abcdefABCDEFx':
|
|
1075
|
+
self._buf.append(char)
|
|
1076
|
+
break
|
|
1077
|
+
chars.append(chr(char))
|
|
1078
|
+
return ''.join(chars) if chars else '0'
|
|
1079
|
+
def __rshift__(self, target):
|
|
1080
|
+
if isinstance(target, ctypes._SimpleCData):
|
|
1081
|
+
target_type = type(target)
|
|
1082
|
+
if target_type == c_void_p:
|
|
1083
|
+
ptr_str = self._parse_ptr()
|
|
1084
|
+
if ptr_str.startswith('0x') or ptr_str.startswith('0X'):
|
|
1085
|
+
val = c_void_p(int(ptr_str, 16))
|
|
1086
|
+
else:
|
|
1087
|
+
val = c_void_p(int(ptr_str) if ptr_str.isdigit() else 0)
|
|
1088
|
+
elif target_type == c_char_p:
|
|
1089
|
+
str_val = self._parse_char_array()
|
|
1090
|
+
val = c_char_p(str_val.encode('utf-8'))
|
|
1091
|
+
ctypes.memmove(target, val, len(str_val.encode('utf-8')))
|
|
1092
|
+
elif target_type == c_wchar_p:
|
|
1093
|
+
str_val = self._parse_char_array()
|
|
1094
|
+
val = c_wchar_p(str_val)
|
|
1095
|
+
ctypes.memmove(target, val, len(str_val) * ctypes.sizeof(c_wchar))
|
|
1096
|
+
elif np.issubdtype(np.dtype(target_type), np.integer):
|
|
1097
|
+
val = target_type(int(self._parse_int()))
|
|
1098
|
+
elif np.issubdtype(np.dtype(target_type), np.floating):
|
|
1099
|
+
val = target_type(float(self._parse_float()))
|
|
1100
|
+
elif np.issubdtype(np.dtype(target_type), np.complexfloating):
|
|
1101
|
+
val = target_type(complex(self._parse_complex()))
|
|
1102
|
+
elif target_type == c_char:
|
|
1103
|
+
val = c_char(self._parse_char().encode('utf-8')[0])
|
|
1104
|
+
elif target_type == c_wchar:
|
|
1105
|
+
val = c_wchar(self._parse_char())
|
|
1106
|
+
else:
|
|
1107
|
+
raise TypeError(f"Unsupported ctypes type: {target_type}")
|
|
1108
|
+
if target_type not in (c_char_p, c_wchar_p):
|
|
1109
|
+
ctypes.memmove(byref(target), byref(val), sizeof(target))
|
|
1110
|
+
elif isinstance(target, (np.generic, np.ndarray)):
|
|
1111
|
+
if isinstance(target, np.generic) or target.ndim == 0:
|
|
1112
|
+
if np.issubdtype(target.dtype, np.integer):
|
|
1113
|
+
val = np.array(self._parse_int(), dtype=target.dtype)
|
|
1114
|
+
elif np.issubdtype(target.dtype, np.floating):
|
|
1115
|
+
val = np.array(self._parse_float(), dtype=target.dtype)
|
|
1116
|
+
elif np.issubdtype(target.dtype, np.complexfloating):
|
|
1117
|
+
val = np.array(self._parse_complex(), dtype=target.dtype)
|
|
1118
|
+
elif np.issubdtype(target.dtype, np.character):
|
|
1119
|
+
val = np.array(self._parse_char(), dtype=target.dtype)
|
|
1120
|
+
else:
|
|
1121
|
+
val = np.array(self._parse_int(), dtype=target.dtype)
|
|
1122
|
+
target[...] = val[()]
|
|
1123
|
+
else:
|
|
1124
|
+
for i in range(target.size):
|
|
1125
|
+
if np.issubdtype(target.dtype, np.integer):
|
|
1126
|
+
val = np.array(self._parse_int(), dtype=target.dtype)
|
|
1127
|
+
elif np.issubdtype(target.dtype, np.floating):
|
|
1128
|
+
val = np.array(self._parse_float(), dtype=target.dtype)
|
|
1129
|
+
elif np.issubdtype(target.dtype, np.complexfloating):
|
|
1130
|
+
val = np.array(self._parse_complex(), dtype=target.dtype)
|
|
1131
|
+
elif np.issubdtype(target.dtype, np.character):
|
|
1132
|
+
val = np.array(self._parse_char(), dtype=target.dtype)
|
|
1133
|
+
else:
|
|
1134
|
+
val = np.array(self._parse_int(), dtype=target.dtype)
|
|
1135
|
+
target.flat[i] = val[()]
|
|
1136
|
+
else:
|
|
1137
|
+
raise TypeError(f"Unsupported target type: {type(target)}")
|
|
1138
|
+
return self
|
|
1139
|
+
__str__ = lambda self:""
|
|
1140
|
+
__repr__ = lambda self:""
|
|
1141
|
+
class OutPutObject:
|
|
1142
|
+
def __lshift__(self, data):
|
|
1143
|
+
sys.stdout.write(str(data))
|
|
1144
|
+
return self
|
|
1145
|
+
__str__ = lambda self:""
|
|
1146
|
+
__repr__ = lambda self:""
|
|
1147
|
+
cin = InPutObject()
|
|
1148
|
+
cout = OutPutObject()
|
|
1149
|
+
endl = "\n"
|
|
912
1150
|
builtins.np = np
|
|
913
1151
|
builtins.T = BHA_bool(1)
|
|
914
1152
|
builtins.F = BHA_bool(0)
|
|
@@ -926,7 +1164,11 @@ builtins.BHA_Function = BHA_Function
|
|
|
926
1164
|
builtins.Ask_BHA = Ask_BHA
|
|
927
1165
|
builtins.Create_BHA = Create_BHA
|
|
928
1166
|
builtins.numba_opt = numba_opt
|
|
929
|
-
|
|
1167
|
+
builtins.cin = cin
|
|
1168
|
+
builtins.cout = cout
|
|
1169
|
+
builtins.endl = endl
|
|
1170
|
+
builtins.BHA_Queue = BHA_Queue
|
|
1171
|
+
Tid,Fid = id(builtins.T),id(builtins.F)
|
|
930
1172
|
original_id = builtins.id
|
|
931
1173
|
def fake_id(obj):
|
|
932
1174
|
if isinstance(obj, BHA_bool):return Tid if obj else Fid
|
|
@@ -936,8 +1178,4 @@ original_builtins_dict = builtins.__dict__.copy()
|
|
|
936
1178
|
__builtins__ = ProtectedBuiltinsDict(original_builtins_dict)
|
|
937
1179
|
builtins = __builtins__
|
|
938
1180
|
sys.modules['builtins'] = builtins
|
|
939
|
-
builtins.name = 'builtins'
|
|
940
|
-
try:
|
|
941
|
-
sys.flags.optimize = 2
|
|
942
|
-
except:
|
|
943
|
-
pass
|
|
1181
|
+
builtins.name = 'builtins'
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: bool-hybrid-array
|
|
3
|
-
Version: 9.11.
|
|
3
|
+
Version: 9.11.9
|
|
4
4
|
Summary: 一个高效的布尔数组(密集+稀疏混合存储,节省内存)
|
|
5
5
|
Home-page: https://github.com/BKsell/bool-hybrid-array
|
|
6
6
|
Author: 蔡靖杰
|
|
@@ -613,6 +613,8 @@ print(f"出队2个元素后: {q}") # 输出:BHA_Queue([T,T,F,T,F])
|
|
|
613
613
|
* **9.11.5**:新增BHA_Queue双栈实现队列
|
|
614
614
|
* **9.11.6**:修复从9.11.3版本开始cpython用户无法安装bool-hybrid-array包的问题
|
|
615
615
|
* **9.11.7**:修复TypeError: 'map' object is not reversible的错误
|
|
616
|
+
* **9.11.8**:增加了Windows系统Python3.14的C扩展优化
|
|
617
|
+
* **9.11.9**:修复BHA_Queue的bug,新增cin和cout(使用方式:a = ctypes.c_int();cin >> a;cout << a)
|
|
616
618
|
|
|
617
619
|
|
|
618
620
|
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
bool_hybrid_array/__init__.py,sha256=QGalf9IbiqJSBW7wmbpduG333dmkQISsLMeQja-qtSg,1077
|
|
2
|
+
bool_hybrid_array/__main__.py,sha256=pjoWN4Noa_K44fqQPqp8H-diKSDf0Da8hdWFgvWUigQ,9083
|
|
3
|
+
bool_hybrid_array/compile_core.pyd,sha256=lriymUZtvs_ryeGM_K8gM33iCIfxRH5Zr5GPKhuNCtw,555520
|
|
4
|
+
bool_hybrid_array/core.c,sha256=VN0qsWCaJc0lEz6zHt7AFJsUcTieM5hkNtSeKh4ilIs,3616205
|
|
5
|
+
bool_hybrid_array/core.cp314-win_amd64.pyd,sha256=bAIpe0dUTBNMVbIDlZoBdtLsN7TmzaOo2KcY16BEvYU,633856
|
|
6
|
+
bool_hybrid_array/core.py,sha256=A1Lwn91T9N9-BhRBDIKJjVzvBVS036Mnaal3bfXN4To,50424
|
|
7
|
+
bool_hybrid_array/秘密.md,sha256=Ii2NvXmv-Ktu04zJsGLcQZvlzT4gOatByE4B2wTK1Ks,48
|
|
8
|
+
bool_hybrid_array/int_array/__init__.py,sha256=HPBdZu5qlXaRI4n_oK6WhnG4ml8H-FP1G44igVxPJIA,6225
|
|
9
|
+
bool_hybrid_array-9.11.9.dist-info/licenses/LICENSE,sha256=Sg4rnGXkBDYkwJCWyxdWp5H60rhVAxpNvFh_l3JWZdY,1070
|
|
10
|
+
bool_hybrid_array-9.11.9.dist-info/METADATA,sha256=8aIKi87Xbs3_J6hkpDGIjFXhE9GiVB2qH2-hJJJXJ7Y,26038
|
|
11
|
+
bool_hybrid_array-9.11.9.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
12
|
+
bool_hybrid_array-9.11.9.dist-info/top_level.txt,sha256=vk-TD77wuVQsN1rJ6uVWZX4sC_wya_WplRDwQKJoBZM,18
|
|
13
|
+
bool_hybrid_array-9.11.9.dist-info/RECORD,,
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
bool_hybrid_array/__init__.py,sha256=MvnpVFUFs0Dtf69ZsTguNfXP2k1PHhR2e9Hwsz6weR4,1039
|
|
2
|
-
bool_hybrid_array/__main__.py,sha256=pjoWN4Noa_K44fqQPqp8H-diKSDf0Da8hdWFgvWUigQ,9083
|
|
3
|
-
bool_hybrid_array/core.py,sha256=QlAhD8TSRIym76ZjtfYdLsaqtz3Es_dYT754RMQoUoY,40854
|
|
4
|
-
bool_hybrid_array/秘密.md,sha256=Ii2NvXmv-Ktu04zJsGLcQZvlzT4gOatByE4B2wTK1Ks,48
|
|
5
|
-
bool_hybrid_array/int_array/__init__.py,sha256=HPBdZu5qlXaRI4n_oK6WhnG4ml8H-FP1G44igVxPJIA,6225
|
|
6
|
-
bool_hybrid_array-9.11.7.dist-info/licenses/LICENSE,sha256=Sg4rnGXkBDYkwJCWyxdWp5H60rhVAxpNvFh_l3JWZdY,1070
|
|
7
|
-
bool_hybrid_array-9.11.7.dist-info/METADATA,sha256=Dsk-thuJ8y4ikh_JK2Ckht-ar5WhiwJow68-mLH_zL0,25858
|
|
8
|
-
bool_hybrid_array-9.11.7.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
9
|
-
bool_hybrid_array-9.11.7.dist-info/top_level.txt,sha256=vk-TD77wuVQsN1rJ6uVWZX4sC_wya_WplRDwQKJoBZM,18
|
|
10
|
-
bool_hybrid_array-9.11.7.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|