bool-hybrid-array 9.11.13__py3-none-any.whl → 9.11.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/core.py CHANGED
@@ -15,6 +15,7 @@ from functools import lru_cache
15
15
  from typing import _GenericAlias
16
16
  from typing import Callable, Union, Sequence, MutableSequence, Any, overload, Sized
17
17
  hybrid_array_cache:list[tuple[Any]] = []
18
+ index_range=lambda BHA:(BHA[i] for i in itertools.count(0) if i < BHA.size)
18
19
  try:
19
20
  msvcrt = ctypes.CDLL('msvcrt.dll')
20
21
  memcpy = msvcrt.memcpy
@@ -277,14 +278,14 @@ class BoolHybridArray(MutableSequence,Exception,metaclass=ResurrectMeta):# type:
277
278
  value_list = list(value)
278
279
  new_len = len(value_list)
279
280
  if step != 1:
280
- slice_indices = list(range(start, stop, step))
281
+ slice_indices = range(start, stop, step)
281
282
  if new_len != len(slice_indices):
282
283
  raise ValueError(f"值长度与切片长度不匹配:{new_len} vs {len(slice_indices)}")
283
284
  for i, val in zip(slice_indices, value_list):
284
285
  self[i] = val
285
286
  return
286
287
  if new_len == max(0, stop - start):
287
- for v,i in zip(new_len,range(start,stop)):
288
+ for v,i in zip(value_list,range(start,stop)):
288
289
  self[i] = v
289
290
  return
290
291
  for i in range(stop - 1, start - 1, -1):
@@ -358,7 +359,7 @@ class BoolHybridArray(MutableSequence,Exception,metaclass=ResurrectMeta):# type:
358
359
  return int(self.size)
359
360
  def __iter__(self):
360
361
  if not self:return BHA_Iterator([])
361
- return BHA_Iterator(map(self.__getitem__,range(self.size)))
362
+ return BHA_Iterator(map(self.__getitem__,index_range(size)))
362
363
  def __next__(self):
363
364
  return next(self.generator)
364
365
  def __contains__(self, value:Any) -> bool:
@@ -427,7 +428,6 @@ class BoolHybridArray(MutableSequence,Exception,metaclass=ResurrectMeta):# type:
427
428
  return self
428
429
  if not self.is_sparse:
429
430
  self += FalsesArray(int(other))
430
- self.optimize()
431
431
  else:
432
432
  self.size += int(other)
433
433
  return self
@@ -448,6 +448,14 @@ class BoolHybridArray(MutableSequence,Exception,metaclass=ResurrectMeta):# type:
448
448
  if len(self) != len(other):
449
449
  raise ValueError(f"异或运算要求数组长度相同({len(self)} vs {len(other)})")
450
450
  return BoolHybridArr(map(operator.xor, self, other),hash_ = self.hash_)
