bool-hybrid-array 9.11.10__py3-none-any.whl → 9.11.12__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/core.py CHANGED
@@ -70,7 +70,7 @@ class ResurrectMeta(abc.ABCMeta,metaclass=abc.ABCMeta):# type: ignore
70
70
  try:
71
71
  setattr(builtins,cls.name,cls)
72
72
  if not sys.is_finalizing():
73
- print(f'警告:禁止删除常变量:{cls}')
73
+ print(f'\033[31m警告:禁止删除常变量:{cls}!\033[0m')
74
74
  raise TypeError(f'禁止删除常变量:{cls}')
75
75
  except NameError:pass
76
76
  def __hash__(cls):
@@ -786,10 +786,10 @@ class ProtectedBuiltinsDict(dict,metaclass=ResurrectMeta):# type: ignore
786
786
  if isinstance(current_T, BHA_bool) and isinstance(current_F, BHA_bool):
787
787
  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)
788
788
  if is_swap:
789
- print(f"""警告:禁止交换内置常量 __{self.name}__["{name}"] 和 __builtins__["{'F' if name == 'T' else 'T'}"]""")
789
+ print(f"""\033[31m警告:禁止交换内置常量 __{self.name}__["{name}"] 和 __builtins__["{'F' if name == 'T' else 'T'}"]!\033[0m""")
790
790
  raise AttributeError(f"""禁止交换内置常量 __{self.name}__["{name}"] 和 __{self.name}__["{'F' if name == 'T' else 'T'}"]""")
791
791
  if name in self.protected_names and name not in ["T", "F"]:
792
- print(f"警告:禁止修改内置常量 __{self.name}__['{name}']")
792
+ print(f"\033[31m警告:禁止修改内置常量 __{self.name}__['{name}']!\033[0m")
793
793
  raise AttributeError(f"禁止修改内置常量 __{self.name}__['{name}']")
794
794
  except:
795
795
  if sys.implementation.name == 'cpython':
@@ -797,7 +797,7 @@ class ProtectedBuiltinsDict(dict,metaclass=ResurrectMeta):# type: ignore
797
797
  finally:super().__setitem__(name, value)
798
798
  def __delitem__(self, name):
799
799
  if name in self.protected_names:
800
- print(f"警告:禁止删除内置常量 __builtins__['{name}']")
800
+ print(f"\033[31m警告:禁止删除内置常量 __builtins__['{name}']!\033[0m")
801
801
  raise AttributeError(f"禁止删除内置常量 __builtins__['{name}']")
802
802
  if name in self:
803
803
  super().__delitem__(name)
@@ -2,6 +2,37 @@ from __future__ import annotations
2
2
  from collections.abc import Iterable
3
3
  from ..core import *
4
4
  import builtins
5
+ def block_insert_sort(arr, start, end):
6
+ for i in range(start + 1, end):
7
+ current = arr[i]
8
+ insert_pos = bisect.bisect_right(arr, current, start, i)
9
+ j = i
10
+ while j > insert_pos:
11
+ arr[j], arr[j-1] = arr[j-1], arr[j]
12
+ j -= 1
13
+ def merge_two_blocks(arr, left_start, left_end, right_end):
14
+ if arr[left_end - 1] <= arr[left_end]:
15
+ return
16
+ left = arr[left_start:left_end]
17
+ right = arr[left_end:right_end]
18
+ i = j = 0
19
+ k = left_start
20
+ while i < len(left) and j < len(right):
21
+ if left[i] <= right[j]:
22
+ arr[k] = left[i]
23
+ i += 1
24
+ else:
25
+ arr[k] = right[j]
26
+ j += 1
27
+ k += 1
28
+ while i < len(left):
29
+ arr[k] = left[i]
30
+ i += 1
31
+ k += 1
32
+ while j < len(right):
33
+ arr[k] = right[j]
34
+ j += 1
35
+ k += 1
5
36
  class IntBitTag(BHA_bool, metaclass=ResurrectMeta):
6
37
  def __str__(self):
7
38
  return "'-1'" if (hasattr(self, 'is_sign_bit') and self.is_sign_bit and self) else "'1'" if self else "'0'"
@@ -95,9 +126,14 @@ class IntHybridArray(BoolHybridArray,metaclass=ResurrectMeta):
95
126
  return self.to_int(bit_chunk)
96
127
 
