bool-hybrid-array 9.11.14__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.
@@ -4,16 +4,16 @@ from types import ModuleType,FunctionType
4
4
  try:from . import compile_core as core
5
5
  except:from . import core
6
6
  from .core import __builtins__,builtins
7
- try:from . import int_array
7
+ try:from . import int_array,float_array
8
8
  except:pass
9
- __version__ = "9.11.14"
9
+ __version__ = "9.11.15"
10
10
  public_objects = []
11
11
  for name in dir(core):
12
12
  if not name.startswith("_"):
13
13
  obj = getattr(core, name)
14
14
  if isinstance(obj, (type, ModuleType)) or callable(obj):
15
15
  public_objects.append(name)
16
- __all__ = public_objects + ["__version__","__builtins__","core","builtins","__dict__","int_array"]
16
+ __all__ = public_objects + ["__version__","__builtins__","core","builtins","__dict__","int_array","float_array"]
17
17
  globals().update({
18
18
  name: getattr(core, name)
19
19
  for name in public_objects
@@ -306,4 +306,41 @@ print(f"第二次出队: {q.dequeue()}") # 输出:F(直接从 self.b 弹出
306
306
 
307
307
  print(f"出队2个元素后: {q}") # 输出:BHA_Queue([T,T,F,T,F])
308
308
 
309
-
309
+ #float_array子包(9.11.15版本新增)
310
+
311
+ # 1. 初始化数组
312
+ f_arr = float_array.FloatHybridArray([1.1, 2.2, 3.3, 4.4, 5.5])
313
+
314
+ # 2. 获取元素
315
+ first_elem = f_arr[0] # 获取第一个元素:BHA_Float(1.1)
316
+ print(f"第一个元素:{first_elem}")
317
+
318
+ # 3. 修改元素
319
+ f_arr[1] = 9.9 # 修改第二个元素为 9.9
320
+ print(f"修改后第二个元素:{f_arr[1]}")
321
+
322
+ # 4. 添加元素
323
+ f_arr.append(6.6) # 追加元素 6.6
324
+ print(f"数组长度:{len(f_arr)}") # 输出:6
325
+
326
+ # 5. 遍历数组
327
+ for elem in f_arr:
328
+ print(f"数组元素:{elem}")
329
+
330
+ #namespace元类(9.11.15版本新增)
331
+ class BaseMathTools(metaclass = namespace):
332
+ pi = 3.141
333
+ def add(a,b):
334
+ return a+b
335
+ protected_names = ("pi","add")
336
+
337
+ class MathTools(BaseMathTools,metaclass = namespace):
338
+ pi = 3.1415926535897932
339
+ def mul(a,b):
340
+ return a*b
341
+ def sub(a,b):
342
+ return a-b
343
+ e = 2.718281828
344
+ protected_names = (*BaseMathTools.protected_names,"e","sub","mul")
345
+
346
+ print(MathTools.sub(10,23))#输出:230
bool_hybrid_array/core.py CHANGED
@@ -947,6 +947,13 @@ def numba_opt():
947
947
  bisect.bisect_left = numba.njit(sig, cache=True)(bisect.bisect_left)
948
948
  bisect.bisect_right = numba.njit(sig, cache=True)(bisect.bisect_right)
949
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
+
950
957
  builtins.np = np
951
958
  builtins.T = BHA_bool(1)
952
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.14
3
+ Version: 9.11.15
4
4
  Summary: 一个高效的布尔数组(密集+稀疏混合存储,节省内存)
5
5
  Home-page: https://github.com/BKsell/bool-hybrid-array
6
6
  Author: 蔡靖杰
@@ -449,7 +449,44 @@ print(f"第二次出队: {q.dequeue()}") # 输出:F(直接从 self.b 弹出
449
449
 
450
450
  print(f"出队2个元素后: {q}") # 输出:BHA_Queue([T,T,F,T,F])
451
451
 
452
+ #float_array子包(9.11.15版本新增)
452
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
453
490
  ```
454
491
 
455
492
  ## 性能优势
@@ -626,6 +663,7 @@ print(f"出队2个元素后: {q}") # 输出:BHA_Queue([T,T,F,T,F])
626
663
  * **9.11.12**:优化了IntHybridArray的__setitem__,新增了IntHybridArray的sort
627
664
  * **9.11.13**:修复IndexError的错误
628
665
  * **9.11.14**:新增BoolHybridArray数组的大小比较
666
+ * **9.11.15**:新增float_array子包和namespace元类
629
667
 
630
668
 
631
669
 
@@ -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=UYkGgU0Ux77DN1qfEW37ba2mjDAhqCIrqCgxGpY3h_g,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=iG3px_6ZJzYhlSnZUpZxJP4CRYfMGk39dlQveU26ZFc,79
6
- bool_hybrid_array/core.py,sha256=6BLUmXX-5fBnjamspmfaZAuVetBvDH-eAn6_F5QPaxM,42607
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.14.dist-info/licenses/LICENSE,sha256=Sg4rnGXkBDYkwJCWyxdWp5H60rhVAxpNvFh_l3JWZdY,1070
11
- bool_hybrid_array-9.11.14.dist-info/METADATA,sha256=mZs2z7RnExO3ywqfEdGXdfb1SRgWXsOx3oTewbn_moI,26618
12
- bool_hybrid_array-9.11.14.dist-info/WHEEL,sha256=wUyA8OaulRlbfwMtmQsvNngGrxQHAvkKcvRmdizlJi0,92
13
- bool_hybrid_array-9.11.14.dist-info/top_level.txt,sha256=vk-TD77wuVQsN1rJ6uVWZX4sC_wya_WplRDwQKJoBZM,18
14
- bool_hybrid_array-9.11.14.dist-info/RECORD,,