bool-hybrid-array 9.10.22__py3-none-any.whl → 9.11.0__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.
@@ -1,9 +1,11 @@
1
+ # -*- coding: utf-8 -*-
1
2
  import sys
2
3
  from types import ModuleType,FunctionType
3
4
  from . import core
4
5
  from .core import __builtins__,builtins
5
- from . import int_array
6
- __version__ = "9.10.22"
6
+ try:from . import int_array
7
+ except:pass
8
+ __version__ = "9.11.0"
7
9
  public_objects = []
8
10
  for name in dir(core):
9
11
  if not name.startswith("_"):
@@ -16,11 +18,11 @@ globals().update({
16
18
  for name in public_objects
17
19
  })
18
20
  try:
19
- __dict__ = ProtectedBuiltinsDict(globals())
20
- sys.modules[__name__+'.int_array'] = ProtectedBuiltinsDict(int_array.__dict__)
21
- sys.modules[__name__+'.core'] = ProtectedBuiltinsDict(core.__dict__)
22
21
  sys.modules[__name__] = ProtectedBuiltinsDict(globals())
23
- sys.modules[__name__].name = 'bool_hybrid_array'
22
+ sys.modules[__name__].name = __name__
23
+ sys.modules[__name__+'.core'] = ProtectedBuiltinsDict(core.__dict__,name = f'{__name__}.core')
24
+ __dict__ = ProtectedBuiltinsDict(globals())
25
+ sys.modules[__name__+'.int_array'] = ProtectedBuiltinsDict(int_array.__dict__,name = __name__+'.int_array')
24
26
  core.__dict__ = ProtectedBuiltinsDict(core.__dict__)
25
27
  except:
26
28
  pass
@@ -1,4 +1,8 @@
1
+ # -*- coding: utf-8 -*-
1
2
  from .__init__ import *
3
+ import io
4
+
5
+ sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8', errors='ignore')
2
6
 
3
7
  # 创建实例
4
8
 
bool_hybrid_array/core.py CHANGED
@@ -1,5 +1,6 @@
1
1
  from __future__ import annotations
2
2
  import builtins
3
+ from types import MappingProxyType
3
4
  import array,bisect,numpy as np
4
5
  from collections.abc import MutableSequence,Iterable,Generator,Iterator,Sequence
5
6
  import itertools,copy,sys,math,weakref,random,mmap,os
@@ -37,12 +38,23 @@ class ResurrectMeta(abc.ABCMeta,metaclass=abc.ABCMeta):
37
38
  super_cls.__setattr__('bases', bases)
38
39
  super_cls.__setattr__('namespace', namespace)
39
40
  super_cls.__setattr__('original_dict', dict(obj.__dict__))
40
- del obj.original_dict["__abstractmethods__"]
41
- del obj.original_dict["_abc_impl"]
41
+ try:del obj.original_dict["__abstractmethods__"]
42
+ except:pass
43
+ try:del obj.original_dict["_abc_impl"]
44
+ except:pass
45
+ try:del obj.original_dict['_abc_registry']
46
+ except:pass
47
+ try:del obj.original_dict['_abc_cache']
48
+ except:pass
49
+ try:del obj.original_dict['_abc_negative_cache']
50
+ except:pass
51
+ try:del obj.original_dict['_abc_negative_cache_version']
52
+ except:pass
53
+ super_cls.__setattr__('original_dict', MappingProxyType(obj.original_dict))
42
54
  return obj
43
55
  @lru_cache
44
56
  def __str__(cls):
45
- return super().__repr__()[8:][:-2]
57
+ return f'{cls.__module__}.{cls.name}'
46
58
  @lru_cache
47
59
  def __repr__(cls,detailed = False):
48
60
  if detailed:
@@ -87,6 +99,7 @@ class ResurrectMeta(abc.ABCMeta,metaclass=abc.ABCMeta):
87
99
  original_dict["__or__"] = __or__
88
100
  except:
89
101
  pass
102
+ original_dict = MappingProxyType(original_dict)
90
103
  ResurrectMeta.__class__ = ResurrectMeta
91
104
  class BHA_Function(metaclass=ResurrectMeta):
92
105
  def __init__(self,v):
@@ -711,11 +724,11 @@ class BHA_Iterator(Iterator,metaclass=ResurrectMeta):
711
724
  return arr.copy() if copy else arr.view()
712
725
  __rand__,__ror__,__rxor__ = __and__,__or__,__xor__
713
726
  class ProtectedBuiltinsDict(dict,metaclass=ResurrectMeta):