97
128
  def __setitem__(self, key, value):
98
- tmp = list(self)
99
- tmp[key] = value
100
- self.__init__(tmp)
129
+ tmp1 = IntHybridArray([value],bit_length = self.bit_length)
130
+ tmp = tmp1.view()
131
+ if tmp1[0] == value:
132
+ super().__setitem__(slice(key*self.bit_length,(key+1)*self.bit_length),tmp)
133
+ else:
134
+ lst = list(self)
135
+ lst[key] = value
136
+ self.__init__(lst)
101
137
  def __iter__(self):
102
138
  return map(self.__getitem__,range(len(self)))
103
139
 
@@ -152,3 +188,17 @@ class IntHybridArray(BoolHybridArray,metaclass=ResurrectMeta):
152
188
  self.total_bits += self.bit_length
153
189
  self.size = self.total_bits
154
190
  self[-1] = value
191
+ def sort(self):
192
+ n = len(self)
193
+ BLOCK_SIZE = 32
194
+ for start in range(0, n, BLOCK_SIZE):
195
+ end = min(start + BLOCK_SIZE, n)
196
+ block_insert_sort(self, start, end)
197
+ merge_size = BLOCK_SIZE
198
+ while merge_size < n:
199
+ for start in range(0, n, merge_size * 2):
200
+ mid = min(start + merge_size, n)
201
+ end = min(start + merge_size * 2, n)
202
+ if mid < end:
203
+ merge_two_blocks(self, start, mid, end)
204
+ merge_size *= 2
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: bool-hybrid-array
3
- Version: 9.11.10
3
+ Version: 9.11.12
4
4
  Summary: 一个高效的布尔数组(密集+稀疏混合存储,节省内存)
5
5
  Home-page: https://github.com/BKsell/bool-hybrid-array
6
6
  Author: 蔡靖杰
@@ -9,6 +9,8 @@ Project-URL: GitHub 主站, https://github.com/BKsell/bool-hybrid-array
9
9
  Project-URL: GitHub 中文镜像, https://www.github-zh.com/projects/1083175506-bool-hybrid-array
10
10
  Project-URL: Issue 反馈(主站), https://github.com/BKsell/bool-hybrid-array/issues
11
11
  Keywords: boolean array,compact storage
12
+ Classifier: Programming Language :: Cython
13
+ Classifier: Programming Language :: Python
12
14
  Classifier: Programming Language :: Python :: 3
13
15
  Classifier: Programming Language :: Python :: 3.8
14
16
  Classifier: Programming Language :: Python :: 3.9
@@ -29,6 +31,8 @@ Requires-Dist: numpy>=1.19.0
29
31
  Provides-Extra: int-array
30
32
  Provides-Extra: numba-opt
31
33
  Requires-Dist: numba>=0.55.0; extra == "numba-opt"
34
+ Provides-Extra: cython-opt
35
+ Requires-Dist: cython>=3.2.4; extra == "cython-opt"
32
36
  Dynamic: author
33
37
  Dynamic: author-email
34
38
  Dynamic: classifier
@@ -616,7 +620,8 @@ print(f"出队2个元素后: {q}") # 输出:BHA_Queue([T,T,F,T,F])
616
620
  * **9.11.8**:增加了Windows系统Python3.14的C扩展优化
617
621
  * **9.11.9**:修复BHA_Queue的bug,新增cin和cout(使用方式:a = ctypes.c_int();cin >> a;cout << a,支持各种ctypes类型、numpy标量)
618
622
  * **9.11.10**:修复cin的AttributeError的错误
619
-
623
+ * **9.11.11**:新增cin对EOF的处理
624
+ * **9.11.12**:优化了IntHybridArray的__setitem__,新增了IntHybridArray的sort
620
625
 
621
626
 
622
627
 