451
+ def __gt__(self,other):
452
+ if self.size!=len(other)
453
+ return self.size>len(other)
454
+ return any(map(operator.gt,self,other)
455
+ def __lt__(self,other):
456
+ if self.size!=len(other)
457
+ return self.size<len(other)
458
+ return any(map(operator.lt,self,other)
451
459
  def __rxor__(self, other) -> BoolHybridArray:
452
460
  return self^other
453
461
  def __invert__(self) -> BoolHybridArray:
@@ -939,6 +947,13 @@ def numba_opt():
939
947
  bisect.bisect_left = numba.njit(sig, cache=True)(bisect.bisect_left)
940
948
  bisect.bisect_right = numba.njit(sig, cache=True)(bisect.bisect_right)
941
949
  from ._cppiostream import cin,cout,endl
950
+ def namespace(name,bases,namespace_):
951
+ tmp = {}
952
+ for base in bases:tmp.update(base.__namespace__)
953
+ self = ProtectedBuiltinsDict({**tmp,**namespace_},name = name,protected_names = namespace_.get("protected_names",()))
954
+ self["__namespace__"] = self
955
+ return self
956
+
942
957
  builtins.np = np
943
958
  builtins.T = BHA_bool(1)
944
959
  builtins.F = BHA_bool(0)
@@ -0,0 +1,3 @@
1
+ try:from .compile_core import *
2
+ except:from .core import*
3
+ __all__ = tuple(globals())
@@ -0,0 +1,158 @@
1
+ from __future__ import annotations
2
+ from collections.abc import Sequence
3
+ from ..int_array import IntHybridArray
4
+ from ..core import BHA_Iterator
5
+ import operator,math,itertools
6
+ class BHA_Float(float):
7
+ def __init__(self, data: int | str | float | BHA_Float | tuple):
8
+ if isinstance(data, tuple):
9
+ self.a,self.b,self.length = data
10
+ return
11
+ if isinstance(data, BHA_Float):
12
+ self.a = data.a
13
+ self.b = data.b
14
+ self.length = data.length
15
+ return
16
+ if isinstance(data, int):
17
+ data = float(data)
18
+ if isinstance(data, float):
19
+ data = repr(data)
20
+ a, b = data.split('.')
21
+ b = b.rstrip('0')
22
+ self.length = len(b) if b else 1
23
+ self.a, self.b = int(a) if a else 0, int(b) if b else 0
24
+
25
+ def _align_decimal(self, other):
26
+ max_len = max(self.length, other.length)
27
+ self_num = self.a * (10 ** max_len) + self.b * (10 ** (max_len - self.length))
28
+ other_num = other.a * (10 ** max_len) + other.b * (10 ** (max_len - other.length))
29
+ return self_num, other_num, max_len
30
+
31
+ def __add__(self, other):
32
+ other = BHA_Float(other)
33
+ self_num, other_num, max_len = self._align_decimal(other)
34
+ sum_num = self_num + other_num
35
+ string = repr(sum_num)
36
+ integer_part = string[:-max_len] if len(string) > max_len else '0'
37
+ decimal_part = string[-max_len:] if len(string) >= max_len else string.zfill(max_len)
38
+ return BHA_Float(f"{integer_part}.{decimal_part}")
39
+
40
+ def __sub__(self, other):
41
+ other = BHA_Float(other)
42
+ self_num, other_num, max_len = self._align_decimal(other)
43
+ sub_num = self_num - other_num
44
+ if sub_num < 0:
45
+ string = repr(-sub_num)
46
+ sign = '-'
47
+ else:
48
+ string = repr(sub_num)
49
+ sign = ''
50
+ integer_part = string[:-max_len] if len(string) > max_len else '0'
51
+ decimal_part = string[-max_len:] if len(string) >= max_len else string.zfill(max_len)
52
+ return BHA_Float(f"{sign}{integer_part}.{decimal_part}")
53
+ def __mul__(self, other):
54
+ other = BHA_Float(other)
55
+ self_num = self.a * (10 ** self.length) + self.b
56
+ other_num = other.a * (10 ** other.length) + other.b
57
+ product = self_num * other_num
58
+ string = repr(product)
59
+ total_decimal = self.length + other.length
60
+ string = string.zfill(total_decimal + 1)
61
+ integer_part = string[:-total_decimal]
62
+ decimal_part = string[-total_decimal:]
63
+ return BHA_Float(f"{integer_part}.{decimal_part}")
64
+
65
+ def __truediv__(self, other, total_decimal = 22):
66
+ other = BHA_Float(other)
67
+ self_num = self.a * (10 ** self.length) + self.b
68
+ other_num = other.a * (10 ** other.length) + other.b
69
+ if other_num == 0:
70
+ raise ZeroDivisionError("Cannot divide by zero")
71
+ div_num = (self_num * (10 ** total_decimal)) // other_num
72
+ string = repr(div_num)
73
+ if len(string) <= total_decimal:
74
+ string = '0' * (total_decimal - len(string) + 1) + string
75
+ integer_part = string[:-total_decimal]
76
+ decimal_part = string[-total_decimal:]
77
+ return BHA_Float(f"{integer_part}.{decimal_part}")
78
+ def __repr__(self):
79
+ return f"BHA_Float({self.a}.{str(self.b).zfill(self.length)})"
80
+ def __str__(self):
81
+ return f"{self.a}.{str(self.b).zfill(self.length)}"
82
+ __radd__ = __add__
83
+ __rmul__ = __mul__
84
+ __rsub__ = lambda self,other:BHA_Float(other)-self
85
+ __rtruediv__ = lambda self,other:BHA_Float(other)/self
86
+ def __float__(self):
87
+ return float(str(self))
88
+ def __int__(self):
89
+ return self.a
90
+ is_integer = lambda self:not self.b
91
+ __bool__ = lambda self:self.a or self.b
92
+ def as_integer_ratio(self) -> tuple[int, int]:
93
+ denominator = 10 ** self.length
94
+ numerator = self.a * denominator + self.b
95
+ if numerator < 0:
96
+ numerator = -numerator
97
+ sign = -1
98
+ else:
99
+ sign = 1
100
+ gcd_val = math.gcd(numerator, denominator)
101
+ if gcd_val == 0:
102
+ gcd_val = 1
103
+ simplified_num = sign * (numerator // gcd_val)
104
+ simplified_den = denominator // gcd_val
105
+ return (simplified_num, simplified_den)
106
+ def __eq__(self,other):
107
+ try:
108
+ other = BHA_Float(other)
109
+ self_num, other_num, _ = self._align_decimal(other)
110
+ return self_num == other_num
111
+ except (ValueError, AttributeError):
112
+ return False
113
+ def __floordiv__(self, other):
114
+ return BHA_Float(int(float(self / other)))
115
+ def __mod__(self, other):
116
+ return self - (self // other) * other
117
+ def __pow__(self, power, m = None):
118
+ return BHA_Float(pow(float(self),float(BHA_Float(power)),m))
119
+ def __neg__(self):
120
+ return BHA_Float((-self.a, self.b, self.length))
121
+ def __pos__(self):
122
+ return self
123
+ def __abs__(self):
124
+ return BHA_Float((abs(self.a), self.b, self.length))
125
+ def __lt__(self,other):
126
+ a, b, _ = self._align_decimal(other)
127
+ return a<b
128
+ def __gt__(self,other):
129
+ a, b, _ = self._align_decimal(other)
130
+ return a>b
131
+ def __round__(self,n = None):
132
+ return round(float(self),n)
133
+ __rmod__ = lambda self,other:BHA_Float(other)%self
134
+ __rfloordiv__ = lambda self,other:BHA_Float(other)//self
135
+ __rpow__ = lambda self,other,m=None:pow(BHA_Float(other),self,m)
136
+ class FloatHybridArray(Sequence):
137
+ def __init__(self,data,Type = BHA_Float):
138
+ self.Type = Type
139
+ data = BHA_Iterator(map(BHA_Float,data))
140
+ self.lengths = IntHybridArray(map(operator.attrgetter('length'),data))
141
+ self.a = IntHybridArray(map(operator.attrgetter('a'),data))
142
+ self.b = IntHybridArray(map(operator.attrgetter('b'),data))
143
+ def __getitem__(self,index):
144
+ return self.Type(BHA_Float((self.a[index],self.b[index],self.lengths[index])))
145
+ def __setitem__(self,index,value):
146
+ value = BHA_Float(value)
147
+ self.lengths[index] = value.length
148
+ self.a[index] = value.a
149
+ self.b[index] = value.b
150
+ def append(self,value):
151
+ value = BHA_Float(value)
152
+ self.lengths.append(value.length)
153
+ self.a.append(value.a)
154
+ self.b.append(value.b)
155
+ def __len__(self):
156
+ return len(self.a)
157
+ def __iter__(self):
158
+ return BHA_Iterator(self[i] for i in itertools.count(0) if i < len(self))
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: bool-hybrid-array
3
- Version: 9.11.13
3
+ Version: 9.11.15
4
4
  Summary: 一个高效的布尔数组(密集+稀疏混合存储,节省内存)
5
5
  Home-page: https://github.com/BKsell/bool-hybrid-array
6
6
  Author: 蔡靖杰
@@ -33,6 +33,8 @@ Provides-Extra: numba-opt
33
33
  Requires-Dist: numba>=0.55.0; extra == "numba-opt"
34
34
  Provides-Extra: cython-opt
35
35
  Requires-Dist: cython>=3.2.4; extra == "cython-opt"
36
+ Provides-Extra: cycy-opt
37
+ Requires-Dist: cycy-runtime>=0.2.4; extra == "cycy-opt"
36
38
  Dynamic: author
37
39
  Dynamic: author-email
38
40
  Dynamic: classifier
@@ -447,7 +449,44 @@ print(f"第二次出队: {q.dequeue()}") # 输出:F(直接从 self.b 弹出
447
449
 
448
450
  print(f"出队2个元素后: {q}") # 输出:BHA_Queue([T,T,F,T,F])
449
451
 
452
+ #float_array子包(9.11.15版本新增)
450
453
 
454
+ # 1. 初始化数组
455
+ f_arr = float_array.FloatHybridArray([1.1, 2.2, 3.3, 4.4, 5.5])
456
+
457
+ # 2. 获取元素
458
+ first_elem = f_arr[0] # 获取第一个元素:BHA_Float(1.1)
459
+ print(f"第一个元素:{first_elem}")
460
+
461
+ # 3. 修改元素
462
+ f_arr[1] = 9.9 # 修改第二个元素为 9.9
463
+ print(f"修改后第二个元素:{f_arr[1]}")
464
+
465
+ # 4. 添加元素
466
+ f_arr.append(6.6) # 追加元素 6.6
467
+ print(f"数组长度:{len(f_arr)}") # 输出:6
468
+
469
+ # 5. 遍历数组
470
+ for elem in f_arr:
471
+ print(f"数组元素:{elem}")
472
+
473
+ #namespace元类(9.11.15版本新增)
474
+ class BaseMathTools(metaclass = namespace):
475
+ pi = 3.141
476
+ def add(a,b):
477
+ return a+b
478
+ protected_names = ("pi","add")
479
+
480
+ class MathTools(BaseMathTools,metaclass = namespace):
481
+ pi = 3.1415926535897932
482
+ def mul(a,b):
483
+ return a*b
484
+ def sub(a,b):
485
+ return a-b
486
+ e = 2.718281828
487
+ protected_names = (*BaseMathTools.protected_names,"e","sub","mul")
488
+
489
+ print(MathTools.sub(10,23))#输出:230
451
490
  ```
452
491
 
453
492
  ## 性能优势
@@ -623,6 +662,9 @@ print(f"出队2个元素后: {q}") # 输出:BHA_Queue([T,T,F,T,F])
623
662
  * **9.11.11**:新增cin对EOF的处理
624
663
  * **9.11.12**:优化了IntHybridArray的__setitem__,新增了IntHybridArray的sort
625
664
  * **9.11.13**:修复IndexError的错误
665
+ * **9.11.14**:新增BoolHybridArray数组的大小比较
666
+ * **9.11.15**:新增float_array子包和namespace元类
667
+
626
668
 
627
669
 
628
670
 
@@ -0,0 +1,15 @@
1
+ bool_hybrid_array/__init__.py,sha256=3lakvdUwLIemZs9s96GNgOJVDXH5dSQoUUQJbc656gQ,1112
2
+ bool_hybrid_array/__main__.py,sha256=Upm136zlFUq1ORDakehl93tyI16Oohqabc4A8IjaGC4,10058
3
+ bool_hybrid_array/_cppiostream.py,sha256=1i973ag_8XgivQkeIbqzHivflcQkVFtX77R_UwChSAg,9205
4
+ bool_hybrid_array/core.c,sha256=iG3px_6ZJzYhlSnZUpZxJP4CRYfMGk39dlQveU26ZFc,79
5
+ bool_hybrid_array/core.py,sha256=lbKvqSnihcT7yWZYEeT4IKA9rZyrUQrRcFT3Cpi2K6E,42890
6
+ bool_hybrid_array/秘密.md,sha256=Ii2NvXmv-Ktu04zJsGLcQZvlzT4gOatByE4B2wTK1Ks,48
7
+ bool_hybrid_array/float_array/__init__.py,sha256=tnOiqeZ4AIvNgPV16tt0ydz0NWzSa6e4arInS6F8Y-0,86
8
+ bool_hybrid_array/float_array/core.py,sha256=1s8DwtZKzx9PK2ZB-93JdieXQ0tG_-uERwmEvWO6k-4,6615
9
+ bool_hybrid_array/int_array/__init__.py,sha256=CCKDUL5GBAXOprc9FhtLNL_rP4IDhvGVWJ-Dporp6YI,112
10
+ bool_hybrid_array/int_array/core.py,sha256=DZ6mC-qLQahV25b_1RHGPK959XYtILYP_Pbwwg7nFLA,7936
11
+ bool_hybrid_array-9.11.15.dist-info/licenses/LICENSE,sha256=Sg4rnGXkBDYkwJCWyxdWp5H60rhVAxpNvFh_l3JWZdY,1070
12
+ bool_hybrid_array-9.11.15.dist-info/METADATA,sha256=RqFSYvXYpxEpOFHmZl3qk_Sq1dj8zb85oXDXs_rSwhM,27748
13
+ bool_hybrid_array-9.11.15.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
14
+ bool_hybrid_array-9.11.15.dist-info/top_level.txt,sha256=vk-TD77wuVQsN1rJ6uVWZX4sC_wya_WplRDwQKJoBZM,18
15
+ bool_hybrid_array-9.11.15.dist-info/RECORD,,
@@ -1,14 +0,0 @@
1
- bool_hybrid_array/__init__.py,sha256=m44910RtpNN9VGJkDkG_T3aZ50wPidd6hT5t1Yw465s,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=3vFAZ6vSMqoP_fWRkXd_KVPVUw4oo2Nv7xi0sBQu2fQ,516096
5
- bool_hybrid_array/core.c,sha256=gFU1P6ksFaDqT0vUC4u65bb700-LZU6vu0mwTUYNLzg,3241001
6
- bool_hybrid_array/core.py,sha256=t0CuBJwRJY870E0ycnMpdfflAIIa6PgUk3W1IVzbDrs,42257
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.13.dist-info/licenses/LICENSE,sha256=Sg4rnGXkBDYkwJCWyxdWp5H60rhVAxpNvFh_l3JWZdY,1070
11
- bool_hybrid_array-9.11.13.dist-info/METADATA,sha256=hYO9uLNP-zI7EIUqLe_5CHcsLDS9DvU4BB-kUG4gKb0,26473
12
- bool_hybrid_array-9.11.13.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
13
- bool_hybrid_array-9.11.13.dist-info/top_level.txt,sha256=vk-TD77wuVQsN1rJ6uVWZX4sC_wya_WplRDwQKJoBZM,18
14
- bool_hybrid_array-9.11.13.dist-info/RECORD,,