714
- def __init__(self, *args, protected_names = ["T", "F", "BHA_Bool", "BHA_List", "BoolHybridArray", "BoolHybridArr",
727
+ def __init__(self, *args, protected_names = ("T", "F", "BHA_Bool", "BHA_List", "BoolHybridArray", "BoolHybridArr",
715
728
  "TruesArray", "FalsesArray", "ProtectedBuiltinsDict", "builtins",
716
729
  "__builtins__", "__dict__","ResurrectMeta","math",
717
730
  "np","protected_names","BHA_Function",
718
- "__class__","Ask_BHA","Create_BHA","Ask_arr","numba_opt"],
731
+ "__class__","Ask_BHA","Create_BHA","Ask_arr","numba_opt"),
719
732
  name = 'builtins', **kwargs):
720
733
  super().__init__(*args, **kwargs)
721
734
  if name == 'builtins':
@@ -723,20 +736,23 @@ class ProtectedBuiltinsDict(dict,metaclass=ResurrectMeta):
723
736
  super().__setattr__('builtins',self)
724
737
  super().__setattr__('__builtins__',self)
725
738
  self.name = name
726
- self.protected_names = protected_names
739
+ super().__setattr__("protected_names",protected_names)
727
740
  def __setitem__(self, name, value):
728
- if name in ["T", "F"]:
729
- current_T = self.get("T")
730
- current_F = self.get("F")
731
- if isinstance(current_T, BHA_bool) and isinstance(current_F, BHA_bool):
732
- is_swap = (name == "T" and isinstance(value, BHA_bool) and value.value == current_F.value)or(name == "F" and isinstance(value, BHA_bool) and value.value == current_T.value)
733
- if is_swap:
734
- print(f"""警告:禁止交换内置常量 __{self.name}__["{name}"] __builtins__["{'F' if name == 'T' else 'T'}"]!""")
735
- raise AttributeError(f"""禁止交换内置常量 __{self.name}__["{name}"] 和 __{self.name}__["{'F' if name == 'T' else 'T'}"]""")
736
- if name in self.protected_names and name not in ["T", "F"]:
737
- print(f"警告:禁止修改内置常量 __{self.name}__['{name}']")
738
- raise AttributeError(f"禁止修改内置常量 __{self.name}__['{name}']")
739
- super().__setitem__(name, value)
741
+ if not hasattr(self,"protected_names"):super().__setitem__(name, value)
742
+ try:
743
+ if name in ["T", "F"]:
744
+ current_T = self.get("T")
745
+ current_F = self.get("F")
746
+ if isinstance(current_T, BHA_bool) and isinstance(current_F, BHA_bool):
747
+ is_swap = (name == "T" and isinstance(value, BHA_bool) and value.value == current_F.value)or(name == "F" and isinstance(value, BHA_bool) and value.value == current_T.value)
748
+ if is_swap:
749
+ print(f"""警告:禁止交换内置常量 __{self.name}__["{name}"] __builtins__["{'F' if name == 'T' else 'T'}"]!""")
750
+ raise AttributeError(f"""禁止交换内置常量 __{self.name}__["{name}"] 和 __{self.name}__["{'F' if name == 'T' else 'T'}"]""")
751
+ if name in self.protected_names and name not in ["T", "F"]:
752
+ print(f"警告:禁止修改内置常量 __{self.name}__['{name}']!")
753
+ raise AttributeError(f"禁止修改内置常量 __{self.name}__['{name}']")
754
+ except:pass
755
+ finally:super().__setitem__(name, value)
740
756
  def __delitem__(self, name):
741
757
  if name in self.protected_names:
742
758
  print(f"警告:禁止删除内置常量 __builtins__['{name}']!")
@@ -749,10 +765,12 @@ class ProtectedBuiltinsDict(dict,metaclass=ResurrectMeta):
749
765
  else:
750
766
  del self[name]
751
767
  def __getattr__(self, name):
752
- if name in self:
753
- return self[name]
754
- else:
755
- raise AttributeError(f"module 'builtins' has no attribute '{name}'")
768
+ try:
769
+ return super().__getattribute__(name)
770
+ except AttributeError:
771
+ if name in self:
772
+ return self[name]
773
+ raise AttributeError(f"module 'builtins' has no attribute '{name}'") from None
756
774
  def __setattr__(self,name,value):
757
775
  try:protected = self.protected_names
758
776
  except Exception:protected = self
@@ -1,7 +1,7 @@
1
+ # -*- coding: utf-8 -*-
1
2
  from __future__ import annotations
2
3
  from ..core import *
3
4
  import builtins
4
-
5
5
  class IntBitTag(BHA_bool, metaclass=ResurrectMeta):
6
6
  def __str__(self):
7
7
  return "'-1'" if (hasattr(self, 'is_sign_bit') and self.is_sign_bit and self) else "'1'" if self else "'0'"
@@ -80,7 +80,7 @@ class IntHybridArray(BoolHybridArray):
80
80
  block_end = block_start + self.bit_length
81
81
  if block_end > self.size:
82
82
  raise IndexError("索引超出范围")
83
- bit_chunk = [super().__getitem__(j) for j in range(block_start, block_end)]
83
+ bit_chunk = [super(self.__class__, self).__getitem__(j) for j in range(block_start, block_end)]
84
84
  num = self.to_int(bit_chunk)
85
85
  result.append(num)
86
86
  return IntHybridArray(result, self.bit_length)
@@ -91,7 +91,7 @@ class IntHybridArray(BoolHybridArray):
91
91
  block_end = block_start + self.bit_length
92
92
  if block_end > self.size:
93
93
  raise IndexError("索引超出范围")
94
- bit_chunk = [super().__getitem__(j) for j in range(block_start, block_end)]
94
+ bit_chunk = [super(self.__class__, self).__getitem__(j) for j in range(block_start, block_end)]
95
95
  return self.to_int(bit_chunk)
96
96
 
97
97
  def __setitem__(self, key, value):
@@ -145,14 +145,10 @@ class IntHybridArray(BoolHybridArray):
145
145
  carry = 0 if num_bits[j] else 1
146
146
  bool_data = [sign_bit] + num_bits
147
147
  for bit_idx in range(self.bit_length):
148
- super().__setitem__(block_start + bit_idx, bool_data[bit_idx])
148
+ super(self.__class__, self).__setitem__(block_start + bit_idx, bool_data[bit_idx])
149
149
 
150
150
  def __iter__(self):
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)
151
+ return map(self.__getitem__,range(len(self)))
156
152
 