@@ -0,0 +1,14 @@
1
+ bool_hybrid_array/__init__.py,sha256=zX4t08F5NAIBY9x5I_wFKVem2sCzB90o1c4Nogz4IzY,1086
2
+ bool_hybrid_array/__main__.py,sha256=uFyebfsZl1tW54AVcc6IDhk36BglTGb_Vw3Djx8pq00,8987
3
+ bool_hybrid_array/_cppiostream.py,sha256=1i973ag_8XgivQkeIbqzHivflcQkVFtX77R_UwChSAg,9205
4
+ bool_hybrid_array/compile_core.cp314-win_amd64.pyd,sha256=3DhgWD3Zrprov7irFmUEmCoe9WndQMt8NVwGncnxcCQ,514560
5
+ bool_hybrid_array/core.c,sha256=om2tuMhsXPLtmFAcJpY-VnZcwVJ2sZrYEPWPsdtEs4M,3230975
6
+ bool_hybrid_array/core.py,sha256=nrmu8djPZS3Y70wRa_QkeM-5v-LGLUkuSZiw__OFU-M,42091
7
+ bool_hybrid_array/秘密.md,sha256=Ii2NvXmv-Ktu04zJsGLcQZvlzT4gOatByE4B2wTK1Ks,48
8
+ bool_hybrid_array/int_array/__init__.py,sha256=CCKDUL5GBAXOprc9FhtLNL_rP4IDhvGVWJ-Dporp6YI,112
9
+ bool_hybrid_array/int_array/core.py,sha256=DZ6mC-qLQahV25b_1RHGPK959XYtILYP_Pbwwg7nFLA,7936
10
+ bool_hybrid_array-9.11.12.dist-info/licenses/LICENSE,sha256=Sg4rnGXkBDYkwJCWyxdWp5H60rhVAxpNvFh_l3JWZdY,1070
11
+ bool_hybrid_array-9.11.12.dist-info/METADATA,sha256=4Nxj1A_jkOzHDUa2htNIUT6b8lbk2mZOwOFgZZl3nv8,26430
12
+ bool_hybrid_array-9.11.12.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
13
+ bool_hybrid_array-9.11.12.dist-info/top_level.txt,sha256=vk-TD77wuVQsN1rJ6uVWZX4sC_wya_WplRDwQKJoBZM,18
14
+ bool_hybrid_array-9.11.12.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (80.10.1)
2
+ Generator: setuptools (80.10.2)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
Binary file
@@ -1,14 +0,0 @@
1
- bool_hybrid_array/__init__.py,sha256=KzXCj4pevLEmZMp789nBkklGWOVGVy7iUohoA3cxhL8,1078
2
- bool_hybrid_array/__main__.py,sha256=uFyebfsZl1tW54AVcc6IDhk36BglTGb_Vw3Djx8pq00,8987
3
- bool_hybrid_array/_cppiostream.py,sha256=uisSGktor52VFxhTcMN011RtzuUE8O1Fgz2VltnPi3c,8447
4
- bool_hybrid_array/compile_core.pyd,sha256=_bSaBSVM8x_fkxdP_-4AiIYWVEkTgV3DWCPXzP-i-00,556544
5
- bool_hybrid_array/core.c,sha256=6jlDe0FTZweoWtfhabEQMOk7kfwaiPFDoe0yYPCMpS8,3230449
6
- bool_hybrid_array/core.py,sha256=nv-veRvbioLefXCe66Py1avxb7_8OZbT5CeyQm-ErQE,42031
7
- bool_hybrid_array/秘密.md,sha256=Ii2NvXmv-Ktu04zJsGLcQZvlzT4gOatByE4B2wTK1Ks,48
8
- bool_hybrid_array/int_array/__init__.py,sha256=CCKDUL5GBAXOprc9FhtLNL_rP4IDhvGVWJ-Dporp6YI,112
9
- bool_hybrid_array/int_array/core.py,sha256=hnXHSLabtbDCnO3JX0M5tsF0BWlQpjWKu7RplMx7i8A,6236
10
- bool_hybrid_array-9.11.10.dist-info/licenses/LICENSE,sha256=Sg4rnGXkBDYkwJCWyxdWp5H60rhVAxpNvFh_l3JWZdY,1070
11
- bool_hybrid_array-9.11.10.dist-info/METADATA,sha256=kmw6K6GnXPoBGWxeNaZ8Rm4HGPdjWwqIsw3WgP2gkM8,26133
12
- bool_hybrid_array-9.11.10.dist-info/WHEEL,sha256=qELbo2s1Yzl39ZmrAibXA2jjPLUYfnVhUNTlyF1rq0Y,92
13
- bool_hybrid_array-9.11.10.dist-info/top_level.txt,sha256=vk-TD77wuVQsN1rJ6uVWZX4sC_wya_WplRDwQKJoBZM,18
14
- bool_hybrid_array-9.11.10.dist-info/RECORD,,