157
153
  def __str__(self):
158
154
  return f"IntHybridArray([{', '.join(map(str, self))}])"
@@ -173,7 +169,7 @@ class IntHybridArray(BoolHybridArray):
173
169
  def index(self, value):
174
170
  value = int(value)
175
171
  x = f"{value} 不在 IntHybridArray 中"
176
- for idx in range(len(self)+2>>2):
172
+ for idx in range(len(self)+1>>1):
177
173
  if self[idx] == value:
178
174
  return idx
179
175
  elif self[-idx] == value:
@@ -184,7 +180,7 @@ class IntHybridArray(BoolHybridArray):
184
180
  def rindex(self, value):
185
181
  value = int(value)
186
182
  x = f"{value} 不在 IntHybridArray 中"
187
- for idx in range(len(self)+2>>2):
183
+ for idx in range(len(self)+1>>1):
188
184
  if self[-idx] == value:
189
185
  return -idx
190
186
  elif self[idx] == value:
@@ -200,4 +196,5 @@ class IntHybridArray(BoolHybridArray):
200
196
  len_ = len(iterable)
201
197
  self.total_bits += len_*self.bit_length
202
198
  for i,j in zip(range(len_),iterable):
203
- self[-i-1] = j
199
+ self[-i-1] = j
200
+ __all__ = list(globals())
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: bool-hybrid-array
3
- Version: 9.10.22
3
+ Version: 9.11.0
4
4
  Summary: 一个高效的布尔数组(密集+稀疏混合存储,节省内存)
5
5
  Home-page: https://github.com/BKsell/bool-hybrid-array
6
6
  Author: 蔡靖杰
@@ -17,6 +17,8 @@ Classifier: Programming Language :: Python :: 3.11
17
17
  Classifier: Programming Language :: Python :: 3.12
18
18
  Classifier: Programming Language :: Python :: 3.13
19
19
  Classifier: Programming Language :: Python :: 3.14
20
+ Classifier: Programming Language :: Python :: Implementation :: CPython
21
+ Classifier: Programming Language :: Python :: Implementation :: PyPy
20
22
  Classifier: License :: OSI Approved :: MIT License
21
23
  Classifier: Operating System :: OS Independent
22
24
  Requires-Python: >=3.8
@@ -572,6 +574,11 @@ except OverflowError as e:
572
574
  * **9.10.20**:优化性能,增加BHA_jit_log日志
573
575
  * **9.10.21**:优化Ask_BHA,移除BHA_jit_log日志
574
576
  * **9.10.22**:进一步优化Ask_BHA的性能
577
+ * **9.11.0**:新增对7.3.10以上的版本的PyPy解释器的支持
578
+
579
+
580
+
581
+
575
582
 
576
583
 
577
584
  ## **彩蛋:**
@@ -586,7 +593,11 @@ except OverflowError as e:
586
593
  * A:BoolHybridArray是本库中的**核心类**,所有函数都是围绕他进行的,但需要`split_index`,`size`,`is_sparse`;
587
594
  BoolHybridArr是一个**函数**,用于把一个可迭代对象转为`BoolHybridArray`类
588
595
  * Q:为什么不建议把太大的本类型数组打印?
589
- * A:虽然本类型数组省内存,但字符串不省内存,一个`True`要4字节,一个`False`要5字节,连逗号都要占1字节(`numpy.ndarray`:我都比字符串省内存)
596
+ * A:虽然BoolHybridArray类型数组省内存,但字符串不省内存,一个`True`要4字节,一个`False`要5字节,连逗号都要占1字节(`numpy.ndarray`:我都比字符串省内存)
597
+ - Q:为什么使用在Windows终端使用PyPy时建议先调用`chcp 65001`再启动PyPy?
598
+ * A:因为本库有很多的的中文报错和打印,项目里也可能会有。Windows终端里的PyPy默认是GBK编码,有中文时会乱码。chcp 65001可以切换到UTF-8编码,防止乱码。
599
+
600
+
590
601
 
591
602
  ## 源代码和原理
592
603
 
@@ -0,0 +1,10 @@
1
+ bool_hybrid_array/__init__.py,sha256=LG4gW4LcOkLDZFgS4fawE2Ztk4cOqm65GXamiHJjLCo,1038
2
+ bool_hybrid_array/__main__.py,sha256=3bnJ2IQctrXWQ1WyBQvh1w882_k3b84LGLL8yUNkXws,8447
3
+ bool_hybrid_array/core.py,sha256=kx023cSTOkN2aK2GJ9E33EQLfZUrXpNEP77eBWRVsRo,39081
4
+ bool_hybrid_array/秘密.md,sha256=Ii2NvXmv-Ktu04zJsGLcQZvlzT4gOatByE4B2wTK1Ks,48
5
+ bool_hybrid_array/int_array/__init__.py,sha256=1TN2O461-Mso4yZ6YFkhHcdNxgPPQYBJ0PzkWdkpFC8,8478
6
+ bool_hybrid_array-9.11.0.dist-info/licenses/LICENSE,sha256=Sg4rnGXkBDYkwJCWyxdWp5H60rhVAxpNvFh_l3JWZdY,1070
7
+ bool_hybrid_array-9.11.0.dist-info/METADATA,sha256=NZ05bIUnF0ql-pkT1NwF30l9LXhUpKTepi0p2cc69Dc,24081
8
+ bool_hybrid_array-9.11.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
9
+ bool_hybrid_array-9.11.0.dist-info/top_level.txt,sha256=vk-TD77wuVQsN1rJ6uVWZX4sC_wya_WplRDwQKJoBZM,18
10
+ bool_hybrid_array-9.11.0.dist-info/RECORD,,
@@ -1,10 +0,0 @@
1
- bool_hybrid_array/__init__.py,sha256=D1b3xe3CjxboRd_BQj6FgIzT6engdRDqx8yrmH-rK-8,955
2
- bool_hybrid_array/__main__.py,sha256=3MsUAXMj6Pe1EzP7YreuUePbXZeQvFSCnejnTeS42kU,8324
3
- bool_hybrid_array/core.py,sha256=s-4uJycfru2veh6Jsj1Z10h8RyYE7TMEaHHZ26YsB7o,38261
4
- bool_hybrid_array/秘密.md,sha256=Ii2NvXmv-Ktu04zJsGLcQZvlzT4gOatByE4B2wTK1Ks,48
5
- bool_hybrid_array/int_array/__init__.py,sha256=acjFchFu3k9CQndDbvKfSIyfMMAbgprz8Skf1a4_dKY,8578
6
- bool_hybrid_array-9.10.22.dist-info/licenses/LICENSE,sha256=Sg4rnGXkBDYkwJCWyxdWp5H60rhVAxpNvFh_l3JWZdY,1070
7
- bool_hybrid_array-9.10.22.dist-info/METADATA,sha256=XnepIEez9plj7k1TRSublVjL7PVGTczegeqL2q9SVSc,23540
8
- bool_hybrid_array-9.10.22.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
9
- bool_hybrid_array-9.10.22.dist-info/top_level.txt,sha256=vk-TD77wuVQsN1rJ6uVWZX4sC_wya_WplRDwQKJoBZM,18
10
- bool_hybrid_array-9.10.22.dist-info/RECORD,,